
    Ng                     z    d dl mZmZmZmZ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mZ  G d de	          ZdS )	    )AnyDictListMappingOptional)CallbackManagerForLLMRun)LLM)convert_to_secret_strget_from_dict_or_envpre_init)
ConfigDict	SecretStrc                      e Zd ZU dZdZeed<   dZeed<   	 dZ	e
ed<   	 dZeed	<   	 d
Zeed<   	 dZeed<   	 dZe
ed<   	 dZe
ed<   	 dZe
ed<   	 g Zee         ed<   	 dZeed<   	 dZeed<   	 dZeed<   	 dZeed<   	 dZeed<   	 dZee         ed<    ed          Zede de fd            Z!e"de#eef         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 ))NLPCloudaa  NLPCloud large language models.

    To use, you should have the ``nlpcloud`` python package installed, and the
    environment variable ``NLPCLOUD_API_KEY`` set with your API key.

    Example:
        .. code-block:: python

            from langchain_community.llms import NLPCloud
            nlpcloud = NLPCloud(model="finetuned-gpt-neox-20b")
    Nclientzfinetuned-gpt-neox-20b
model_nameTgpuenlanggffffff?temperature   
max_lengthlength_no_inputremove_inputremove_end_sequence	bad_wordsg      ?top_p2   top_krepetition_penalty   	num_beamsnum_return_sequencesnlpcloud_api_keyforbid)extravaluesreturnc                    t          t          |dd                    |d<   	 ddl}|                    |d         |d                                         |d         |d                   |d	<   n# t
          $ r t          d
          w xY w|S )z?Validate that api key and python package exists in environment.r$   NLPCLOUD_API_KEYr   Nr   r   r   )r   r   r   zXCould not import nlpcloud python package. Please install it with `pip install nlpcloud`.)r
   r   nlpcloudClientget_secret_valueImportError)clsr'   r+   s      ]/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/llms/nlpcloud.pyvalidate_environmentzNLPCloud.validate_environment:   s     &; );=OPP&
 &
!"	OOO'|$)*;;==5MF^	  /    F8  	 	 	A  	
 s   A
A. .Bc                     | j         | j        | j        | j        | j        | j        | j        | j        | j        | j	        | j
        dS )z4Get the default parameters for calling NLPCloud API.r   r   r   r   r   r   r   r   r    r"   r#   r3   selfs    r0   _default_paramszNLPCloud._default_paramsP   sP      +/#3 -#'#;ZZ"&"9$($=
 
 	
    c                 J    i d| j         id| j        id| j        i| j        S )zGet the identifying parameters.r   r   r   )r   r   r   r6   r4   s    r0   _identifying_paramszNLPCloud._identifying_paramsa   sH    
T_-
dh
 ty!
 "	
 	
r7   c                     dS )zReturn type of llm.r+    r4   s    r0   	_llm_typezNLPCloud._llm_typek   s	     zr7   promptstoprun_managerkwargsc                     |r"t          |          dk    rt          d          |rt          |          dk    r	|d         }nd}i | j        |} | j        j        |fd|i|}|d         S )al  Call out to NLPCloud's create endpoint.

        Args:
            prompt: The prompt to pass into the model.
            stop: Not supported by this interface (pass in init method)

        Returns:
            The string generated by the model.

        Example:
            .. code-block:: python

                response = nlpcloud("Tell me a joke.")
        r!   zXNLPCloud only supports a single stop sequence per generation.Pass in a list of length 1.r   Nend_sequencegenerated_text)len
ValueErrorr6   r   
generation)r5   r=   r>   r?   r@   rB   paramsresponses           r0   _callzNLPCloud._callp   s    *  	 CIIMM.    	 c$ii1nn7LLL3D(3F3)4;)&VV|VvVV())r7   )NN))__name__
__module____qualname____doc__r   r   __annotations__r   strr   boolr   r   floatr   intr   r   r   r   r   r   r   r    r"   r#   r$   r   r   r   model_configr   r   r1   propertyr   r6   r9   r<   r   rI   r;   r7   r0   r   r   	   s        
 
 FC.J...C%D#.K+JE OT   SL$- $$$$:ItCy5E5DE3OOOO ####:Is* !#!!!;,0hy)000:  L $ 4    X* 
c!2 
 
 
 X
  
WS#X%6 
 
 
 X
 3    X %):>	 *  * * tCy! * 67	 *
  * 
 *  *  *  *  *  *r7   r   N)typingr   r   r   r   r   langchain_core.callbacksr   #langchain_core.language_models.llmsr	   langchain_core.utilsr
   r   r   pydanticr   r   r   r;   r7   r0   <module>rZ      s    5 5 5 5 5 5 5 5 5 5 5 5 5 5 = = = = = = 3 3 3 3 3 3 V V V V V V V V V V * * * * * * * *G* G* G* G* G*s G* G* G* G* G*r7   