
    Ng5                     h    d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
mZmZ  G d de
e          ZdS )    )AnyDictListOptional)
Embeddings)get_from_dict_or_env)	BaseModelFieldmodel_validatorc                      e Zd ZU dZ edd          Zeed<    ed          Ze	ed<   	 e	ed	<   	 dZ
ee         ed
<   	  ed          ededefd                        Zde	dee         fdZdee	         deee                  fdZdS )ZhipuAIEmbeddingsu  ZhipuAI embedding model integration.

    Setup:

        To use, you should have the ``zhipuai`` python package installed, and the
        environment variable ``ZHIPU_API_KEY`` set with your API KEY.

        More instructions about ZhipuAi Embeddings, you can get it
        from  https://open.bigmodel.cn/dev/api#vector

        .. code-block:: bash

            pip install -U zhipuai
            export ZHIPU_API_KEY="your-api-key"

    Key init args — completion params:
        model: Optional[str]
            Name of ZhipuAI model to use.
        api_key: str
            Automatically inferred from env var `ZHIPU_API_KEY` if not provided.

    See full list of supported init args and their descriptions in the params section.

    Instantiate:

        .. code-block:: python

            from langchain_community.embeddings import ZhipuAIEmbeddings

            embed = ZhipuAIEmbeddings(
                model="embedding-2",
                # api_key="...",
            )

    Embed single text:
        .. code-block:: python

            input_text = "The meaning of life is 42"
            embed.embed_query(input_text)

        .. code-block:: python

            [-0.003832892, 0.049372625, -0.035413884, -0.019301128, 0.0068899863, 0.01248398, -0.022153955, 0.006623926, 0.00778216, 0.009558191, ...]


    Embed multiple text:
        .. code-block:: python

            input_texts = ["This is a test query1.", "This is a test query2."]
            embed.embed_documents(input_texts)

        .. code-block:: python

            [
                [0.0083934665, 0.037985895, -0.06684559, -0.039616987, 0.015481004, -0.023952313, ...],
                [-0.02713102, -0.005470169, 0.032321047, 0.042484466, 0.023290444, 0.02170547, ...]
            ]
    NT)defaultexcludeclientzembedding-2)r   modelapi_key
dimensionsbefore)modevaluesreturnc                     t          |dd          |d<   	 ddlm}  ||d                   |d<   n# t          $ r t          d          w xY w|S )z/Validate that auth token exists in environment.r   ZHIPUAI_API_KEYr   )ZhipuAI)r   r   zUCould not import zhipuai python package.Please install it with `pip install zhipuai`.)r   zhipuair   ImportError)clsr   r   s      b/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/embeddings/zhipuai.pyvalidate_environmentz&ZhipuAIEmbeddings.validate_environmentO   s     1DUVVy	''''''&wvi/@AAAF8 	 	 	@  	
 s	   2 Atextc                 >    |                      |g          }|d         S )z
        Embeds a text using the AutoVOT algorithm.

        Args:
            text: A text to embed.

        Returns:
            Input document's embedded list.
        r   )embed_documents)selfr    resps      r   embed_queryzZhipuAIEmbeddings.embed_query_   s"     ##TF++Aw    textsc                     | j         -| j        j                            | j        || j                   }n&| j        j                            | j        |          }d |j        D             }|S )a0  
        Embeds a list of text documents using the AutoVOT algorithm.

        Args:
            texts: A list of text documents to embed.

        Returns:
            A list of embeddings for each document in the input list.
            Each embedding is represented as a list of float values.
        N)r   inputr   )r   r)   c                     g | ]	}|j         
S  )	embedding).0rs     r   
<listcomp>z5ZhipuAIEmbeddings.embed_documents.<locals>.<listcomp>   s    555aak555r&   )r   r   
embeddingscreater   data)r#   r'   r$   r0   s       r   r"   z!ZhipuAIEmbeddings.embed_documentsl   sv     ?&;)00j? 1  DD ;)00tz0OOD5549555
r&   )__name__
__module____qualname____doc__r
   r   r   __annotations__r   strr   r   intr   classmethodr   r   r   floatr%   r"   r+   r&   r   r   r      s"        9 9v %d333FC333}---E3---LLLN $J$$$
 _(###$ 3    [ $# U    T#Y 4U3D      r&   r   N)typingr   r   r   r   langchain_core.embeddingsr   langchain_core.utilsr   pydanticr	   r
   r   r   r+   r&   r   <module>r@      s    , , , , , , , , , , , , 0 0 0 0 0 0 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6x x x x x	: x x x x xr&   