
    7|h                        d Z ddlmZ ddlZddlmZmZmZmZ ddl	Z	ddl
m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mZ dd	lmZ  ej4                  e      Z G d
 de      Z G d de      Z G d dee      Zy)zWrapper around Minimax APIs.    )annotationsN)AnyDictListOptional)CallbackManagerForLLMRun)LLM)convert_to_secret_strget_from_dict_or_envpre_init)	BaseModel
ConfigDictField	SecretStrmodel_validator)enforce_stop_tokensc                  l    e Zd ZU dZded<   ded<   ded<   ded<    ed	      edd
              ZddZy)_MinimaxEndpointClientz(API client for the Minimax LLM endpoint.strhostgroup_idr   api_keyapi_urlbefore)modec                :    d|vr|d   }|d   }| d| }||d<   |S )Nr   r   r   z /v1/text/chatcompletion?GroupId= )clsvaluesr   r   r   s        _/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/llms/minimax.pyset_api_urlz"_MinimaxEndpointClient.set_api_url"   s?     F"&>Dj)H>xjIG 'F9    c                   dd| j                   j                          i}t        j                  | j                  ||      }|j
                  s%t        d|j                   d|j                         |j                         d   d   dkD  r9t        d	|j                         d   d    d|j                         d   d
          |j                         d   S )NAuthorizationzBearer )headersjsonzHTTP z error: 	base_respstatus_coder   zAPI 
status_msgreply)
r   get_secret_valuerequestspostr   ok
ValueErrorr(   textr&   )selfrequestr%   responses       r    r-   z_MinimaxEndpointClient.post,   s    "gdll.K.K.M-N$OP==wWM{{uX%9%9$:(8==/RSS==?;'6:x}}{3MBC8==?;7EFH  }}w''r"   N)r   Dict[str, Any]returnr   )r2   r   r5   r   )	__name__
__module____qualname____doc____annotations__r   classmethodr!   r-   r   r"   r    r   r      s>    2
IML(#  $(r"   r   c                      e Zd ZU dZ e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<   	  ee      Zded<   	 dZded<   dZded<   dZded<   edd       Zedd       Zedd       Zed d       Zy)!MinimaxCommonz4Common parameters for Minimax large language models.r   )protected_namespacesr   _clientzabab5.5-chatr   model   int
max_tokensgffffff?floattemperaturegffffff?top_p)default_factoryr4   model_kwargsNzOptional[str]minimax_api_hostminimax_group_idzOptional[SecretStr]minimax_api_keyc                    t        t        |dd            |d<   t        |dd      |d<   t        |ddd      |d<   t        |d   |d   |d   	      |d
<   |S )z?Validate that api key and python package exists in environment.rK   MINIMAX_API_KEYrJ   MINIMAX_GROUP_IDrI   MINIMAX_API_HOSTzhttps://api.minimax.chat)default)r   r   r   r?   )r
   r   r   )r   r   s     r    validate_environmentz"MinimaxCommon.validate_environmentN   s     %: ):<MN%
 ! &:&(:&
!" &:.	&
!" 3*+,-./
y
 r"   c                x    | j                   | j                  | j                  | j                  d| j                  S )z2Get the default parameters for calling OpenAI API.)r@   tokens_to_generaterE   rF   )r@   rC   rE   rF   rH   r1   s    r    _default_paramszMinimaxCommon._default_paramse   s<     ZZ"&//++ZZ	

 
 	
r"   c                :    i d| j                   i| j                  S )zGet the identifying parameters.r@   )r@   rU   rT   s    r    _identifying_paramsz!MinimaxCommon._identifying_paramsp   s$     A7DJJ'@4+?+?@@r"   c                     y)zReturn type of llm.minimaxr   rT   s    r    	_llm_typezMinimaxCommon._llm_typeu   s     r"   )r   r   r5   r   )r5   r4   )r5   r   )r6   r7   r8   r9   r   model_configr:   r@   rC   rE   rF   r   dictrH   rI   rJ   rK   r   rQ   propertyrU   rW   rZ   r   r"   r    r=   r=   :   s    >26L##E3JAKQE5D#(#>L.>V&*m*&*m*+/O(/ , 
 
 A A  r"   r=   c                  0    e Zd ZdZ	 	 d	 	 	 	 	 	 	 	 	 ddZy)Minimaxa  Minimax large language models.

    To use, you should have the environment variable
    ``MINIMAX_API_KEY`` and ``MINIMAX_GROUP_ID`` set with your API key,
    or pass them as a named parameter to the constructor.
    Example:
     . code-block:: python
         from langchain_community.llms.minimax import Minimax
         minimax = Minimax(model="<model_name>", minimax_api_key="my-api-key",
          minimax_group_id="my-group-id")
    Nc                    | j                   }d|dg|d<   |j                  |       | j                  j                  |      }|t	        ||      }|S )a)  Call out to Minimax's completion endpoint to chat
        Args:
            prompt: The prompt to pass into the model.
        Returns:
            The string generated by the model.
        Example:
            .. code-block:: python
                response = minimax("Tell me a joke.")
        USER)sender_typer0   messages)rU   updater?   r-   r   )r1   promptstoprun_managerkwargsr2   r0   s          r    _callzMinimax._call   sZ      &&/5vFG
v||  ) 'tT2Dr"   )NN)
re   r   rf   zOptional[List[str]]rg   z"Optional[CallbackManagerForLLMRun]rh   r   r5   r   )r6   r7   r8   r9   ri   r   r"   r    r_   r_   {   sD    
 %):>	 " 8	
  
r"   r_   ) r9   
__future__r   loggingtypingr   r   r   r   r,   langchain_core.callbacksr   #langchain_core.language_models.llmsr	   langchain_core.utilsr
   r   r   pydanticr   r   r   r   r   langchain_community.llms.utilsr   	getLoggerr6   loggerr   r=   r_   r   r"   r    <module>rt      sp    " "    4 V V M M >			8	$(Y (@>I >B&mS &r"   