
    dh                         S SK r S SKJr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  S SKJrJrJr  S SKJr  \ R(                  " \5      r " S S	\5      rg)
    N)AnyDictListMappingOptional)CallbackManagerForLLMRun)LLM)
get_fields)
ConfigDictFieldmodel_validator)enforce_stop_tokensc                      \ rS rSr% SrSr\\S'    \" \	S9r
\\\4   \S'    \" SS9r\" S	S
9\S\\\4   S\4S j5       5       r\S\\\4   4S j5       r\S\4S j5       r  SS\S\\\      S\\   S\S\4
S jjrSrg)Modal   a\  Modal large language models.

To use, you should have the ``modal-client`` python package installed.

Any parameters that are valid to be passed to the call can be passed
in, even if not explicitly saved on this class.

Example:
    .. code-block:: python

        from langchain_community.llms import Modal
        modal = Modal(endpoint_url="")

 endpoint_url)default_factorymodel_kwargsforbid)extrabefore)modevaluesreturnc                 T   [        U 5      R                  5        Vs1 sH  o"R                  iM     nnUR                  S0 5      n[	        U5       HL  nXS;  d  M
  XT;   a  [        SU S35      e[        R                  U SU S35        UR                  U5      XE'   MN     XAS'   U$ s  snf )z>Build extra kwargs from additional params that were passed in.r   zFound z supplied twice.zJ was transferred to model_kwargs.
                    Please confirm that z is what you intended.)	r
   r   aliasgetlist
ValueErrorloggerwarningpop)clsr   fieldall_required_field_namesr   
field_names         V/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/llms/modal.pybuild_extraModal.build_extra*   s     >H_=S=S=U#V=UEKK=U #V

>2.v,J9&$vj\9I%JKK# %))34JN %+JJz$:! ' "'~ $Ws   B%c                 >    0 SU R                   0ESU R                  0E$ )zGet the identifying parameters.r   r   )r   r   selfs    r(   _identifying_paramsModal._identifying_params=   s2    
t001
t001
 	
    c                     g)zReturn type of llm.modal r,   s    r(   	_llm_typeModal._llm_typeE   s     r0   Npromptstoprun_managerkwargsc                 .   U R                   =(       d    0 n0 UEUEn[        R                  " U R                  SS0SU0UES9n XR	                  5       S   ;   a  UR	                  5       nWS   nUb  [        X5      nU$ ! [
         a    [        S5      ef = f)zCall to Modal endpoint.zContent-Typezapplication/jsonr6   )urlheadersjsonz,LangChain requires 'prompt' key in response.)r   requestspostr   r=   KeyErrorr   )	r-   r6   r7   r8   r9   paramsresponseresponse_jsontexts	            r(   _callModal._callJ   s     ""(b%F%f%==!! 2 F-f-
	K22 ( X& 't2D  	KIJJ	Ks   &A> >Br3   )NN)__name__
__module____qualname____firstlineno____doc__r   str__annotations__r   dictr   r   r   r   model_configr   classmethodr)   propertyr   r.   r4   r   r   r   rE   __static_attributes__r3   r0   r(   r   r      s    L##(#>L$sCx.> L (#c3h C   $" 
WS#X%6 
 
 3   %):>	 tCy! 67	
  
 r0   r   )loggingtypingr   r   r   r   r   r>   langchain_core.callbacksr   #langchain_core.language_models.llmsr	   langchain_core.utils.pydanticr
   pydanticr   r   r   langchain_community.llms.utilsr   	getLoggerrG   r!   r   r3   r0   r(   <module>r[      sA     5 5  = 3 4 7 7 >			8	$VC Vr0   