
    g                         d dl mZmZ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  G d	 d
e
      Zy)    )AnyListOptionalUnion)HeadersResponseN)
BaseConfigBaseLLMExceptionLiteLLMLoggingObj)AllMessageValues)ModelResponse   PetalsErrorc                   D    e Zd ZU dZdZee   ed<   ej                  Z
e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   ed<   dZee   ed	<   dej                  dddddfdee   dee   dee   dee   dee   dee   d	ee   d
dfdZe fd       Zdededeeef   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e#dee   d ee   d
e!fd!Z$	 	 d$dededee   dedee   d"ee   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                         D ]%  \  }	}
|	dk7  s|
t        | j                  |	|
       ' y )Nself)localsitemssetattr	__class__)r   r   r   r   r   r   r   r   locals_keyvalues              b/var/www/openai/venv/lib/python3.12/site-packages/litellm/llms/petals/completion/transformation.py__init__zPetalsConfig.__init__1   s;     (!--/JCf}!2U3 *    c                      t         |          S N)super
get_config)clsr    s    r$   r*   zPetalsConfig.get_configB   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_classF   s     #]G
 	
r&   modelc                 
    g dS )N)
max_tokensr   r   stream )r   r2   s     r$   get_supported_openai_paramsz(PetalsConfig.get_supported_openai_paramsM   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 )Nr4   r   r   r   r5   )r   )r   r8   r9   r2   r:   paramr#   s          r$   map_openai_paramszPetalsConfig.map_openai_paramsP   sl     /446LE5$49 01%16.+0( ,1) 7 r&   messageslitellm_paramsc                     t        d      NzXPetals transformation currently done in handler.py. [TODO] Move to the transformation.pyNotImplementedError)r   r2   r>   r9   r?   r.   s         r$   transform_requestzPetalsConfig.transform_requestb   s     "f
 	
r&   raw_responsemodel_responselogging_objrequest_dataencodingapi_key	json_modec                     t        d      rA   rB   )r   r2   rE   rF   rG   rH   r>   r9   r?   rI   rJ   rK   s               r$   transform_responsezPetalsConfig.transform_responsen   s     "f
 	
r&   api_basec                     i S r(   r6   )r   r.   r2   r>   r9   rJ   rN   s          r$   validate_environmentz!PetalsConfig.validate_environment   s	     	r&   )NN)'__name__
__module____qualname____doc__r   r   int__annotations__litellmr4   r   r   boolr   floatr   r   r   r%   classmethodr*   strr   dictr   r
   r1   r   r7   r=   r   rD   r   r   r   r   rM   rP   __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 "&"&		 	 '(		
 	 #	 3-	 
	r&   r   )typingr   r   r   r   httpxr   r   rW   )litellm.llms.base_llm.chat.transformationr	   r
   r   litellm.types.llms.openair   litellm.types.utilsr   common_utilsr   r   r6   r&   r$   <module>rd      s4    - - #  
 7 - &x: xr&   