
    ^h                         S r SSKJrJrJrJr  SSKJr  SSKJ	r	J
r
Jr  SSKJrJrJrJr  SSKJr  SS	KJr   " S
 S\5      rg)z
Support for gpt model family 
    )ListOptionalUnioncast)convert_content_list_to_str)AllMessageValuesAllPromptValuesOpenAITextCompletionUserMessage)ChoicesMessageModelResponseTextCompletionResponse   )OpenAIGPTConfig   )is_tokens_or_list_of_tokensc                     ^  \ rS rSr% SrSr\\   \S'   Sr	\\
   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S	'   Sr\\   \S
'   Sr\\   \S'   Sr\\\\4      \S'   Sr\\   \S'               SS\\   S\\
   S\\   S\\   S\\   S	\\   S
\\   S\\   S\\\\4      S\\   S\\   S\\   SS4S jjr\U 4S j5       rS\\\   \\   4   S\4S jr  SS\\    S\\!   4S jjr"S\S\4S jr#Sr$U =r%$ )OpenAITextCompletionConfig   a  
Reference: https://platform.openai.com/docs/api-reference/completions/create

The class `OpenAITextCompletionConfig` provides configuration for the OpenAI's text completion API interface. Below are the parameters:

- `best_of` (integer or null): This optional parameter generates server-side completions and returns the one with the highest log probability per token.

- `echo` (boolean or null): This optional parameter will echo back the prompt in addition to the completion.

- `frequency_penalty` (number or null): Defaults to 0. It is a numbers from -2.0 to 2.0, where positive values decrease the model's likelihood to repeat the same line.

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

- `logprobs` (integer or null): This optional parameter includes the log probabilities on the most likely tokens as well as the chosen tokens.

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

- `n` (integer or null): This optional parameter sets how many completions to generate for each prompt.

- `presence_penalty` (number or null): Defaults to 0 and can be between -2.0 and 2.0. Positive values increase 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.

- `suffix` (string or null): Defines the suffix that comes after a completion of inserted text.

- `temperature` (number or null): This optional parameter defines the sampling temperature to use.

- `top_p` (number or null): An alternative to sampling with temperature, used for nucleus sampling.
Nbest_ofechofrequency_penalty
logit_biaslogprobs
max_tokensnpresence_penaltystopsuffixtemperaturetop_p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    r!   locals_keyvalues                   g/home/james-whalen/.local/lib/python3.13/site-packages/litellm/llms/openai/completion/transformation.py__init__#OpenAITextCompletionConfig.__init__?   s=     (--/!--/JCf}!23 *    c                     > [         TU ]  5       $ )N)super
get_config)clsr)   s    r-   r3   %OpenAITextCompletionConfig.get_configS   s    w!##r0   messagesc                    [        U5      S:X  aw  US   R                  S5      nU(       a7  [        U[        5      (       a"  [	        U5      (       a  [        [        U5      nU$ Sn[        [        [        US   5      5      nX4-  n U$ / nU H.  n [        [        [        U5      5      nUR                  U5        M0     UnU$ ! [         a  nUeS nAff = f)Nr   r   content )lenget
isinstancelistr   r   r	   r   r   append	Exception)r$   r6   message_contentopenai_promptr8   prompt_str_listmes           r-   _transform_prompt,OpenAITextCompletionConfig._transform_promptW   s     x=A&qkooi8O55/@@15o1W   !#5)8A;7 (  *,O9$?OQR:STG#**73  ,M ! Gs   *C
CCCresponse_objectmodel_response_objectc                 p    Ub  Uc  [        S5      e/ n[        US   5       H0  u  pE[        US   SS9n[        US   XFS9nUR	                  U5        M2     X2l        SU;   a  [        USUS   5        S	U;   a
  US	   Ul        S
U;   a
  US
   Ul        UUR                  S'   U$ ! [         a  nUeS nAff = f)NzError in response object formatchoicestext	assistant)r8   rolefinish_reason)rN   indexmessageusageidmodeloriginal_response)
ValueError	enumerater   r   r>   rJ   r(   rR   rS   _hidden_paramsr?   )r$   rG   rH   choice_listidxchoicerP   rD   s           r-   %convert_to_chat_model_response_object@OpenAITextCompletionConfig.convert_to_chat_model_response_objectt   s    
	&*?*G !BCCK()CD!"6N$ !"("9 ""6*  E -8)/)-w8PQ&+:4+@%(/).=g.F%+   "001DE )( 	G	s   B!B$ $
B5.B00B5rS   c                 
    / SQ$ )N)	functionsfunction_callr    r!   r   streamstream_optionsr   r   r   r   r   userresponse_formatseedtoolstool_choicemax_retriesr   top_logprobsextra_headers )r$   rS   s     r-   get_supported_openai_params6OpenAITextCompletionConfig.get_supported_openai_params   s    
 	
r0   rj   )NNNNNNNNNNNN)NN)&__name__
__module____qualname____firstlineno____doc__r   r   int__annotations__r   boolr   r   dictr   r   r   r   r   r   strr=   r   floatr.   classmethodr3   r   r   r
   r	   rE   r   r   r[   rk   __static_attributes____classcell__)r)   s   @r-   r   r      s   < "GXc]!D(4.'+x}+!%J%"Hhsm" $J$Ax}&*hsm*'+D(5d#
$+ FHSM  "&#+/%)"&$(*.+/ $'+!%4#4 tn4 $C=	4
 TN4 3-4 SM4 C=4 #3-4 uS$Y'(4 4 e_4 4 
4( $ $-.5T0UUV 
> =A9=#!"89#  (6#J
 
 
 
r0   r   N)rq   typingr   r   r   r   8litellm.litellm_core_utils.prompt_templates.common_utilsr   litellm.types.llms.openair   r	   r
   litellm.types.utilsr   r   r   r   chat.gpt_transformationr   utilsr   r   rj   r0   r-   <module>r      s>    / . 
 X W 5 .[
 [
r0   