o
    ưi                     @   s|   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
 d
e
ZdS )    )AnyListOptionalUnion)HeadersResponseN)
BaseConfigBaseLLMExceptionLiteLLMLoggingObj)AllMessageValues)ModelResponse   PetalsErrorc                       s  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dZe fddZdededeeef d
efddZded
efddZdedededed
ef
ddZdedee dededed
efd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'd(Z$		d,dededee deded%ee d)ee d
efd*d+Z%  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                 C   s>   t   }| D ]\}	}
|	dkr|
d urt| j|	|
 q	d S )Nself)localscopyitemssetattr	__class__)r   r   r   r   r   r   r   r   Zlocals_keyvalue r!   d/home/app/Keep/.python/lib/python3.10/site-packages/litellm/llms/petals/completion/transformation.py__init__1   s   
zPetalsConfig.__init__c                    s
   t   S N)super
get_config)clsr   r!   r"   r&   B   s   
zPetalsConfig.get_configerror_messagestatus_codeheadersc                 C   s   t |||dS )N)r*   messager+   r   )r   r)   r*   r+   r!   r!   r"   get_error_classF   s   zPetalsConfig.get_error_classmodelc                 C   s   g dS )N)
max_tokensr   r   streamr!   )r   r.   r!   r!   r"   get_supported_openai_paramsM   s   z(PetalsConfig.get_supported_openai_paramsnon_default_paramsoptional_paramsdrop_paramsc                 C   sV   |  D ]$\}}|dkr||d< |dkr||d< |dkr ||d< |dkr(||d< q|S )Nr/   r   r   r   r0   )r   )r   r2   r3   r.   r4   paramr    r!   r!   r"   map_openai_paramsP   s   zPetalsConfig.map_openai_paramsmessageslitellm_paramsc                 C      t dNzXPetals transformation currently done in handler.py. [TODO] Move to the transformation.pyNotImplementedError)r   r.   r7   r3   r8   r+   r!   r!   r"   transform_requestb   s   zPetalsConfig.transform_requestraw_responsemodel_responselogging_objrequest_dataencodingapi_key	json_modec                 C   r9   r:   r;   )r   r.   r>   r?   r@   rA   r7   r3   r8   rB   rC   rD   r!   r!   r"   transform_responsen   s   zPetalsConfig.transform_responseapi_basec                 C   s   i S r$   r!   )r   r+   r.   r7   r3   r8   rC   rF   r!   r!   r"   validate_environment   s   
z!PetalsConfig.validate_environment)NN)'__name__
__module____qualname____doc__r   r   int__annotations__litellmr/   r   r   boolr   floatr   r   r   r#   classmethodr&   strr   dictr   r	   r-   r   r1   r6   r   r=   r   r   r
   r   rE   rG   __classcell__r!   r!   r(   r"   r      s   
 	





	

	r   )typingr   r   r   r   Zhttpxr   r   rN   Z)litellm.llms.base_llm.chat.transformationr   r	   r
   Zlitellm.types.llms.openair   Zlitellm.types.utilsr   Zcommon_utilsr   r   r!   r!   r!   r"   <module>   s    