
    Ngt                       d dl mZ d dlZd dlmZmZmZmZmZ d dl	Z	d dl
mZ d dlmZ d dlmZmZmZ d dlmZmZmZ d dlmZmZmZmZ  ej        e          ZddZddZ eddd           G d dee                      Z dS )    )annotationsN)AnyCallableDictListOptional)
deprecated)
Embeddings)convert_to_secret_strget_from_dict_or_envpre_init)	BaseModel
ConfigDict	SecretStr)before_sleep_logretrystop_after_attemptwait_exponentialreturnCallable[[Any], Any]c            	         d} d}d}d}t          dt          |          t          | ||          t          t          t
          j                            S )z#Returns a tenacity retry decorator.         T)
multiplierminmax)reraisestopwaitbefore_sleep)r   r   r   r   loggerloggingWARNING)r   min_secondsmax_secondsmax_retriess       `/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/embeddings/solar.py_create_retry_decoratorr)      s^     JKKK,,+VVV%fgo>>	       
embeddingsSolarEmbeddingsargsr   kwargsc                L     t                      }|d fd            } ||i |S )z*Use tenacity to retry the completion call.r-   r   r.   r   c                      j         | i |S )N)embed)r-   r.   r+   s     r(   _embed_with_retryz+embed_with_retry.<locals>._embed_with_retry)   s    z0000r*   )r-   r   r.   r   r   r   )r)   )r+   r-   r.   retry_decoratorr2   s   `    r(   embed_with_retryr4   %   sN    -//O1 1 1 1 1 _1 d-f---r*   z0.0.34z1.0zlangchain_upstage.ChatUpstage)sinceremovalalternative_importc                      e Zd ZU dZdZded<   	 dZded<   	 dZded	<   	  ed
          Z	e
dd            ZddZddZddZdS )r,   aJ  Solar's embedding service.

    To use, you should have the environment variable``SOLAR_API_KEY`` set
    with your API token, or pass it as a named parameter to the constructor.

    Example:
        .. code-block:: python

            from langchain_community.embeddings import SolarEmbeddings
            embeddings = SolarEmbeddings()

            query_text = "This is a test query."
            query_result = embeddings.embed_query(query_text)

            document_text = "This is a test document."
            document_result = embeddings.embed_documents([document_text])

    z*https://api.upstage.ai/v1/solar/embeddingsstrendpoint_urlzsolar-1-mini-embedding-querymodelNzOptional[SecretStr]solar_api_keyforbid)extravaluesr   r   c                L    t          t          |dd                    }||d<   |S )z'Validate api key exists in environment.r<   SOLAR_API_KEY)r   r   )clsr?   r<   s      r(   validate_environmentz$SolarEmbeddings.validate_environmentR   s3     . /JJ
 
 #0r*   textList[List[float]]c                B   | j         |d}d| j                                         dd}t          j        | j        ||          }|                                }t          |d                   dk    rt          d|d	                    |d         d         d
         }|S )N)r;   inputzBearer zapplication/json)AuthorizationzContent-Type)headersjsondatar   zSolar API returned an error: 	base_resp	embedding)	r;   r<   get_secret_valuerequestspostr:   rJ   len
ValueError)selfrD   payloadrI   responseparsed_responserM   s          r(   r1   zSolarEmbeddings.embed[   s    
 Z
 
 Ot'9'J'J'L'LNN.
 
 =!2G'RRR"--// v&''1,,N0LNN   $F+A.{;	r*   texts	List[str]c                $      fd|D             }|S )zEmbed documents using a Solar embedding endpoint.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        c                2    g | ]}t          |           S )rD   r4   ).0rD   rS   s     r(   
<listcomp>z3SolarEmbeddings.embed_documents.<locals>.<listcomp>   s'    JJJD&t$777JJJr*    )rS   rW   r+   s   `  r(   embed_documentszSolarEmbeddings.embed_documentsx   s%     KJJJEJJJ
r*   List[float]c                (    t          | |          }|S )zEmbed a query using a Solar embedding endpoint.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        r[   r\   )rS   rD   rM   s      r(   embed_queryzSolarEmbeddings.embed_query   s     %T555	r*   )r?   r   r   r   )rD   r9   r   rE   )rW   rX   r   rE   )rD   r9   r   ra   )__name__
__module____qualname____doc__r:   __annotations__r;   r<   r   model_configr   rC   r1   r`   rc   r_   r*   r(   r,   r,   0   s          & ELDDDD/E////')-M---- :  L    X   :
 
 
 

 
 
 
 
 
r*   )r   r   )r+   r,   r-   r   r.   r   r   r   )!
__future__r   r#   typingr   r   r   r   r   rO   langchain_core._apir	   langchain_core.embeddingsr
   langchain_core.utilsr   r   r   pydanticr   r   r   tenacityr   r   r   r   	getLoggerrd   r"   r)   r4   r,   r_   r*   r(   <module>rr      s   " " " " " "  6 6 6 6 6 6 6 6 6 6 6 6 6 6  * * * * * * 0 0 0 0 0 0 V V V V V V V V V V 5 5 5 5 5 5 5 5 5 5            
	8	$	$    . . . . 
E6U  [ [ [ [ [i [ [ [ [ [r*   