
    Ng                        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mZmZ d dlmZ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 G d dee          ZdS )    )annotationsN)AnyCallableDictListOptional)
Embeddings)convert_to_secret_strget_from_dict_or_envpre_init)	BaseModel
ConfigDictField	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       b/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/embeddings/minimax.py_create_retry_decoratorr)      s^     JKKK,,+VVV%fgo>>	       
embeddingsMiniMaxEmbeddings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*   c                      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
<   	  e	dd          Z
ded<   	  e	dd          Zded<   	  edd          Zed#d            Zd$dZd%dZd&d"ZdS )'r,   u1  MiniMax embedding model integration.

    Setup:
        To use, you should have the environment variable ``MINIMAX_GROUP_ID`` and
        ``MINIMAX_API_KEY`` set with your API token.

        .. code-block:: bash

            export MINIMAX_API_KEY="your-api-key"
            export MINIMAX_GROUP_ID="your-group-id"

    Key init args — completion params:
        model: Optional[str]
            Name of ZhipuAI model to use.
        api_key: Optional[str]
            Automatically inferred from env var `MINIMAX_GROUP_ID` if not provided.
        group_id: Optional[str]
            Automatically inferred from env var `MINIMAX_GROUP_ID` 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 MiniMaxEmbeddings

            embed = MiniMaxEmbeddings(
                model="embo-01",
                # api_key="...",
                # group_id="...",
                # other
            )

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

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

        .. code-block:: python

            [0.03016241, 0.03617699, 0.0017198119, -0.002061239, -0.00029994643, -0.0061320597, -0.0043635326, ...]

    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.0021588828, -0.007608119, 0.029349545, -0.0038194496, 0.008031177, -0.004529633, -0.020150753, ...],
                [ -0.00023150232, -0.011122423, 0.016930554, 0.0083089275, 0.012633711, 0.019683322, -0.005971041, ...]
            ]
    z&https://api.minimax.chat/v1/embeddingsstrendpoint_urlzembo-01modeldbembed_type_dbqueryembed_type_queryNgroup_id)defaultaliaszOptional[str]minimax_group_idapi_keyzOptional[SecretStr]minimax_api_keyTforbid)populate_by_nameextravaluesr   r   c                    t          |ddgd          }t          t          |ddgd                    }||d<   ||d<   |S )z9Validate that group id and api key exists in environment.r@   r=   MINIMAX_GROUP_IDrB   rA   MINIMAX_API_KEY)r   r
   )clsrF   r@   rB   s       r(   validate_environmentz&MiniMaxEmbeddings.validate_environment}   sk     0'46H
 
 0 *I68I 
 

 &6!"$3 !r*   texts	List[str]
embed_typeList[List[float]]c                2   | j         ||d}d| j                                         dd}d| j        i}t	          j        | j        |||          }|                                }|d         d         d	k    rt          d
|d                    |d         }|S )N)r8   typerL   zBearer zapplication/json)AuthorizationzContent-TypeGroupId)paramsheadersjson	base_respstatus_coder   zMiniMax API returned an error: vectors)	r8   rB   get_secret_valuer@   requestspostr7   rV   
ValueError)	selfrL   rN   payloadrU   rT   responseparsed_responser+   s	            r(   r1   zMiniMaxEmbeddings.embed   s     Z
 
 Qt';'L'L'N'NPP.
 
 t,

 =fgG
 
 
 #--// ;'6!;;P/+2NPP   %Y/
r*   c                4    t          | || j                  }|S )zEmbed documents using a MiniMax embedding endpoint.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        rL   rN   )r4   r:   )r^   rL   r+   s      r(   embed_documentsz!MiniMaxEmbeddings.embed_documents   s!     &d%DDVWWW
r*   textList[float]c                B    t          | |g| j                  }|d         S )zEmbed a query using a MiniMax embedding endpoint.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        rc   r   )r4   r<   )r^   re   r+   s      r(   embed_queryzMiniMaxEmbeddings.embed_query   s0     &4+@
 
 

 !}r*   )rF   r   r   r   )rL   rM   rN   r6   r   rO   )rL   rM   r   rO   )re   r6   r   rf   )__name__
__module____qualname____doc__r7   __annotations__r8   r:   r<   r   r@   rB   r   model_configr   rK   r1   rd   rh    r*   r(   r,   r,   /   s5        8 8t AL@@@@E'M#####&+eD
&K&K&KKKKK#+05Y+O+O+OOOOOO":  L
    X# # # #J
 
 
 
     r*   )r   r   )r+   r,   r-   r   r.   r   r   r   ) 
__future__r   r#   typingr   r   r   r   r   r[   langchain_core.embeddingsr	   langchain_core.utilsr
   r   r   pydanticr   r   r   r   tenacityr   r   r   r   	getLoggerri   r"   r)   r4   r,   ro   r*   r(   <module>rw      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 < < < < < < < < < < < <            
	8	$	$    . . . .Z Z Z Z Z	: Z Z Z Z Zr*   