
    dh                        S r SSKJr  SSKrSSKJrJrJrJr  SSK	r	SSK
Jr  SSKJr  SSKJrJrJr  SSKJrJrJrJrJr  SS	KJr  \R4                  " \5      r " S
 S\5      r " S S\5      r " S S\\5      rg)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                  r    \ rS rSr% SrS\S'   S\S'   S\S'   S\S'   \" S	S
9\SS j5       5       rSS jr	Sr
g)_MinimaxEndpointClient   z(API client for the Minimax LLM endpoint.strhostgroup_idr   api_keyapi_urlbefore)modec                <    SU;  a  US   nUS   nU SU 3nXAS'   U$ )Nr   r   r   z /v1/text/chatcompletion?GroupId= )clsvaluesr   r   r   s        X/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/llms/minimax.pyset_api_url"_MinimaxEndpointClient.set_api_url"   s=     F"&>Dj)H>xjIG '9    c                   SSU R                   R                  5        30n[        R                  " U R                  X!S9nUR
                  (       d%  [        SUR                   SUR                   35      eUR                  5       S   S   S:  a9  [        S	UR                  5       S   S    SUR                  5       S   S
    35      eUR                  5       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/   _MinimaxEndpointClient.post,   s    "gdll.K.K.M-N$OP==wM{{uX%9%9$:(8==/RSS==?;'6:x}}{3MBC8==?;7EFH  }}w''r$   r   N)r    Dict[str, Any]returnr   )r4   r   r8   r   )__name__
__module____qualname____firstlineno____doc____annotations__r   classmethodr"   r/   __static_attributes__r   r$   r!   r   r      s>    2
IML(#  $(r$   r   c                     \ rS rSr% Sr\" SS9rS\S'   SrS\S	'    S
r	S\S'    Sr
S\S'    SrS\S'    \" \S9rS\S'    SrS\S'   SrS\S'   SrS\S'   \SS j5       r\S S j5       r\S S j5       r\S!S j5       rSrg)"MinimaxCommon:   z4Common parameters for Minimax large language models.r   )protected_namespacesr   _clientzabab5.5-chatr   model   int
max_tokensgffffff?floattemperaturegffffff?top_p)default_factoryr7   model_kwargsNzOptional[str]minimax_api_hostminimax_group_idzOptional[SecretStr]minimax_api_keyc                    [        [        USS5      5      US'   [        USS5      US'   [        USSSS9US'   [        US   US   US   S	9US
'   U$ )z?Validate that api key and python package exists in environment.rQ   MINIMAX_API_KEYrP   MINIMAX_GROUP_IDrO   MINIMAX_API_HOSTzhttps://api.minimax.chat)default)r   r   r   rE   )r
   r   r   )r   r    s     r!   validate_environment"MinimaxCommon.validate_environmentN   s     %: ):<MN%
 ! &:&(:&
!" &:.	&
!" 3*+,-./
y
 r$   c                x    U R                   U R                  U R                  U R                  S.U R                  E$ )z2Get the default parameters for calling OpenAI API.)rF   tokens_to_generaterK   rL   )rF   rI   rK   rL   rN   r3   s    r!   _default_paramsMinimaxCommon._default_paramse   s<     ZZ"&//++ZZ	

 
 	
r$   c                :    0 SU R                   0EU R                  E$ )zGet the identifying parameters.rF   )rF   r\   r[   s    r!   _identifying_params!MinimaxCommon._identifying_paramsp   s$     A7DJJ'@4+?+?@@r$   c                    g)zReturn type of llm.minimaxr   r[   s    r!   	_llm_typeMinimaxCommon._llm_typeu   s     r$   )r    r   r8   r   )r8   r7   )r8   r   )r9   r:   r;   r<   r=   r   model_configr>   rF   rI   rK   rL   r   dictrN   rO   rP   rQ   r   rW   propertyr\   r_   rc   r@   r   r$   r!   rB   rB   :   s    >26L##E3JAKQE5D#(#>L.>V&*m*&*m*+/O(/ , 
 
 A A  r$   rB   c                  <    \ rS rSrSr  S         SS jjrSrg)Minimax{   a  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                    U R                   nSUS./US'   UR                  U5        U R                  R                  U5      nUb  [	        Xb5      nU$ )zCall 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_typer2   messages)r\   updaterE   r/   r   )r3   promptstoprun_managerkwargsr4   r2   s          r!   _callMinimax._call   sX      &&/5vFG
v||  ) 't2Dr$   r   )NN)
rp   r   rq   zOptional[List[str]]rr   z"Optional[CallbackManagerForLLMRun]rs   r   r8   r   )r9   r:   r;   r<   r=   rt   r@   r   r$   r!   ri   ri   {   sI    
 %):>	 " 8	
  
 r$   ri   ) r=   
__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   	getLoggerr9   loggerr   rB   ri   r   r$   r!   <module>r      sn    " "    4 V V M M >			8	$(Y (@>I >B&mS &r$   