a
    bg                     @   sl   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 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                   @   sb  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dZee e dddZ!e"e#eef d d!d"Z$e"e#eef d d#d$Z%e"ed d%d&Z&d*eeee  ee' eed'd(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_keyZforbid)extra)valuesreturnc                 C   sj   t t|dd|d< z6ddl}|j|d |d  |d |d d|d	< W n tyd   td
Y n0 |S )z?Validate that api key and python package exists in environment.r"   ZNLPCLOUD_API_KEYr   Nr   r   r   )r   r   r   zXCould not import nlpcloud python package. Please install it with `pip install nlpcloud`.)r	   r
   nlpcloudZClientZget_secret_valueImportError)clsr$   r&    r)   o/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/llms/nlpcloud.pyvalidate_environment:   s     


zNLPCloud.validate_environment)r%   c                 C   s2   | 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!   r,   selfr)   r)   r*   _default_paramsP   s    zNLPCloud._default_paramsc                 C   s(   i d| j id| jid| ji| jS )zGet the identifying parameters.r   r   r   )r   r   r   r/   r-   r)   r)   r*   _identifying_paramsa   s    zNLPCloud._identifying_paramsc                 C   s   dS )zReturn type of llm.r&   r)   r-   r)   r)   r*   	_llm_typek   s    zNLPCloud._llm_type)promptstoprun_managerkwargsr%   c                 K   sf   |rt |dkrtdn|r4t |dkr4|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_sequenceZgenerated_text)len
ValueErrorr/   r   Z
generation)r.   r2   r3   r4   r5   r6   paramsresponser)   r)   r*   _callp   s    
zNLPCloud._call)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   Zmodel_configr   r   r+   propertyr   r/   r0   r1   r   r;   r)   r)   r)   r*   r   	   sJ   
	  
r   N)typingr   r   r   r   r   Zlangchain_core.callbacksr   Z#langchain_core.language_models.llmsr   Zlangchain_core.utilsr	   r
   r   Zpydanticr   r   r   r)   r)   r)   r*   <module>   s
   