
    dhr!                     j    S SK r S SKJr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Jr   " S S\5      rg)    N)AnyDictListMappingOptionalUnion)CallbackManagerForLLMRun)LLM)Field	SecretStrc                   *   \ rS rSr% Sr\\S'   \\S'   Sr\	\   \S'   Sr
\	\   \S'   Sr\	\   \S'   \" \S	9r\\\4   \S
'   \" SSS.5      r\\S'   \S\4S j5       r  SS\S\	\\      S\	\   S\S\4
S jjr\S\\\4   4S j5       rS\4S jrSrg)	Predibase	   a  Use your Predibase models with Langchain.

To use, you should have the ``predibase`` python package installed,
and have your Predibase API key.

The `model` parameter is the Predibase "serverless" base_model ID
(see https://docs.predibase.com/user-guide/inference/models for the catalog).

An optional `adapter_id` parameter is the Predibase ID or HuggingFace ID of a
fine-tuned LLM adapter, whose base model is the `model` parameter; the
fine-tuned adapter must be compatible with its base model;
otherwise, an error is raised.  If the fine-tuned adapter is hosted at Predibase,
then `adapter_version` in the adapter repository must be specified.

An optional `predibase_sdk_version` parameter defaults to latest SDK version.
modelpredibase_api_keyNpredibase_sdk_version
adapter_idadapter_version)default_factorymodel_kwargs   g?)max_new_tokenstemperaturedefault_options_for_generationreturnc                     g)N	predibase selfs    Z/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/llms/predibase.py	_llm_typePredibase._llm_type(   s        promptstoprun_managerkwargsc                 @   0 U R                   EU R                  =(       d    0 EU=(       d    0 EnU R                  5       (       a   SSKJn  SSKJn  SSKJnJ	n	  SSK
Jn
Jn  SSKJn  SSKJn  U" U R"                  R%                  5       SS	S
9nU" US9nUR+                  SU R,                   3S9nU R.                  (       aP    UR1                  U R.                  U R2                  S S9nUR5                  US9R7                  UUS9nUR8                  $ UR7                  UUS9nUR8                  $ SSKJn  S[<        R>                  S'   U" U R"                  R%                  5       S9nSS K nSSK!J"n  SSK#J$n  SSK%J&n  URN                  RQ                  U R,                  S9nU R.                  (       ax   U R2                  (       aD  U R.                   SU R2                   3nURS                  SS 5         UR6                  " S(UUS.UD6nO7 UR6                  " S(UU R.                  S!S".UD6nO UR6                  " S(S%U0UD6nURV                  nU$ ! [&         a  n['        S5      UeS nAf[(         a  n[)        S5      UeS nAff = f! U a     UR+                  SU R.                   3S9n GNf = f! U a  n[)        SU S 35      UeS nAff = f! U a  n[)        S#U R.                   S$35      UeS nAff = f! URT                   a  n[)        S&U R,                   S'35      UeS nAff = f))Nr   )PredibaseClient)get_session)ServerResponseErrorSession)HuggingFaceLLMLLMDeployment)GeneratedResponse)Modelz https://api.app.predibase.com/v1zserving.app.predibase.com)tokengatewayserving_endpoint)sessionzZCould not import Predibase Python package. Please install it with `pip install predibase`.z-Your API key is not correct. Please try againzpb://deployments/)uri)nameversionmodel_idzhf://)r   )r%   options)r   zhttps://api.app.predibase.comPREDIBASE_GATEWAY)	api_token)Client)GenerationError)Response)deployment_ref/r<   )r%   r   zAn adapter with the ID "zE" cannot be found in the Predibase repository of fine-tuned adapters.hub)r%   r   adapter_sourcezEither an adapter with the ID "z" cannot be found in a HuggingFace repository, or it is incompatible with the base model (please make sure that the adapter configuration is consistent).
r%   zAn LLM with the deployment ID "z" cannot be found at Predibase (please refer to "https://docs.predibase.com/user-guide/inference/models" for the list of supported models).
r   ),r   r   _is_deprecated_sdk_versionr   r*   predibase.pqlr+   predibase.pql.apir,   r-    predibase.resource.llm.interfacer.   r/   predibase.resource.llm.responser0   predibase.resource.modelr1   r   get_secret_valueImportError
ValueErrorr
   r   r   	get_modelr   with_adaptergenerateresponser   osenvironrequestslorax.clientr=   lorax.errorsr>   lorax.typesr?   deploymentsclientpopJSONDecodeErrorgenerated_text) r    r%   r&   r'   r(   r:   r*   r+   r,   r-   r.   r/   r0   r1   r5   pcebase_llm_deploymentadapter_modelresultr   r   rS   LoraxClientr>   r?   lorax_clientpb_adapter_idrP   gejderesponse_texts                                    r!   _callPredibase._call,   s   1
111
  &B1
 |1

 **,,Y55 N:#.00AAC>%@$
 '6g&F 24'

|4 28 2 J$&LL!__ $ 4 4!% %1 %M -999NWW!# X  ??"	 -55!# 6  ??"'*I

&'(,,==? 
	 	60($-$9$9$@$@:: %A %

 ?? ##(,'8$:N:N9O%P
+44  %#0  " H+44  %#'??',  "	 H'00 ! !//_  !F   Y !PQWXXY( + J$&FFt6G/HF$IMJ` ' $4]O D: =  ' $;DOO;L M 
  ++  7

| D  s   AI %I? -J(  K &K. 
I<II<+I77I<?"J%$J%(K.J>>KK+K&&K+.L>LLc                 "    0 SU R                   0E$ )zGet the identifying parameters.r   )r   r   s    r!   _identifying_paramsPredibase._identifying_params   s    
t001
 	
r$   c                      SS K nSSKJn  SSKJn  UR	                  SS9nU R
                  =(       d    UnUR	                  US9nXd:  =(       d    SU;   (       + $ ! [         a  n[        S5      UeS nAff = f)Nr   )__version__)Versionz2024.4.8)version_stringz+devzkCould not import Predibase Python package. Please install it with `pip install semantic_version predibase`.)semantic_versionpredibase.versionrm   semantic_version.basern   r   rK   )r    rp   current_versionrn   sdk_semver_deprecatedactual_current_versionsdk_semver_currentr]   s           r!   rD   $Predibase._is_deprecated_sdk_version   s    	#H5-=-E-E) .F .! +/*D*D*W"*:*B*B5 +C + $; 644   	S 	s   AA 
A5$A00A5r   )NN)__name__
__module____qualname____firstlineno____doc__str__annotations__r   r   r   r   r   intr   dictr   r   r   r   propertyr"   r   r	   rg   r   rj   boolrD   __static_attributes__r   r$   r!   r   r   	   s   " J  +/8C=/ $J$%)OXc])#(#>L$sCx.>+0!	
,"D  3   %):>	PP tCy!P 67	P
 P 
Pd 
WS#X%6 
 
D r$   r   )rQ   typingr   r   r   r   r   r   langchain_core.callbacksr	   #langchain_core.language_models.llmsr
   pydanticr   r   r   r   r$   r!   <module>r      s%    	 < < = 3 %Q Qr$   