
    Ng;                         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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                      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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_keyforbid)extrabefore)modevaluesreturnc                 l   t          t          | j                                                            }|                    di           }t          |          D ]U}||vrO||v rt          d| d          t                              | d| d           |                    |          ||<   V||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        _/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/llms/pipelineai.pybuild_extrazPipelineAI.build_extra1   s     $'tC,<,A,A,C,C'D'D#E#E 

,b11v,, 	; 	;J!999&&$%Jj%J%J%JKKK# N N)3N N N   %+JJz$:$:j!$) !    c                 L    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   s7     1 );=OP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   s,    
t01
 $"67
 	
r/   c                     dS )zReturn type of llm.pipeline_ai r4   s    r-   	_llm_typezPipelineAI._llm_typeU   s	     }r/   promptstoprun_managerkwargsc                 |   	 ddl m} n# t          $ r t          d          w xY w || j                                                  }| j        pi }i ||}|                    | j        ||g          }	 |j        d         d         }	n # t          $ r t          d|           w xY w|t          |	|          }	|	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: )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!   	....... 	 	 	D  	
 T%:%K%K%M%MNNN%+%F%f%!!$"3ff5EFF	%a(+DD 	 	 	 "" "  	
  'tT22Ds   	 #6B
 
B')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      s          L#.&+eD&A&A&AOT#s(^AAA -1hy)000:  L _(###c3h C    [ $#" $ 4    X 
WS#X%6 
 
 
 X
 3    X %):>	  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_      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              ? > > > > >		8	$	$e e e e ei e e e e er/   