
    NgF                        d dl mZ d dlZd dlmZmZmZmZ d dlm	Z	 d dl
mZmZ d dlmZ  ej        e          Z G d dee	          ZdS )	    )annotationsN)AnyDictListOptional)
Embeddings)get_from_dict_or_envpre_init)	BaseModelc                      e Zd ZU dZdZded<   	 dZded<   	 dZded<   	 d	Zded
<   	 dZ	ded<   	 dZ
ded<   	 dZded<   	 ded<   	 edd            Zd dZd!dZdS )"VolcanoEmbeddingsz)`Volcengine Embeddings` embedding models.NzOptional[str]
volcano_ak
volcano_skz*maas-api.ml-platform-cn-beijing.volces.comstrhostz
cn-beijingregionzbge-large-zhmodelz1.0versiond   int
chunk_sizer   clientvaluesr   returnc                F   t          |dd          |d<   t          |dd          |d<   	 ddlm}  ||d         |d                   }|                    |d                    |                    |d                    ||d	<   n# t
          $ r t          d
          w xY w|S )a6  
        Validate whether volcano_ak and volcano_sk in the environment variables or
        configuration file are available or not.

        init volcano embedding client with `ak`, `sk`, `host`, `region`

        Args:

            values: a dictionary containing configuration information, must include the
            fields of volcano_ak and volcano_sk
        Returns:

            a dictionary containing configuration information. If volcano_ak and
            volcano_sk are not provided in the environment variables or configuration
            file,the original values will be returned; otherwise, values containing
            volcano_ak and volcano_sk will be returned.
        Raises:

            ValueError: volcengine package not found, please install it with
            `pip install volcengine`
        r   VOLC_ACCESSKEYr   VOLC_SECRETKEYr   )MaasServicer   r   r   zMvolcengine package not found, please install it with `pip install volcengine`)r	   volcengine.maasr   set_akset_skImportError)clsr   r   r   s       e/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/embeddings/volcengine.pyvalidate_environmentz&VolcanoEmbeddings.validate_environment.   s    .  4 
  
|
  4 
  
|	333333 [1ABBFMM&.///MM&.///%F8 	 	 	+  	
 s   AB BtextList[float]c                :    |                      |g          d         S )Nr   )embed_documents)selfr&   s     r$   embed_queryzVolcanoEmbeddings.embed_query^   s    ##TF++A..    texts	List[str]List[List[float]]c                f     fdt          dt                     j                  D             }g }|D ]y} j         j        d|d}	 ddlm}  j                            |          }|	                    d |d         D                        [# |$ r}t          d|           d	}~ww xY w|S )
a_  
        Embeds a list of text documents using the AutoVOT algorithm.

        Args:
            texts (List[str]): A list of text documents to embed.

        Returns:
            List[List[float]]: A list of embeddings for each document in the input list.
                            Each embedding is represented as a list of float values.
        c                4    g | ]}||j         z            S  )r   ).0ir*   r-   s     r$   
<listcomp>z5VolcanoEmbeddings.embed_documents.<locals>.<listcomp>l   s:     
 
 
 !a$/))*
 
 
r,   r   )namer   )r   input)MaasExceptionc                    g | ]
}|d          S )	embeddingr2   )r3   ress     r$   r5   z5VolcanoEmbeddings.embed_documents.<locals>.<listcomp>}   s    EEEC,EEEr,   datazembed by volcengine Error: N)rangelenr   r   r   r   r8   r   
embeddingsextend
ValueError)	r*   r-   text_in_chunkslstchunkreqr8   respes	   ``       r$   r)   z!VolcanoEmbeddings.embed_documentsa   s   
 
 
 
 
1c%jj$/::
 
 
 # 	D 	DE !J#|   CD999999{--c22

EEVEEEFFFF  D D D !Bq!B!BCCCD
s   ABB.B))B.)r   r   r   r   )r&   r   r   r'   )r-   r.   r   r/   )__name__
__module____qualname____doc__r   __annotations__r   r   r   r   r   r   r
   r%   r+   r)   r2   r,   r$   r   r      s        33 $J$$$$I !%J$$$$I =D<<<<EFE  E
 GJ2KKK- - - X-^/ / / /     r,   r   )
__future__r   loggingtypingr   r   r   r   langchain_core.embeddingsr   langchain_core.utilsr	   r
   pydanticr   	getLoggerrH   loggerr   r2   r,   r$   <module>rU      s    " " " " " "  , , , , , , , , , , , , 0 0 0 0 0 0 ? ? ? ? ? ? ? ?      		8	$	$s s s s s	: s s s s sr,   