o
    ZhF                     @  st   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eZG dd dee	ZdS )	    )annotationsN)AnyDictListOptional)
Embeddings)get_from_dict_or_envpre_init)	BaseModelc                   @  s   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dZd#ddZd$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                 C  s   t |dd|d< t |dd|d< z$ddlm} ||d |d }||d  ||d  ||d	< W |S  ty?   td
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   ZVOLC_ACCESSKEYr   ZVOLC_SECRETKEYr   )MaasServicer   r   r   zMvolcengine package not found, please install it with `pip install volcengine`)r   volcengine.maasr   Zset_akZset_skImportError)clsr   r   r    r   `/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/embeddings/volcengine.pyvalidate_environment.   s,   
z&VolcanoEmbeddings.validate_environmenttextList[float]c                 C  s   |  |gd S )Nr   )embed_documents)selfr    r   r   r   embed_query^   s   zVolcanoEmbeddings.embed_querytexts	List[str]List[List[float]]c           	        s    fddt dt jD }g }|D ]9} j jd|d}zddlm}  j|}|	dd |d D  W q |yN } zt
d	| d
}~w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                   s   g | ]}|| j   qS r   )r   ).0ir#   r%   r   r   
<listcomp>l   s    z5VolcanoEmbeddings.embed_documents.<locals>.<listcomp>r   )namer   )r   input)MaasExceptionc                 S  s   g | ]}|d  qS )Z	embeddingr   )r(   resr   r   r   r+   }   s    datazembed by volcengine Error: N)rangelenr   r   r   r   r.   r   Z
embeddingsextend
ValueError)	r#   r%   Ztext_in_chunkslstchunkreqr.   resper   r*   r   r"   a   s&   z!VolcanoEmbeddings.embed_documents)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"   r   r   r   r   r      s,   
 
/r   )
__future__r   loggingtypingr   r   r   r   Zlangchain_core.embeddingsr   Zlangchain_core.utilsr   r	   Zpydanticr
   	getLoggerr:   loggerr   r   r   r   r   <module>   s    
