Ë
    uPêjd  ã                   ó†   — d dl mZmZ d dlmZmZ d dlZd dlmZm	Z	m
Z
 d dlmZ d dlmZ ddlmZ erd dlZ G d	„ d
e«      Zy)é    )ÚTYPE_CHECKINGÚFinal)ÚHeadersÚResponseN)Ú
BaseConfigÚBaseLLMExceptionÚLiteLLMLoggingObj)ÚAllMessageValues)ÚModelResponseé   ©ÚPetalsErrorc                   óD  ‡ — e Zd ZU dZdZedz  ed<   ej                  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ej                  dddddf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ededee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e   dededed
efd„Z	 	 d%dede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!	 	 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"ˆ xZ#S )&ÚPetalsConfigae  
    Reference: https://github.com/petals-infra/chat.petals.dev#post-apiv1generate
    The `PetalsConfig` class encapsulates the configuration for the Petals API. The properties of this class are described below:

    - `max_length` (integer): This represents the maximum length of the generated text (including the prefix) in tokens.

    - `max_new_tokens` (integer): This represents the maximum number of newly generated tokens (excluding the prefix).

    The generation parameters are compatible with `.generate()` from Hugging Face's Transformers library:

    - `do_sample` (boolean, optional): If set to 0 (default), the API runs greedy generation. If set to 1, the API performs sampling using the parameters below:

    - `temperature` (float, optional): This value sets the temperature for sampling.

    - `top_k` (integer, optional): This value sets the limit for top-k sampling.

    - `top_p` (float, optional): This value sets the limit for top-p (nucleus) sampling.

    - `repetition_penalty` (float, optional): This helps apply the repetition penalty during text generation, as discussed in this paper.
    NÚ
max_lengthÚmax_new_tokensÚ	do_sampleÚtemperatureÚtop_kÚtop_pÚrepetition_penaltyÚ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   Úlocals_ÚkeyÚvalues              úr/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/petals/completion/transformation.pyÚ__init__zPetalsConfig.__init__2   sF   € ô  ›Ÿ™›ˆØ!Ÿ-™-›/ò 	4‰JˆC�Ø�f‹} Ñ!2Ü˜Ÿ™¨¨UÕ3ñ	4ó    c                 ó    •— t         ‰| �  «       S ©N)ÚsuperÚ
get_config)Úclsr   s    €r#   r)   zPetalsConfig.get_configA   s   ø€ ä‰wÑ!Ó#Ð#r%   Úerror_messageÚstatus_codeÚheadersc                 ó   — t        |||¬«      S )N)r,   Úmessager-   r   )r   r+   r,   r-   s       r#   Úget_error_classzPetalsConfig.get_error_classE   s   € Ü {¸MÐSZÔ[Ð[r%   Úmodelc                 ó
   — g d¢S )N)Ú
max_tokensr   r   Ústream© )r   r1   s     r#   Úget_supported_openai_paramsz(PetalsConfig.get_supported_openai_paramsH   s   € Ú?Ð?r%   Únon_default_paramsÚoptional_paramsÚdrop_paramsc                 óˆ   — |j                  «       D ].  \  }}|dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  sŒ*||d<   Œ0 |S )Nr3   r   r   r   r4   )r   )r   r7   r8   r1   r9   Úparamr"   s          r#   Úmap_openai_paramszPetalsConfig.map_openai_paramsK   sq   € ð /×4Ñ4Ó6ò 	2‰LˆE�5Ø˜Ò$Ø49�Ð 0Ñ1Ø˜Ò%Ø16� Ñ.Ø˜ÒØ+0� Ñ(Ø˜Ó Ø,1� Ò)ð	2ð Ðr%   ÚmessagesÚlitellm_paramsc                 ó   — t        d«      ‚©NzXPetals transformation currently done in handler.py. [TODO] Move to the transformation.py©ÚNotImplementedError)r   r1   r=   r8   r>   r-   s         r#   Útransform_requestzPetalsConfig.transform_request]   s   € ô "Øfó
ð 	
r%   Úraw_responseÚmodel_responseÚlogging_objÚrequest_dataÚencodingztiktoken.Encoding | NoneÚapi_keyÚ	json_modec                 ó   — t        d«      ‚r@   rA   )r   r1   rD   rE   rF   rG   r=   r8   r>   rH   rI   rJ   s               r#   Útransform_responsezPetalsConfig.transform_responsei   s   € ô "Øfó
ð 	
r%   Úapi_basec                 ó   — i S r'   r5   )r   r-   r1   r=   r8   r>   rI   rM   s           r#   Úvalidate_environmentz!PetalsConfig.validate_environment{   s	   € ð ˆ	r%   )NN)$Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚintÚ__annotations__Úlitellmr3   r   r   Úboolr   Úfloatr   r   r   r$   Úclassmethodr)   ÚstrÚdictr   r   r0   Úlistr6   r<   r
   rC   r   r   r	   rL   rO   Ú__classcell__)r   s   @r#   r   r      sÉ  ø… ñð* "€J��d‘
Ó!Ø!(×!3Ñ!3€N�C˜$‘JÓ3Ø!€Iˆt�d‰{Ó!Ø $€K�˜‘Ó$Ø€Eˆ3�‰:ÓØ€Eˆ5�4‰<ÓØ'+Ð˜ ™Ó+ð "&Ø%,×%7Ñ%7Ø!%Ø$(Ø Ø"Ø+/ñ4à˜$‘Jð4ð ˜d™
ð4ð ˜$‘;ð	4ð
 ˜T‘\ð4ð �T‰zð4ð �t‰|ð4ð " D™Lð4ð 
ó4ð ó$ó ð$ð\¨Sð \¸sð \ÈTÐT[É^ð \Ð`pó \ð@°ð @¸ó @ðà ðð ðð ð	ð
 ðð 
óð$

àð

ð Ð'Ñ(ð

ð ð	

ð
 ð

ð ð

ð 
ó

ð. #Ø!%ñ
àð
ð ð
ð &ð	
ð
 'ð
ð ð
ð Ð'Ñ(ð
ð ð
ð ð
ð -ð
ð �t‘ð
ð ˜$‘;ð
ð 
ó
ð2 #Ø#ñ
àð
ð ð
ð Ð'Ñ(ð	
ð
 ð
ð ð
ð �t‘ð
ð ˜‘*ð
ð 
÷
r%   r   )Útypingr   r   Úhttpxr   r   rV   Ú)litellm.llms.base_llm.chat.transformationr   r   r	   Úlitellm.types.llms.openair
   Úlitellm.types.utilsr   Úcommon_utilsr   Útiktokenr   r5   r%   r#   ú<module>re      s7   ðß 'ç #ã ÷ñ õ
 7Ý -å &áÛôq�:õ qr%   