
    7|h                         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 d dlmZ d dlmZmZmZ d dlmZ  e j(                  e      Z G d d	e      Zy)
    N)AnyDictListMappingOptional)CallbackManagerForLLMRun)LLM)
get_fields)
ConfigDictFieldmodel_validator)enforce_stop_tokensc                      e Zd ZU dZdZeed<   	  ee      Z	e
eef   ed<   	  ed      Z ed	      ed
e
eef   defd              Zedeeef   fd       Zedefd       Z	 	 ddedeee      dee   dedef
dZy)Modala|  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                 L   t        |       j                         D ch c]  }|j                   }}|j                  di       }t	        |      D ]I  }||vs||v rt        d| d      t        j                  | d| d       |j                  |      ||<   K ||d<   |S c c}w )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         ]/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/llms/modal.pybuild_extrazModal.build_extra*   s     >H_=S=S=U#VEEKK#V #V

>2.v, 	;J!99&$vj\9I%JKK# %))34JN %+JJz$:j!	; "'~ $Ws   B!c                 >    i d| j                   id| j                  iS )zGet the identifying parameters.r   r   )r   r   selfs    r'   _identifying_paramszModal._identifying_params=   s2    
t001
t001
 	
    c                      y)zReturn type of llm.modal r*   s    r'   	_llm_typezModal._llm_typeE   s     r-   Npromptstoprun_managerkwargsc                 $   | j                   xs i }i ||}t        j                  | j                  ddid|i|      }	 ||j	                         d   v r|j	                         }d   }|t        ||      }|S # t
        $ r t        d      w xY w)zCall to Modal endpoint.zContent-Typezapplication/jsonr2   )urlheadersjsonz,LangChain requires 'prompt' key in response.)r   requestspostr   r9   KeyErrorr   )	r+   r2   r3   r4   r5   paramsresponseresponse_jsontexts	            r'   _callzModal._callJ   s     ""(b%F%f%==!! 2 F-f-
	K22 ( X& 'tT2D  	KIJJ	Ks    %A: :B)NN)__name__
__module____qualname____doc__r   str__annotations__r   dictr   r   r   r   model_configr   classmethodr(   propertyr   r,   r1   r   r   r   rA   r0   r-   r'   r   r      s    L##(#>L$sCx.> L (#c3h C   $" 
WS#X%6 
 
 3   %):>	 tCy! 67	
  
r-   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   	getLoggerrB   r    r   r0   r-   r'   <module>rT      sC     5 5  = 3 4 7 7 >			8	$VC Vr-   