
    dh)                         S SK r S SKJrJrJrJrJr  S SKJr  S SK	J
r
  S SKJr  S SKJr  S SKJrJrJr  S SKJr  \ R*                  " \5      r\" S	S
SS9 " S S\5      5       rg)    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S rSr% SrSr\\S'   Sr\	\
   \S'    Sr\	\   \S'    S	r\	\   \S
'    Sr\	\   \S'    Sr\	\   \S'    Sr\	\\
      \S'   Sr\	\\
\\
\4   4      \S'    Sr\	\\
\4      \S'    Sr\	\
   \S'    \" SS9r\" SS9S\S\4S j5       r\S\\
\4   4S j5       r\S\
4S j5       rS\S\\
\4   4S jr   S!S\
S\	\\
      S\	\!   S\S\
4
S jjr"S r#g)"PredictionGuard   a  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                 r    [        USS5      n SSKJn  U" US9US'   U$ ! [         a    [        S5      ef = f)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       `/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/llms/predictionguard.pyvalidate_environment$PredictionGuard.validate_environmentB   s\     *-/H

	7." F8   	H 	s     6c                     SU R                   0$ )zGet the identifying parameters.r   )r   selfs    r.   _identifying_params#PredictionGuard._identifying_paramsX   s     $$    c                     g)zReturn type of llm.r*    r2   s    r.   	_llm_typePredictionGuard._llm_type]   s     !r6   kwargsc           
      t   UR                  SU R                  5      nUR                  SU R                  5      n0 U R                  U R                  U R
                  U R                  [        U[        5      (       a  UR                  5       OU[        U[        5      (       a  UR                  5       OUS.EUEnU$ )Nr   r   )r   r   r   r   inputoutput)
popr   r   r   r   r   r   
isinstancer   
model_dump)r3   r;   r=   r>   paramss        r.   _get_parametersPredictionGuard._get_parametersb   s    

2D4N4NO4d6Q6QR
"oo#//*4UI*F*FE$$&E ,6fi+H+HF%%'f
 
  r6   promptrun_managerc                    U R                   " S0 UD6nSnU R                  b  Ub  [        S5      eU R                  b  U R                  nOUnU R                  R                  R
                  " SU R                  US.UD6nUS    HK  nUR                  SS5      R                  S5      (       d  M+  US   R                  S5      n	[        SU	 35      e   US   S	   S
   n
U(       a  [        X5      n
U
$ )zCall 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   rE   choicesstatus zerror: z Error from PredictionGuard API: r   textr8   )rC   r   
ValueErrorr   completionscreater   get
startswithremoveprefixr   )r3   rE   r   rF   r;   rB   stopsresponsereserr_msgrK   s              r.   _callPredictionGuard._cally   s    " %%//99 T%5QRRYY"IIEE;;**11 
**
 
 I&Cwwx$//	::h-44Y? #CG9!MNN '
 	"1%f- &t3Dr6   r8   )NN)$__name__
__module____qualname____firstlineno____doc__r   r   __annotations__r   r   strr   intr   floatr   r   r   r   r   r   r   boolr   r    r   model_configr   r/   propertyr4   r9   rC   r	   rV   __static_attributes__r8   r6   r.   r   r      s    FC2E8C=2 #J#A#'K%'Q E8E? SE8C=F $D(49
$CG8DeCI.>)>$?@GK8<HT#t)_5<9-1Xc]1#H-L(#$ 4  $* %T#s(^ % % !3 ! ! S#X 4 %):>	-- tCy!- 67	-
 - 
- -r6   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   	getLoggerrX   loggerr   r8   r6   r.   <module>ro      s_     3 3 6 = 3 5 ; ; >			8	$ 
B
Rc R
Rr6   