
    ^h^                         S SK JrJrJrJr  S SKJrJr  S SKrS SK	J
r
JrJr  S SKJr  S SKJr  SSKJr   " S	 S
\
5      rg)    )AnyListOptionalUnion)HeadersResponseN)
BaseConfigBaseLLMExceptionLiteLLMLoggingObj)AllMessageValues)ModelResponse   PetalsErrorc                   V  ^  \ rS rSr% SrSr\\   \S'   \	R                  r\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S	'   Sr\\   \S
'   S\	R                  SSSSS4S\\   S\\   S\\   S\\   S\\   S	\\   S
\\   SS4S jjr\U 4S j5       rS\S\S\\\4   S\4S jrS\S\4S jrS\S\S\S\S\4
S jrS\S\\   S\S\S\S\4S jr   S%S\S\!S\"S\#S\S\\   S\S\S\$S \\   S!\\   S\"4S" jjr% S&S\S\S\\   S\S \\   S\4S# jjr&S$r'U =r($ )'PetalsConfig   a9  
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                     [        5       nUR                  5        H(  u  pU	S:w  d  M  U
c  M  [        U R                  X5        M*     g )Nself)localsitemssetattr	__class__)r   r   r   r   r   r   r   r   locals_keyvalues              g/home/james-whalen/.local/lib/python3.13/site-packages/litellm/llms/petals/completion/transformation.py__init__PetalsConfig.__init__1   s7     (!--/JCf}!23 *    c                     > [         TU ]  5       $ N)super
get_config)clsr!   s    r%   r,   PetalsConfig.get_configB   s    w!##r(   error_messagestatus_codeheadersc                     [        X!US9$ )N)r0   messager1   r   )r   r/   r0   r1   s       r%   get_error_classPetalsConfig.get_error_classF   s     #G
 	
r(   modelc                 
    / SQ$ )N)
max_tokensr   r   stream )r   r6   s     r%   get_supported_openai_params(PetalsConfig.get_supported_openai_paramsM   s    ??r(   non_default_paramsoptional_paramsdrop_paramsc                     UR                  5        H/  u  pVUS:X  a  XbS'   US:X  a  XbS'   US:X  a  XbS'   US:X  d  M+  XbS'   M1     U$ )Nr8   r   r   r   r9   )r   )r   r=   r>   r6   r?   paramr$   s          r%   map_openai_paramsPetalsConfig.map_openai_paramsP   sb     /446LE$49 01%16.+0( ,1) 7 r(   messageslitellm_paramsc                     [        S5      eNzXPetals transformation currently done in handler.py. [TODO] Move to the transformation.pyNotImplementedError)r   r6   rD   r>   rE   r1   s         r%   transform_requestPetalsConfig.transform_requestb   s     "f
 	
r(   raw_responsemodel_responselogging_objrequest_dataencodingapi_key	json_modec                     [        S5      erG   rH   )r   r6   rL   rM   rN   rO   rD   r>   rE   rP   rQ   rR   s               r%   transform_responsePetalsConfig.transform_responsen   s     "f
 	
r(   c                     0 $ r*   r:   )r   r1   r6   rD   r>   rQ   s         r%   validate_environment!PetalsConfig.validate_environment   s	     	r(   r:   )NNr*   ))__name__
__module____qualname____firstlineno____doc__r   r   int__annotations__litellmr8   r   r   boolr   floatr   r   r   r&   classmethodr,   strr   dictr   r
   r4   r   r;   rB   r   rJ   r   r   r   r   rT   rW   __static_attributes____classcell__)r!   s   @r%   r   r      s   * !%J$ HSM  !%Ix~$#'K%'E8C=!E8E?!*.. %) $('+#!%.24SM4 !
4 D>4 e_4 }4 4 %UO4 
4" $ $
 
/2
=B4==Q
	
@ @ @   	
  
$



 '(

 	


 

 

 


. "&$(

 
 &	

 '
 
 '(
 
 
 
 #
 D>
 

0 "&  '(	
  # 
 r(   r   )typingr   r   r   r   httpxr   r   r`   )litellm.llms.base_llm.chat.transformationr	   r
   r   litellm.types.llms.openair   litellm.types.utilsr   common_utilsr   r   r:   r(   r%   <module>rn      s4    - - #  
 7 - &w: wr(   