
    dh>                         S SK r S SKrS SKJrJrJrJrJrJr  S SK	r	S SK
Jr  S SKJr  S SKJr  S SKJr  \R$                  " \5      r " S S\5      rg)	    N)AnyDictListMappingOptionalSet)CallbackManagerForLLMRun)LLM)Field)enforce_stop_tokensc                     ^  \ rS rSr% SrSr\\S'    \" SSS9r	\
\S'    S	r\\   \S
'    Sr\\   \S'    Sr\\
   \S'    Sr\\S'    Sr\\   \S'    / r\\\      \S'    Sr\\
   \S'    Sr\\   \S'    Sr\\S'    / r\\   \S'    Sr\\S'    S\SS4U 4S jjr\S\4S j5       r\S\\   4S j5       r S\!\\4   4S  jr"\S\#\\4   4S! j5       r$  S&S"\S\\\      S#\\%   S\S\4
S$ jjr&S%r'U =r($ )'Yuan2   u>  Yuan2.0 language models.

Example:
    .. code-block:: python

        yuan_llm = Yuan2(
            infer_api="http://127.0.0.1:8000/yuan",
            max_tokens=1024,
            temp=1.0,
            top_p=0.9,
            top_k=40,
        )
        print(yuan_llm)
        print(yuan_llm.invoke("你是谁？"))
zhttp://127.0.0.1:8000/yuan	infer_apii   	max_token)alias
max_tokensgffffff?tempg?top_pr   top_kF	do_sampleechostop@   repeat_last_ngzG?repeat_penalty	streaminghistoryuse_historykwargsreturnNc                    > [         TU ]  " S0 UD6  U R                  =(       d    SS:  a7  U R                  =(       d    SS:  a  [        R                  S5        SU l        ggg)zInitialize the Yuan2 class.r   zGtop_p and top_k cannot be set simultaneously. set top_k to 0 instead...N )super__init__r   r   loggerwarning)selfr    	__class__s     V/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/llms/yuan2.pyr%   Yuan2.__init__I   sT    "6"JJO!q djjoA%:NN, DJ &;     c                     g)NzYuan2.0r#   r(   s    r*   	_llm_typeYuan2._llm_typeT   s    r,   c                  
    1 Sk$ )N>   r   r   r   r   r   r#   r#   r,   r*   _model_param_namesYuan2._model_param_namesX   s    
 	
r,   c           	          U R                   U R                  U R                  U R                  U R                  U R
                  U R                  U R                  S.$ )Nr   r   r   r   r   r   r   r   r5   r.   s    r*   _default_paramsYuan2._default_paramsb   sH    //"11IIZZZZ++	
 		
r,   c                     SU R                   0U R                  5       EU R                  R                  5        VVs0 sH  u  pXR	                  5       ;   d  M  X_M     snnE$ s  snnf )zGet the identifying parameters.model)r/   r6   __dict__itemsr2   )r(   kvs      r*   _identifying_paramsYuan2._identifying_paramsn   sm     T^^
""$
 "&!4!4!6!6!?V?V?X:X!6
 	
s   A"A"promptrun_managerc           	         U R                   (       a7  U R                  R                  U5        SR                  U R                  5      nOUnSS0n[        R
                  " SUS./U R                  U R                  U R                  U R                  U R                  S.5      n[        R                  SU5         [        R                  " U R                  XgS9n[        R                  SU 35        UR&                  S:w  a  [%        SU 35      e UR	                  5       n
U
S   S:w  a  [%        SU
S    SU
S    S35      eSU
;   a/  [)        U
S   S   5      S:  a  U
S   S   S   S   nO[%        S5      e[%        S5      eUb  [/        X5      nU R                   (       a  U R                  R                  U5        [        R                  SU R                   35        U$ ! [        R                   R"                   a  n	[%        S	U	 35      eS
n	A	ff = f! [        R                   R*                   a   n	[%        SU	 SUR,                   35      eS
n	A	ff = f)u0  Call out to a Yuan2.0 LLM inference endpoint.

Args:
    prompt: The prompt to pass into the model.
    stop: Optional list of stop words to use when generating.

Returns:
    The string generated by the model.

Example:
    .. code-block:: python

        response = yuan_llm.invoke("你能做什么?")
z<n>zContent-Typezapplication/json000)idques)	ques_listtokens_to_generatetemperaturer   r   r   zYuan2.0 prompt:)headersdatazError raised by inference api: NzYuan2.0 response:    zFailed with response: errCode0zFailed with error code [z], error message: [exceptionMsg]resDataoutputr   anszNo output found in response.zNo resData found in response.z:Error raised during decoding response from inference api: z.
Response: z	history: )r   r   appendjoinjsondumpsr   r   r   r   r   r&   debugrequestsputr   
exceptionsRequestException
ValueErrorstatus_codelenJSONDecodeErrortextr   )r(   r@   r   rA   r    inputrI   rJ   responseerespgenerate_texts               r*   _callYuan2._cally   sF   , LL'JJt||,EE!#56zz%*E:;&*oo#yy!^^	
 	&.	D||DNNGOH 	)(453&5hZ@AA	==?DI#% .tI.? @''+N';&<A? 
 D tIx01Q6$(OH$=a$@$GM$%CDD !@AA /DM LL.y/0M ""33 	D>qcBCC	D0 ""22 	LQC P'}}o/ 	s7   9G AH *H H<H

HI0II)r   )NN))__name__
__module____qualname____firstlineno____doc__r   str__annotations__r   r   intr   r   floatr   r   r   boolr   r   r   r   r   r   r   r   r   r%   propertyr/   staticmethodr   r2   r   r6   r   r>   r	   rf   __static_attributes____classcell__)r)   s   @r*   r   r      s     2Is1D4J4D(5/. E8E? .E8C=.It !D(4. % "D(49
"@#%M8C=%&*NHUO*2It/GT#Y%K'	 	 	 3   
C 
 


c3h 

 
WS#X%6 
 
 %):>	TT tCy!T 67	T
 T 
T Tr,   r   )rU   loggingtypingr   r   r   r   r   r   rX   langchain_core.callbacksr	   #langchain_core.language_models.llmsr
   pydanticr   langchain_community.llms.utilsr   	getLoggerrh   r&   r   r#   r,   r*   <module>r}      s>      : :  = 3  >			8	$~C ~r,   