Ë
    uPêjœ  ã                   ó¬   — d dl Z d dlZd dlmZmZmZ d dlZd dlmZ d dl	m
Z
mZ d dlmZ d dlmZmZ ddlmZ erd dlZd d	lmZ eZneZ G d
„ de
«      Zy)é    N)ÚTYPE_CHECKINGÚAnyÚFinal©Úconvert_content_list_to_str)Ú
BaseConfigÚBaseLLMException)ÚAllMessageValues)ÚModelResponseÚUsageé   ©ÚNLPCloudError)ÚLoggingc                   óä  ‡ — e Zd ZU dZdZedz  ed<   dZedz  ed<   dZ	e
dz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed	<   dZedz  ed
<   dZedz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed<   	 	 	 	 	 	 	 	 	 	 	 	 d*dedz  dedz  de
dz  dedz  dedz  dedz  d	edz  d
edz  dedz  dedz  dedz  dedz  ddfd„Zeˆ fd„«       Z	 	 d+dede
dee   dedede
dz  de
dz  defd„Zde
defd„Zdedede
dedef
d„Zde
dedeej>                  z  de fd „Z!de
dee   dedededefd!„Z"	 	 d+de
d"ejF                  d#e$d$e%d%edee   deded&d'de
dz  d(edz  de$fd)„Z&ˆ xZ'S ),ÚNLPCloudConfigal  
    Reference: https://docs.nlpcloud.com/#generation

    - `max_length` (int): Optional. The maximum number of tokens that the generated text should contain.

    - `length_no_input` (boolean): Optional. Whether `min_length` and `max_length` should not include the length of the input text.

    - `end_sequence` (string): Optional. A specific token that should be the end of the generated sequence.

    - `remove_end_sequence` (boolean): Optional. Whether to remove the `end_sequence` string from the result.

    - `remove_input` (boolean): Optional. Whether to remove the input text from the result.

    - `bad_words` (list of strings): Optional. List of tokens that are not allowed to be generated.

    - `temperature` (float): Optional. Temperature sampling. It modulates the next token probabilities.

    - `top_p` (float): Optional. Top P sampling. Below 1, only the most probable tokens with probabilities that add up to top_p or higher are kept for generation.

    - `top_k` (int): Optional. Top K sampling. The number of highest probability vocabulary tokens to keep for top k filtering.

    - `repetition_penalty` (float): Optional. Prevents the same word from being repeated too many times.

    - `num_beams` (int): Optional. Number of beams for beam search.

    - `num_return_sequences` (int): Optional. The number of independently computed returned sequences.
    NÚ
max_lengthÚlength_no_inputÚend_sequenceÚremove_end_sequenceÚremove_inputÚ	bad_wordsÚtemperatureÚtop_pÚtop_kÚrepetition_penaltyÚ	num_beamsÚnum_return_sequencesÚreturnc                 ó¤   — t        «       j                  «       }|j                  «       D ]%  \  }}|dk7  sŒ|€Œt        | j                  ||«       Œ' y )NÚself)ÚlocalsÚcopyÚitemsÚsetattrÚ	__class__)r!   r   r   r   r   r   r   r   r   r   r   r   r   Úlocals_ÚkeyÚvalues                   úo/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/nlp_cloud/chat/transformation.pyÚ__init__zNLPCloudConfig.__init__D   sF   € ô  ›Ÿ™›ˆØ!Ÿ-™-›/ò 	4‰JˆC�Ø�f‹} Ñ!2Ü˜Ÿ™¨¨UÕ3ñ	4ó    c                 ó    •— t         ‰| �  «       S ©N)ÚsuperÚ
get_config)Úclsr&   s    €r*   r0   zNLPCloudConfig.get_configX   s   ø€ ä‰wÑ!Ó#Ð#r,   ÚheadersÚmodelÚmessagesÚoptional_paramsÚlitellm_paramsÚapi_keyÚapi_basec                 ó$   — dddœ}|rd|› �|d<   |S )Nzapplication/json)Úacceptzcontent-typezToken ÚAuthorization© )r!   r2   r3   r4   r5   r6   r7   r8   s           r*   Úvalidate_environmentz#NLPCloudConfig.validate_environment\   s,   € ð )Ø.ñ
ˆñ Ø)/°¨yÐ'9ˆG�OÑ$Øˆr,   c                 ó
   — g d¢S )N)Ú
