
    ^hc                         S r SSKJrJrJrJrJrJr  SSKrSSK	r	SSK
JrJr  SSKJr  SSKJr  SSKJr  \(       a	  SS	KJr  \rO\r " S
 S\5      rg)z
Support for gpt model family 
    )TYPE_CHECKINGAnyListOptionalUnioncastN)
BaseConfigBaseLLMException)AllMessageValues)ModelResponse   )OpenAIError)Loggingc                   >  ^  \ rS rSr% SrSr\\   \S'   Sr	\\
\\4      \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S	'   Sr\\   \S
'   Sr\\
\\4      \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'              S+S\\   S\\
\\4      S\\   S\\   S\\   S	\\   S
\\   S\\
\\4      S\\   S\\   S\\   SS4S jjr\U 4S j5       rS\S\4S jrS\S\S\S\S\4
S jrS\S\S\S\S\4
S jrS\\   S\S\\   4S jr S\S\\   S\S\S\S\4S jr!  S,S\S\"RF                  S\$S \%S!\S\\   S\S\S"\&S#\\   S$\\   S\$4S% jjr'S&\S'\S\
\\"RP                  4   S\)4S( jr* S-S\S\S\\   S\S#\\   S\4S) jjr+S*r,U =r-$ ).OpenAIGPTConfig   a  
Reference: https://platform.openai.com/docs/api-reference/chat/create

The class `OpenAIConfig` provides configuration for the OpenAI's Chat API interface. Below are the parameters:

- `frequency_penalty` (number or null): Defaults to 0. Allows a value between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, thereby minimizing repetition.

- `function_call` (string or object): This optional parameter controls how the model calls functions.

- `functions` (array): An optional parameter. It is a list of functions for which the model may generate JSON inputs.

- `logit_bias` (map): This optional parameter modifies the likelihood of specified tokens appearing in the completion.

- `max_tokens` (integer or null): This optional parameter helps to set the maximum number of tokens to generate in the chat completion.

- `n` (integer or null): This optional parameter helps to set how many chat completion choices to generate for each input message.

- `presence_penalty` (number or null): Defaults to 0. It penalizes new tokens based on if they appear in the text so far, hence increasing the model's likelihood to talk about new topics.

- `stop` (string / array / null): Specifies up to 4 sequences where the API will stop generating further tokens.

- `temperature` (number or null): Defines the sampling temperature to use, varying between 0 and 2.

- `top_p` (number or null): An alternative to sampling with temperature, used for nucleus sampling.
Nfrequency_penaltyfunction_call	functions
logit_bias
max_tokensnpresence_penaltystoptemperaturetop_presponse_formatreturnc                     [        5       R                  5       nUR                  5        H(  u  pUS:w  d  M  Uc  M  [        U R                  X5        M*     g )Nself)localscopyitemssetattr	__class__)r    r   r   r   r   r   r   r   r   r   r   r   locals_keyvalues                  e/home/james-whalen/.local/lib/python3.13/site-packages/litellm/llms/openai/chat/gpt_transformation.py__init__OpenAIGPTConfig.__init__?   s=     (--/!--/JCf}!23 *    c                     > [         TU ]  5       $ N)super
get_config)clsr%   s    r)   r0   OpenAIGPTConfig.get_configR   s    w!##r,   modelc                     / SQn/ nUS:w  a  US:w  a  UR                  S5        U[        R                  ;   d  U[        R                  ;   a  UR                  S5        X#-   $ )N)r   r   logprobstop_logprobsr   max_completion_tokens
modalities
predictionr   r   seedr   streamstream_optionsr   r   toolstool_choicer   r   max_retriesextra_headersparallel_tool_callszgpt-3.5-turbo-16kzgpt-4r   user)appendlitellmopen_ai_chat_completion_modelsopen_ai_text_completion_models)r    r3   base_paramsmodel_specific_paramss       r)   get_supported_openai_params+OpenAIGPTConfig.get_supported_openai_paramsV   sj    
4 !#((Ug-=!(():; W;;;g<<<!(( 22r,   non_default_paramsoptional_paramsdrop_paramsc                 p    U R                  U5      nUR                  5        H  u  pgXe;   d  M  XrU'   M     U$ )a  
If any supported_openai_params are in non_default_params, add them to optional_params, so they are use in API call

