
    Ng                         d dl Z d dl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 d dlmZ d dlmZ  e j        e          Z G d d	e	          ZdS )
    N)AnyDictListOptional)CallbackManagerForLLMRun)LLM)get_from_dict_or_envpre_init)
ConfigDict)enforce_stop_tokensc                      e Zd ZU dZdZeed<   dZee	         ed<   	 dZ
eee	ef                  ed<   	 dZeed<   	 d	Zeed
<   	 dZee	         ed<   	 dZeee	                  ed<    ed          Zededefd            Zedee	ef         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 )PredictionGuarda  Prediction Guard large language models.

    To use, you should have the ``predictionguard`` python package installed, and the
    environment variable ``PREDICTIONGUARD_TOKEN`` set with your access token, or pass
    it as a named parameter to the constructor. To use Prediction Guard's API along
    with OpenAI models, set the environment variable ``OPENAI_API_KEY`` with your
    OpenAI API key as well.

    Example:
        .. code-block:: python

            pgllm = PredictionGuard(model="MPT-7B-Instruct",
                                    token="my-access-token",
                                    output={
                                        "type": "boolean"
                                    })
    NclientzMPT-7B-Instructmodeloutput   
max_tokensg      ?temperaturetokenstopforbid)extravaluesreturnc                     t          |dd          }	 ddl}|                    |          |d<   n# t          $ r t          d          w xY w|S )zHValidate that the access token and python package exists in environment.r   PREDICTIONGUARD_TOKENr   N)r   r   zfCould not import predictionguard python package. Please install it with `pip install predictionguard`.)r	   predictionguardClientImportError)clsr   r   pgs       d/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/llms/predictionguard.pyvalidate_environmentz$PredictionGuard.validate_environment7   s|     %VW6MNN	((((!yyuy55F8 	 	 	H  	
 s	   1 Ac                      | j         | j        dS )z@Get the default parameters for calling the Prediction Guard API.r   r   r%   selfs    r"   _default_paramszPredictionGuard._default_paramsF   s     /+
 
 	
    c                 &    i d| j         i| j        S )zGet the identifying parameters.r   )r   r(   r&   s    r"   _identifying_paramsz#PredictionGuard._identifying_paramsN   s     A7DJ'@4+?@@r)   c                     dS )zReturn type of llm.r    r&   s    r"   	_llm_typezPredictionGuard._llm_typeS   s
     ! r)   promptrun_managerkwargsc           	      <   ddl }| j        }| j        |t          d          | j        | j        |d<   n||d<    |j        j        d
| j        || j        |d         |d         d|}|d         d         d	         }|| j        t          ||d                   }|S )a&  Call out to Prediction Guard's model API.
        Args:
            prompt: The prompt to pass into the model.
        Returns:
            The string generated by the model.
        Example:
            .. code-block:: python
                response = pgllm.invoke("Tell me a joke.")
        r   Nz2`stop` found in both the input and default params.stop_sequencesr   r   )r   r/   r   r   r   choicestextr-   )	r   r(   r   
ValueError
Completioncreater   r   r   )	r'   r/   r   r0   r1   r!   paramsresponser5   s	            r"   _callzPredictionGuard._callX   s      	%$$$%9 T%5QRRRY"'+yF#$$'+F#$'2=' 
*;}-l+
 
 
 
 	"1%f- ty4&tV4D-EFFDr)   )NN)__name__
__module____qualname____doc__r   r   __annotations__r   r   strr   r   r   intr   floatr   r   r   r   model_configr
   r#   propertyr(   r+   r.   r   r;   r-   r)   r"   r   r      s         $ FC,E8C=,,,'+FHT#s(^$+++FJAKQE8C=- $D(49
$$$:  L $ 4    X 
c3h 
 
 
 X
 AT#s(^ A A A XA !3 ! ! ! X! %):>	) )) tCy!) 67	)
 ) 
) ) ) ) ) )r)   r   )loggingtypingr   r   r   r   langchain_core.callbacksr   #langchain_core.language_models.llmsr   langchain_core.utilsr	   r
   pydanticr   langchain_community.llms.utilsr   	getLoggerr<   loggerr   r-   r)   r"   <module>rO      s     , , , , , , , , , , , , = = = = = = 3 3 3 3 3 3 ? ? ? ? ? ? ? ?       > > > > > >		8	$	$s s s s sc s s s s sr)   