a
    bg;                     @   s   d dl 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mZmZmZ d dlmZ e eZG dd	 d	e
eZdS )
    N)AnyDictListMappingOptional)CallbackManagerForLLMRun)LLM)convert_to_secret_strget_from_dict_or_envpre_init)	BaseModel
ConfigDictField	SecretStrmodel_validator)enforce_stop_tokensc                   @   s   e Zd ZU dZdZeed< eedZ	e
eef ed< dZee ed< edd	Zed
dee
eef edddZee
e
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 )
PipelineAIa  PipelineAI large language models.

    To use, you should have the ``pipeline-ai`` python package installed,
    and the environment variable ``PIPELINE_API_KEY`` set with your API key.

    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 PipelineAI
            pipeline = PipelineAI(pipeline_key="")
     pipeline_key)default_factorypipeline_kwargsNpipeline_api_keyZforbid)extrabefore)mode)valuesreturnc                 C   s|   t t| j }|di }t|D ]H}||vr&||v rJtd| dt| d| d ||||< q&||d< |S )z>Build extra kwargs from additional params that were passed in.r   zFound z supplied twice.zM was transferred to pipeline_kwargs.
                    Please confirm that z is what you intended.)	setlistZmodel_fieldskeysget
ValueErrorloggerwarningpop)clsr   Zall_required_field_namesr   
field_name r'   q/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/llms/pipelineai.pybuild_extra1   s    zPipelineAI.build_extrac                 C   s   t t|dd}||d< |S )z?Validate that api key and python package exists in environment.r   ZPIPELINE_API_KEY)r	   r
   )r%   r   r   r'   r'   r(   validate_environmentD   s
    
zPipelineAI.validate_environment)r   c                 C   s   i d| j id| jiS )zGet the identifying parameters.r   r   )r   r   selfr'   r'   r(   _identifying_paramsM   s
    zPipelineAI._identifying_paramsc                 C   s   dS )zReturn type of llm.Zpipeline_air'   r+   r'   r'   r(   	_llm_typeU   s    zPipelineAI._llm_type)promptstoprun_managerkwargsr   c           
      K   s   zddl m} W n ty*   tdY n0 || j d}| jpDi }i ||}|| j||g}z|jd d }	W n  t	y   t	d| Y n0 |durt
|	|}	|	S )z Call to Pipeline Cloud endpoint.r   )PipelineCloudz^Could not import pipeline-ai python package. Please install it with `pip install pipeline-ai`.)tokenzAA pipeline run should have a `result_preview` attribute.Run was: N)Zpipeliner3   ImportErrorr   Zget_secret_valuer   Zrun_pipeliner   Zresult_previewAttributeErrorr   )
r,   r/   r0   r1   r2   r3   clientparamsruntextr'   r'   r(   _callZ   s*    



zPipelineAI._call)NN)__name__
__module____qualname____doc__r   str__annotations__r   dictr   r   r   r   r   r   r   Zmodel_configr   classmethodr)   r   r*   propertyr   r-   r.   r   r   r;   r'   r'   r'   r(   r      s2   
  
r   )logging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   Zlangchain_community.llms.utilsr   	getLoggerr<   r"   r   r'   r'   r'   r(   <module>   s   
