
    7|hF                        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y)	    )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y)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   clientc                    t        |dd      |d<   t        |dd      |d<   	 ddlm}  ||d   |d         }|j                  |d          |j	                  |d          ||d	<   |S # t
        $ r t        d
      w xY w)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)clsvaluesr   r   s       h/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/embeddings/volcengine.pyvalidate_environmentz&VolcanoEmbeddings.validate_environment.   s    .  4 
|
  4 
|	3 1ABFMM&./MM&./%F8   	+ 	s   AA& &A;c                ,    | j                  |g      d   S )Nr   )embed_documents)selftexts     r#   embed_queryzVolcanoEmbeddings.embed_query^   s    ##TF+A..    c                   t        dt        |      | j                        D cg c]  }|||| j                  z     }}g }|D ]e  }| j                  | j                  d|d}	 ddlm} | j                  j                  |      }|j                  |d   D 	cg c]  }	|	d   	 c}	       g |S c c}w c c}	w # $ r}
t        d|
       d}
~
ww xY w)	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.
        r   )namer   )r   input)MaasExceptiondata	embeddingzembed by volcengine Error: N)rangelenr   r   r   r   r.   r   
embeddingsextend
ValueError)r'   textsitext_in_chunkslstchunkreqr.   respreses              r#   r&   z!VolcanoEmbeddings.embed_documentsa   s     1c%j$//:
 !a$//)*
 
 # 	DE !JJ#|| CD9{{--c2

VEC,EF	D 
)
" F  D #>qc!BCCDs/   B,"3B6B1
!B61B66C;C		C)r"   r   returnr   )r(   r   r?   zList[float])r6   z	List[str]r?   zList[List[float]])__name__
__module____qualname____doc__r   __annotations__r   r   r   r   r   r   r
   r$   r)   r&    r*   r#   r   r      s    3 $J$I !%J$I =D#<EFCE  E3
 GSJ2K- -^/r*   r   )
__future__r   loggingtypingr   r   r   r   langchain_core.embeddingsr   langchain_core.utilsr	   r
   pydanticr   	getLoggerr@   loggerr   rE   r*   r#   <module>rN      s<    "  , , 0 ? 			8	$s	: sr*   