
    7|h;                         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 j.                  e      Z G d d	e
e      Zy)
    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                   0   e Zd ZU dZdZeed<   	  ee      Z	e
eef   ed<   	 dZee   ed<    ed	      Z ed
      ede
eef   defd              Zede
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y)
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_keyforbid)extrabefore)modevaluesreturnc                 :   t        t        | j                  j                                     }|j	                  di       }t        |      D ]I  }||vs||v rt        d| d      t        j                  | d| d       |j                  |      ||<   K ||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listmodel_fieldskeysget
ValueErrorloggerwarningpop)clsr   all_required_field_namesr   
field_names        b/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/llms/pipelineai.pybuild_extrazPipelineAI.build_extra1   s     $'tC,<,<,A,A,C'D#E 

,b1v, 	;J!99&$vj\9I%JKK# %))34JN %+JJz$:j!	; %* !    c                 <    t        t        |dd            }||d<   |S )z?Validate that api key and python package exists in environment.r   PIPELINE_API_KEY)r
   r   )r*   r   r   s      r-   validate_environmentzPipelineAI.validate_environmentD   s/     1 );=OP
 &6!"r/   c                 >    i d| j                   id| j                  iS )zGet the identifying parameters.r   r   )r   r   selfs    r-   _identifying_paramszPipelineAI._identifying_paramsM   s2    
t001
 $"6"67
 	
r/   c                      y)zReturn type of llm.pipeline_ai r4   s    r-   	_llm_typezPipelineAI._llm_typeU   s     r/   promptstoprun_managerkwargsc                 f   	 ddl m}  || j                  j	                               }| j
                  xs i }i ||}|j                  | j                  ||g      }	 |j                  d   d   }	|t        |	|      }	|	S # t        $ r t        d      w xY w# t        $ r t        d|       w xY w)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: )pipeliner@   ImportErrorr   get_secret_valuer   run_pipeliner   result_previewAttributeErrorr   )
r5   r;   r<   r=   r>   r@   clientparamsruntexts
             r-   _callzPipelineAI._callZ   s    	. T%:%:%K%K%MN%%+%F%f%!!$"3"3ff5EF	%%a(+D  'tT2D+  	D 	  	 5" 	s   B  B  BB0)NN)__name__
__module____qualname____doc__r   str__annotations__r   dictr   r   r   r   r   r   r   model_configr   classmethodr.   r   r2   propertyr   r6   r:   r   r   rL   r9   r/   r-   r   r      s5    L#.&+D&AOT#s(^A -1hy)0L (#c3h C   $" $ 4   
WS#X%6 
 
 3   %):>	 tCy! 67	
  
r/   r   )loggingtypingr   r   r   r   r   langchain_core.callbacksr   #langchain_core.language_models.llmsr	   langchain_core.utilsr
   r   r   pydanticr   r   r   r   r   langchain_community.llms.utilsr   	getLoggerrM   r'   r   r9   r/   r-   <module>r_      sK     5 5 = 3 V V  ?			8	$ei er/   