
    ~
i)                         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 d dlmZ d dlmZmZmZ d dlmZ  e j        e          Z ed	d
d           G d de                      ZdS )    N)AnyDictListOptionalUnion)
deprecated)CallbackManagerForLLMRun)LLM)get_from_dict_or_env)	BaseModel
ConfigDictmodel_validator)enforce_stop_tokensz0.3.28z1.0z)langchain_predictionguard.PredictionGuard)sinceremovalalternative_importc                   R   e Zd ZU dZdZeed<   dZee	         ed<   	 dZ
ee         ed<   	 dZee         ed	<   	 d
Zee         ed<   	 dZee         ed<   	 dZeee	                  ed<   dZeee	ee	ef         f                  ed<   	 dZeee	ef                  ed<   	 dZee	         ed<   	  ed          Z ed          dedefd            Zedee	ef         fd            Zede	fd            Zdedee	ef         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_API_KEY`` set with your API key, or pass
    it as a named parameter to the constructor.

    Example:
        .. code-block:: python

            llm = PredictionGuard(
                model="Hermes-3-Llama-3.1-8B",
                predictionguard_api_key="your Prediction Guard API key",
            )
    NclientzHermes-3-Llama-3.1-8Bmodel   
max_tokensg      ?temperatureg?top_ptop_kstoppredictionguard_inputpredictionguard_outputpredictionguard_api_keyforbid)extrabefore)modevaluesreturnc                     t          |dd          }	 ddlm}  ||          |d<   n# t          $ r t          d          w xY w|S )zCValidate that the api_key and python package exists in environment.r   PREDICTIONGUARD_API_KEYr   )r   )api_keyr   zfCould not import predictionguard python package. Please install it with `pip install predictionguard`.)r   predictionguardr   ImportError)clsr$   
pg_api_keyr   s       C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langchain_community/llms/predictionguard.pyvalidate_environmentz$PredictionGuard.validate_environmentB   s     *-/H
 

	777777."     F8  	 	 	H  	 s	   ) Ac                     d| j         iS )zGet the identifying parameters.r   )r   selfs    r-   _identifying_paramsz#PredictionGuard._identifying_paramsX   s     $$    c                     dS )zReturn type of llm.r)    r0   s    r-   	_llm_typezPredictionGuard._llm_type]   s
     ! r3   kwargsc           
      X   |                     d| j                  }|                     d| j                  }i | j        | j        | j        | j        t          |t                    r|	                                n|t          |t                    r|	                                n|d|}|S )Nr   r   )r   r   r   r   inputoutput)
popr   r   r   r   r   r   
isinstancer   
model_dump)r1   r7   r9   r:   paramss        r-   _get_parameterszPredictionGuard._get_parametersb   s    

2D4NOO4d6QRR
"o#/*4UI*F*FQE$$&&&E ,6fi+H+HTF%%'''f 
 
  r3   promptrun_managerc                     | j         di |}d}| j        |t          d          | j        | j        }n|} | j        j        j        d| j        |d|}|d         D ]X}|                    dd                              d          r-|d         	                    d          }	t          d|	           Y|d         d	         d
         }
|rt          |
|          }
|
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 = llm.invoke("Tell me a joke.")
        Nz2`stop` found in both the input and default params.)r   r@   choicesstatus zerror: z Error from PredictionGuard API: r   textr5   )r?   r   
ValueErrorr   completionscreater   get
startswithremoveprefixr   )r1   r@   r   rA   r7   r>   stopsresponsereserr_msgrF   s              r-   _callzPredictionGuard._cally   s-   " &%////9 T%5QRRRY"IEEE14;*1 
*
 
 
 
 I& 	O 	OCwwx$$//	:: Oh-44Y?? !MG!M!MNNNO 	"1%f-  	4&tU33Dr3   )NN)"__name__
__module____qualname____doc__r   r   __annotations__r   r   strr   intr   floatr   r   r   r   r   r   r   boolr   r   r   model_configr   r.   propertyr2   r6   r?   r	   rQ   r5   r3   r-   r   r      sO          FC2E8C=222 #J###A#'K%'''Q E8E?   SE8C=F $D(49
$$$CG8DeCI.>)>$?@GGGK8<HT#t)_5<<<9-1Xc]111#:H---L_(###$ 4    $#* %T#s(^ % % % X% !3 ! ! ! X! S#X    4 %):>	- -- tCy!- 67	-
 - 
- - - - - -r3   r   )loggingtypingr   r   r   r   r   langchain_core._api.deprecationr   langchain_core.callbacksr	   #langchain_core.language_models.llmsr
   langchain_core.utilsr   pydanticr   r   r   langchain_community.llms.utilsr   	getLoggerrR   loggerr   r5   r3   r-   <module>rg      s)    3 3 3 3 3 3 3 3 3 3 3 3 3 3 6 6 6 6 6 6 = = = = = = 3 3 3 3 3 3 5 5 5 5 5 5 ; ; ; ; ; ; ; ; ; ; > > > > > >		8	$	$ 
B  
R R R R Rc R R 
R R Rr3   