Args:
    non_default_params (dict): Non-default parameters to filter.
    optional_params (dict): Optional parameters to update.
    model (str): Model name for parameter support check.

Returns:
    dict: Updated optional_params with supported non-default parameters.
)rI   r#   )r    rK   rL   r3   rM   supported_openai_paramsparamr(   s           r)   _map_openai_params"OpenAIGPTConfig._map_openai_params   s@    $ #'"B"B5"I.446LE/).& 7 r,   c                 &    U R                  UUUUS9$ )N)rK   rL   r3   rM   )rQ   )r    rK   rL   r3   rM   s        r)   map_openai_params!OpenAIGPTConfig.map_openai_params   s(     &&1+#	 ' 
 	
r,   messagesc                     U$ r.    )r    rV   r3   s      r)   _transform_messages#OpenAIGPTConfig._transform_messages   s	     r,   litellm_paramsheadersc                     UUS.UE$ )z
Transform the overall request to be sent to the API.

Returns:
    dict: The transformed request. Sent as the body of the API call.
)r3   rV   rX   )r    r3   rV   rL   r[   r\   s         r)   transform_request!OpenAIGPTConfig.transform_request   s      
 
 	
r,   raw_responsemodel_responselogging_objrequest_dataencodingapi_key	json_modec                     [         e)zT
Transform the response from the API.

Returns:
    dict: The transformed response.
NotImplementedError)r    r3   r`   ra   rb   rc   rV   rL   r[   rd   re   rf   s               r)   transform_response"OpenAIGPTConfig.transform_response   s
    ( "!r,   error_messagestatus_codec                 H    [        UU[        [        R                  U5      S9$ )N)rm   messager\   )r   r   httpxHeaders)r    rl   rm   r\   s       r)   get_error_classOpenAIGPTConfig.get_error_class   s%     #!0
 	
r,   c                     [         er.   rh   )r    r\   r3   rV   rL   re   s         r)   validate_environment$OpenAIGPTConfig.validate_environment   s
     "!r,   rX   )NNNNNNNNNNN)NNr.   ).__name__
__module____qualname____firstlineno____doc__r   r   int__annotations__r   r   strdictr   listr   r   r   r   r   r   r   r   r*   classmethodr0   rI   boolrQ   rT   r   r   rY   r^   rp   Responser   LiteLLMLoggingObjr   rj   rq   r
   rr   ru   __static_attributes____classcell__)r%   s   @r)   r   r      s   4 (,x}+04M8E#t),-4 $Ix~$!%J% $J$Ax}&*hsm*'+D(5d#
$+!%K#%E8C=&*OXd^* ,048$(%)$(*.+/%)#*.4#C=4  c4i 014 D>	4
 TN4 SM4 C=4 #3-4 uS$Y'(4 c]4 }4 "$4 
4& $ $'3 '3 '3R   	
  
0
 
 
 	

 
 

-.7:		


 '(
 	

 
 
 

> "&$("" nn" &	"
 '" " '(" " " " #" D>" 
",
 
/2
=B4CV=W
	
 "&"" " '(	"
 " #" 
" "r,   r   )r{   typingr   r   r   r   r   r   rp   rD   )litellm.llms.base_llm.chat.transformationr	   r
   litellm.types.llms.openair   litellm.types.utilsr   common_utilsr   *litellm.litellm_core_utils.litellm_loggingr   _LiteLLMLoggingObjr   r   rX   r,   r)   <module>r      sE    C B   R 6 - &X*M"j M"r,   