
    Ng                         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dS )
    N)AnyDictListMappingOptional)CallbackManagerForLLMRun)LLM)
get_fields)
ConfigDictFieldmodel_validator)enforce_stop_tokensc                   R   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dS )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                 \   d t          |                                           D             }|                    di           }t          |          D ]U}||vrO||v rt	          d| d          t
                              | d| d           |                    |          ||<   V||d<   |S )z>Build extra kwargs from additional params that were passed in.c                     h | ]	}|j         
S  )alias).0fields     Z/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/llms/modal.py	<setcomp>z$Modal.build_extra.<locals>.<setcomp>.   s    #V#V#VEEK#V#V#V    r   zFound z supplied twice.zJ was transferred to model_kwargs.
                    Please confirm that z is what you intended.)r
   r   getlist
ValueErrorloggerwarningpop)clsr   all_required_field_namesr   
field_names        r!   build_extrazModal.build_extra*   s     $W#VZ__=S=S=U=U#V#V#V 

>2..v,, 	; 	;J!999&&$%Jj%J%J%JKKK# N N)3N N N   %+JJz$:$:j!!&~r#   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=   s,    
t01
t01
 	
r#   c                     dS )zReturn type of llm.modalr   r/   s    r!   	_llm_typezModal._llm_typeE   s	     wr#   Npromptstoprun_managerkwargsc                 :   | j         pi }i ||}t          j        | j        ddid|i|          }	 ||                                d         v r|                                }n# t
          $ r t          d          w xY w|d         }|t          ||          }|S )zCall to Modal endpoint.zContent-Typezapplication/jsonr5   )urlheadersjsonz,LangChain requires 'prompt' key in response.)r   requestspostr   r<   KeyErrorr   )	r0   r5   r6   r7   r8   paramsresponseresponse_jsontexts	            r!   _callzModal._callJ   s     "(b%F%f%=! 2 F-f-
 
 
	K222 ( 	K 	K 	KIJJJ	KX& 'tT22Ds   0A$ $A>)NN)__name__
__module____qualname____doc__r   str__annotations__r   dictr   r   r   r   model_configr   classmethodr-   propertyr   r1   r4   r   r   r   rD   r   r#   r!   r   r      s          L##(5#>#>#>L$sCx.>>> :  L _(###c3h C    [ $#" 
WS#X%6 
 
 
 X
 3    X %):>	  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   	getLoggerrE   r'   r   r   r#   r!   <module>rW      s     5 5 5 5 5 5 5 5 5 5 5 5 5 5  = = = = = = 3 3 3 3 3 3 4 4 4 4 4 4 7 7 7 7 7 7 7 7 7 7 > > > > > >		8	$	$V V V V VC V V V V Vr#   