max_tokensÚstreamr   r   Úpresence_penaltyÚfrequency_penaltyÚnÚstopr<   )r!   r3   s     r*   Úget_supported_openai_paramsz*NLPCloudConfig.get_supported_openai_paramsn   s   € ò	
ð 		
r,   Únon_default_paramsÚdrop_paramsc                 óØ   — |j                  «       D ]V  \  }}|dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  r||d	<   |d
k(  sŒR||d<   ŒX |S )Nr?   r   r@   r   r   rA   rB   rC   r   rD   Ústop_sequences)r$   )r!   rF   r5   r3   rG   Úparamr)   s          r*   Úmap_openai_paramsz NLPCloudConfig.map_openai_paramsz   s¼   € ð /×4Ñ4Ó6ò 	:‰LˆE�5Ø˜Ò$Ø05� Ñ-Ø˜Ò Ø,1� Ñ)Ø˜Ò%Ø16� Ñ.Ø˜ÒØ+0� Ñ(ØÐ*Ò*Ø6;�Ð 2Ñ3ØÐ+Ò+Ø7<�Ð 3Ñ4Ø˜Š|Ø:?�Ð 6Ñ7Ø˜‹Ø49�Ð 0Ò1ð!	:ð" Ðr,   Úerror_messageÚstatus_codec                 ó   — t        |||¬«      S )N)rM   Úmessager2   r   )r!   rL   rM   r2   s       r*   Úget_error_classzNLPCloudConfig.get_error_class”   s   € Ü¨¸mÐU\Ô]Ð]r,   c                 óB   — dj                  d„ |D «       «      }d|i|¥}|S )Nú c              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr.   r   )Ú.0rO   s     r*   ú	<genexpr>z3NLPCloudConfig.transform_request.<locals>.<genexpr>Ÿ   s   è ø€ Ò\ÈÔ:¸7×CÑ\ùs   ‚Útext)Újoin)r!   r3   r4   r5   r6   r2   rV   Údatas           r*   Útransform_requestz NLPCloudConfig.transform_request—   s6   € ð —h‘hÑ\ÐS[Ô\Ó\ˆð �Dð
àð
ˆð
 ˆr,   Úraw_responseÚmodel_responseÚlogging_objÚrequest_dataÚencodingztiktoken.Encoding | NoneÚ	json_modec                 óx  — |j                  d |
|j                  d|i¬«       	 |j                  «       }d|v rt	        |d   |j
                  ¬«      ‚	 t        |d   «      dkD  r!|d   |j                  d   j                  _	        |d   }|d   }t        t        j                  «       «      |_        ||_        t        ||||z   ¬	«      }t!        |d
|«       |S # t        $ r" t	        |j                  |j
                  ¬«      ‚w xY w# t        $ r+ t	        t        j                  |«      |j
                  ¬«      ‚w xY w)NÚcomplete_input_dict)Úinputr7   Úoriginal_responseÚadditional_args)rO   rM   ÚerrorÚgenerated_textr   Únb_input_tokensÚnb_generated_tokens)Úprompt_tokensÚcompletion_tokensÚtotal_tokensÚusage)Ú	post_callrV   ÚjsonÚ	Exceptionr   rM   ÚlenÚchoicesrO   ÚcontentÚdumpsÚintÚtimeÚcreatedr3   r   r%   )r!   r3   rZ   r[   r\   r]   r4   r5   r6   r^   r7   r_   Úcompletion_responseri   rj   rl   s                   r*   Útransform_responsez!NLPCloudConfig.transform_response¨   sd  € ð 	×ÑØØØ*×/Ñ/Ø2°LÐAð	 	ô 	
