Ë
    µŒj>  ã                   ó¦   — d dl Z d dlZd dlmZmZmZmZmZmZ d dl	Z	d dl
mZ d dlmZ d dlmZ d dlmZ  ej$                  e«      Z G d„ de«      Zy)	é    N)ÚAnyÚDictÚListÚMappingÚOptionalÚSet)ÚCallbackManagerForLLMRun)ÚLLM)ÚField)Úenforce_stop_tokensc                   óà  ‡ — e Zd ZU dZdZeed<   	  ed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d<   	 dZee   ed<   	 g Zeee      ed<   	 dZee	   ed<   	 dZee   ed<   	 dZeed<   	 g Zee   ed<   	 dZeed<   	 deddfˆ fd„Zedefd„«       Zedee   fd„«       Zde eef   fd„Z!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%ˆ xZ&S )%ÚYuan2un  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_ngáz®Gáò?Úrepeat_penaltyÚ	streamingÚhistoryÚuse_historyÚkwargsÚreturnNc                 ó¬   •— t        ‰| �  di |¤Ž | j                  xs ddkD  r1| j                  xs ddkD  rt        j                  d«       d| _        yyy)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     €úh/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/llms/yuan2.pyr$   zYuan2.__init__I   sT   ø€ ä‰ÑÑ"˜6Ò"à�J‰JŠO˜!˜qÒ  d§j¡j¢o°A¸Ò%:Ü�N‰Nð,ôð ˆD�Jð &;Ð ó    c                  ó   — y)NzYuan2.0r"   ©r'   s    r)   Ú	_llm_typezYuan2._llm_typeT   s   € àr*   c                  ó
   — h d£S )N>   r   r   r   r   r   r"   r"   r*   r)   Ú_model_param_nameszYuan2._model_param_namesX   s   € ò
ð 	
r*   c           	      ó¸   — | j                   | j                  | j                  | j                  | j                  | j
                  | j                  | j                  dœS )N©r   r   r   r   r   r   r   r   r1   r,   s    r)   Ú_default_paramszYuan2._default_paramsb   sH   € àŸ™ØŸ™ØŸ/™/Ø"×1Ñ1Ø—I‘IØ—Z‘ZØ—Z‘ZØ×+Ñ+ñ	
ð 		
r*   c                 óÌ   — d| j                   i| j                  «       ¥| j                  j                  «       D ��ci c]  \  }}|| j	                  «       v sŒ||“Œ c}}¥S c c}}w )zGet the identifying parameters.Úmodel)r-   r2   Ú__dict__Úitemsr/   )r'   ÚkÚvs      r)   Ú_identifying_paramszYuan2._identifying_paramsn   sq   € ð �T—^‘^ð
à×"Ñ"Ó$ð
ð "&§¡×!4Ñ!4Ô!6ôÙ!6™˜˜A¸!¸t×?VÑ?VÓ?XÒ:X��1‘Ð!6òð
ð 	
ùós   »A ÁA ÚpromptÚrun_managerc           	      óŠ  — | j                   r7| j                  j                  |«       dj                  | j                  «      }n|}ddi}t	        j
                  d|dœg| j                  | j                  | j                  | j                  | j                  dœ«      }t        j                  d|«       	 t        j                  | j                  ||¬«      }t        j                  d|› �«       |j&                  dk7  rt%        d|› �«      ‚	 |j	                  «       }
|
d   dk7  rt%        d|
d   › d|
d   › d�«      ‚d|
v r.t)        |
d   d   «      dk\  r|
d   d   d   d   }nt%        d«      ‚t%        d«      ‚	 |�t/        ||«      }| j                   r| j                  j                  |«       t        j                  d| j                  › �«       |S # t        j                   j"                  $ r}	t%        d	|	› �«      ‚d
}	~	ww xY w# t        j                   j*                  $ r }	t%        d|	› d|j,                  › �«      ‚d
}	~	ww xY w)ux  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   r;   r   ÚinputrC   rD   ÚresponseÚeÚrespÚgenerate_texts               r)   Ú_callzYuan2._cally   sO  € ð, ×ÒØ�L‰L×Ñ Ô'Ø—J‘J˜tŸ|™|Ó,‰EàˆEà!Ð#5Ð6ˆä�z‰zà%*°EÑ:Ð;Ø&*§o¡oØ#Ÿy™yØŸ™ØŸ™Ø!Ÿ^™^ñó	
ˆô 	�‰Ð&¨Ô.ð	DÜ—|‘| D§N¡N¸GÈ$ÔOˆHô 	�‰Ð)¨(¨Ð4Ô5à×Ñ 3Ò&ÜÐ5°h°ZÐ@ÓAÐAð	Ø—=‘=“?ˆDà�I‰ #Ò%Ü Ø.¨t°I©Ð.?ð @'Ø'+¨NÑ';Ð&<¸Að?óð ð
 ˜DÑ Ü�t˜I‘ xÑ0Ó1°QÒ6Ø$(¨¡O°HÑ$=¸aÑ$@ÀÑ$G‘Mä$Ð%CÓDÐDä Ð!@ÓAÐAð	 "ð ÐÜ/°¸tÓDˆMð ×ÒØ�L‰L×Ñ Ô.ä�‰�y §¡ Ð/Ô0ØÐøôM ×"Ñ"×3Ñ3ò 	DÜÐ>¸q¸cÐBÓCÐCûð	Dûô0 ×"Ñ"×2Ñ2ò 	ÜØLÈQÈCð PØ'Ÿ}™}˜oð/óð ûð	ús1   Â3"G ÄA-H ÇHÇ/G=Ç=HÈIÈ"H=È=I)NN)'Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚstrÚ__annotations__r   r   Úintr   r   Úfloatr   r   r   Úboolr   r   r   r   r   r   r   r   r   r$   Úpropertyr-   Ústaticmethodr   r/   r   r2   r   r9   r	   r`   Ú__classcell__)r(   s   @r)   r   r      sº  ø… ñð  2€IˆsÓ1Øá˜D¨Ô4€J�Ó4Øà€Dˆ(�5‰/ÓØ.à €Eˆ8�E‰?Ó Ø.à€Eˆ8�C‰=ÓØ.à€IˆtÓðð !€Dˆ(�4‰.Ó Ø%à "€Dˆ(�4˜‘9Ñ
Ó"Ø@à#%€M�8˜C‘=Ó%Øà&*€N�H˜U‘OÓ*Ø2à€IˆtÓØ/à€GˆT�#‰YÓØ%à€K�ÓØ'ð	 ð 	¨õ 	ð ð˜3ò ó ðð ð
  C¡ò 
ó ð
ð

  c¨3 h¡ó 

ð ð
 W¨S°#¨XÑ%6ò 
ó ð
ð %)Ø:>ñ	TàðTð �t˜C‘yÑ!ðTð Ð6Ñ7ð	Tð
 ðTð 
÷Tr*   r   )rO   ÚloggingÚtypingr   r   r   r   r   r   rR   Úlangchain_core.callbacksr	   Ú#langchain_core.language_models.llmsr
   Úpydanticr   Úlangchain_community.llms.utilsr   Ú	getLoggerra   r%   r   r"   r*   r)   Ú<module>rt      s@   ðÛ Û ß :× :ã Ý =Ý 3Ý å >à	ˆ×	Ñ	˜8Ó	$€ô~ˆCõ ~r*   