
    dh                     r    S SK JrJrJrJr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Jr   " S S\	5      rg)	    )AnyDictListMappingOptional)CallbackManagerForLLMRun)LLM)convert_to_secret_strget_from_dict_or_envpre_init)
ConfigDict	SecretStrc                      \ rS rSr% SrSr\\S'   Sr\	\S'    Sr
\\S'    S	r\	\S
'    Sr\\S'    Sr\\S'    Sr\\S'    Sr\\S'    Sr\\S'    / r\\	   \S'    Sr\\S'    Sr\\S'    Sr\\S'    Sr\\S'    Sr\\S'    Sr\\   \S'   \" SS9r\ S\!S\!4S  j5       r"\#S\$\	\4   4S! j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)+NLPCloud	   aE  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                     [        [        USS5      5      US'    SSKnUR                  US   US   R	                  5       US   US   S9US	'   U$ ! [
         a    [        S
5      ef = f)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      Y/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/llms/nlpcloud.pyvalidate_environmentNLPCloud.validate_environment:   s     &; );=OP&
!"	'|$)*;;=5MF^	  /  F8   	A 	s   3A A&c                     U R                   U R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  S.$ )z4Get the default parameters for calling NLPCloud API.r   r   r   r   r   r   r   r    r!   r#   r$   r5   selfs    r1   _default_paramsNLPCloud._default_paramsP   sg      ++//#33 --#'#;#;ZZZZ"&"9"9$($=$=
 	
    c                 r    0 SU R                   0ESU R                  0ESU R                  0EU R                  E$ )zGet the identifying parameters.r   r   r   )r   r   r   r8   r6   s    r1   _identifying_paramsNLPCloud._identifying_paramsa   sQ    
T__-
dhh
 tyy!
 ""	
 	
r:   c                     g)zReturn type of llm.r,    r6   s    r1   	_llm_typeNLPCloud._llm_typek   s     r:   promptstoprun_managerkwargsc                     U(       a  [        U5      S:  a  [        S5      eU(       a  [        U5      S:X  a  US   nOSn0 U R                  EUEnU R                  R                  " U4SU0UD6nUS   $ )a$  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
ValueErrorr8   r   
generation)r7   rB   rC   rD   rE   rG   paramsresponses           r1   _callNLPCloud._callp   s    * CIM.  c$i1n7LL3D((3F3;;))&V|VvV())r:   r?   )NN)+__name__
__module____qualname____firstlineno____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   r2   propertyr   r8   r<   r@   r   rN   __static_attributes__r?   r:   r1   r   r   	   s   
 FC.J.C%D#.K+JE OT SL$- $$:ItCy5E5DE3OO ##:Is* !#!;,0hy)0L $ 4  * 
c!2 
 
  
WS#X%6 
 
 3   %):>	 * * tCy! * 67	 *
  * 
 *  *r:   r   N)typingr   r   r   r   r   langchain_core.callbacksr   #langchain_core.language_models.llmsr	   langchain_core.utilsr
   r   r   pydanticr   r   r   r?   r:   r1   <module>rb      s(    5 5 = 3 V V *G*s G*r:   