ð	aØ)5×):Ñ):Ó)<Ðð Ð)Ñ)ÜØ+¨GÑ4Ø(×4Ñ4ôð ð
ÜÐ*Ð+;Ñ<Ó=ÀÒAØ@SÐTdÑ@e�N×*Ñ*¨1Ñ-×5Ñ5Ô=ð  3Ð3DÑEˆØ#6Ð7LÑ#MÐä!$¤T§Y¡Y£[Ó!1ˆÔØ$ˆÔÜØ'Ø/Ø&Ð):Ñ:ô
ˆô
 	� ¨Ô/ØÐøô; ò 	aÜ¨×(9Ñ(9À|×G_ÑG_Ô`Ð`ð	aûô ò Ü#Ü ŸJ™JÐ':Ó;Ø ,× 8Ñ 8ôð ðús   £C Á2D Ã+DÄ4D9)NNNNNNNNNNNN)NN)(Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rt   Ú__annotations__r   Úboolr   Ústrr   r   r   Úlistr   Úfloatr   r   r   r   r   r+   Úclassmethodr0   Údictr
   r=   rE   rK   ÚhttpxÚHeadersr	   rP   rY   ÚResponser   ÚLoggingClassrx   Ú__classcell__)r&   s   @r*   r   r      sb  ø… ñð8 "€J��d‘
Ó!Ø#'€O�T˜D‘[Ó'Ø#€L�#˜‘*Ó#Ø'+Ð˜ ™Ó+Ø $€L�$˜‘+Ó$Ø!€Iˆt�d‰{Ó!Ø $€K�˜‘Ó$Ø€Eˆ5�4‰<ÓØ€Eˆ3�‰:ÓØ'+Ð˜ ™Ó+Ø €Iˆs�T‰zÓ Ø'+Ð˜# ™*Ó+ð "&Ø'+Ø#'Ø+/Ø$(Ø!%Ø$(Ø"Ø Ø+/Ø $Ø+/ñ4à˜$‘Jð4ð  ™ð4ð ˜D‘jð	4ð
 " D™[ð4ð ˜T‘kð4ð ˜$‘;ð4ð ˜T‘\ð4ð �t‰|ð4ð �T‰zð4ð " D™Lð4ð ˜‘:ð4ð " D™jð4ð 
ó4ð( ó$ó ð$ð #Ø#ñàðð ðð Ð'Ñ(ð	ð
 ðð ðð �t‘ðð ˜‘*ðð 
óð$

°ð 

¸ó 

ðà ðð ðð ð	ð
 ðð 
óð4^¨Sð ^¸sð ^ÈTÐTY×TaÑTaÑMað ^Ðfvó ^ðàðð Ð'Ñ(ðð ð	ð
 ðð ðð 
óð8 #Ø!%ñ6àð6ð —n‘nð6ð &ð	6ð
 "ð6ð ð6ð Ð'Ñ(ð6ð ð6ð ð6ð -ð6ð �t‘ð6ð ˜$‘;ð6ð 
÷6r,   r   )rn   ru   Útypingr   r   r   r„   Ú8litellm.litellm_core_utils.prompt_templates.common_utilsr   Ú)litellm.llms.base_llm.chat.transformationr   r	   Úlitellm.types.llms.openair
   Úlitellm.utilsr   r   Úcommon_utilsr   ÚtiktokenÚ*litellm.litellm_core_utils.litellm_loggingr   ÚLiteLLMLoggingObjr‡   r   r<   r,   r*   ú<module>r’      sI   ðÛ Û ß ,Ñ ,ã õ÷ SÝ 6ß .å (áÛåWà$�Là€LôD�Zõ Dr,   