Ë
    uPêj©  ã                   óx   — d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	m
Z
mZmZ ddlmZ dd	lmZ  G d
„ dee«      Zy)z
Support for gpt model family
é    )ÚFinal)ÚBaseTextCompletionConfig)ÚAllMessageValuesÚOpenAITextCompletionUserMessage)ÚChoicesÚMessageÚModelResponseÚTextCompletionResponseé   )ÚOpenAIGPTConfigé   ©Ú_transform_promptc                   ó   ‡ — e Zd ZU dZdZedz  ed<   dZedz  ed<   dZ	edz  ed<   dZ
edz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed	<   dZedz  ed
<   dZeez  dz  ed<   dZedz  ed<   	 	 	 	 	 	 	 	 	 	 	 	 ddedz  dedz  dedz  dedz  dedz  dedz  d	edz  d
edz  deez  dz  dedz  dedz  dedz  ddfd„Zeˆ fd„«       Z	 	 ddedz  dedz  fd„Zdedefd„Zdedee   ee   z  dededef
d„Zˆ xZS )ÚOpenAITextCompletionConfigaî  
    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                 ó¤   — t        «       j                  «       }|j                  «       D ]%  \  }}|dk7  sŒ|€Œt        | j                  ||«       Œ' y )NÚself)ÚlocalsÚcopyÚitemsÚsetattrÚ	__class__)r    r   r   r   r   r   r   r   r   r   r   r   r   Úlocals_ÚkeyÚvalues                   úr/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/openai/completion/transformation.pyÚ__init__z#OpenAITextCompletionConfig.__init__9   sF   € ô  ›Ÿ™›ˆØ!Ÿ-™-›/ò 	4‰JˆC�Ø�f‹} Ñ!2Ü˜Ÿ™¨¨UÕ3ñ	4ó    c                 ó    •— t         ‰| �  «       S )N)ÚsuperÚ
get_config)Úclsr%   s    €r)   r.   z%OpenAITextCompletionConfig.get_configM   s   ø€ ä‰wÑ!Ó#Ð#r+   Úresponse_objectÚmodel_response_objectc           
      óŽ  — 	 |�|€t        d«      ‚g }t        |d   «      D ]H  \  }}t        |d   d¬«      }t        |d   |||j	                  dd «      ¬«      }|j                  |«       ŒJ ||_        d	|v rt        |d	|d	   «       d
|v r
|d
   |_        d|v r
|d   |_	        ||j                  d<   |S # t        $ r}|‚d }~ww xY w)NzError in response object formatÚchoicesÚtextÚ	assistant)ÚcontentÚroleÚfinish_reasonr   )r8   ÚindexÚmessager   ÚusageÚidÚmodelÚoriginal_response)Ú
ValueErrorÚ	enumerater   r   ÚgetÚappendr3   r$   r<   r=   Ú_hidden_paramsÚ	Exception)r    r0   r1   Úchoice_listÚidxÚchoicer:   Úes           r)   Ú%convert_to_chat_model_response_objectz@OpenAITextCompletionConfig.convert_to_chat_model_response_objectQ   s  € ð
!	àÐ&Ð*?Ð*GÜ Ð!BÓCÐCØ02ˆKÜ(¨¸Ñ)CÓDò +‘��VÜ!Ø" 6™NØ$ô�ô !Ø"(¨Ñ"9ØØ#Ø#ŸZ™Z¨
°DÓ9ô	�ð ×"Ñ" 6Õ*ð+ð -8Ð!Ô)à˜/Ñ)ÜÐ-¨w¸ÈÑ8PÔQà�Ñ&Ø+:¸4Ñ+@Ð%Ô(à˜/Ñ)Ø.=¸gÑ.FÐ%Ô+ð  ð "×0Ñ0Ð1DÑEð )Ð(øÜò 	ØˆGûð	ús   ‚B1B4 Â4	CÂ=B?Â?Cr=   c                 ó
   — g d¢S )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    r=   s     r)   Úget_supported_openai_paramsz6OpenAITextCompletionConfig.get_supported_openai_paramsy   s   € ò
ð 	
r+   ÚmessagesÚoptional_paramsÚheadersc                 ó&   — t        |«      }||dœ|¥S )N)r=   Úpromptr   )r    r=   rY   rZ   r[   r]   s         r)   Ú!transform_text_completion_requestz<OpenAITextCompletionConfig.transform_text_completion_request’   s(   € ô *¨(Ó3ˆàØñ
ð ð
ð 	
r+   )NNNNNNNNNNNN)NN) Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚintÚ__annotations__r   Úboolr   r   Údictr   r   r   r   r   ÚstrÚlistr   Úfloatr*   Úclassmethodr.   r
   r	   rI   rX   r   r   r^   Ú__classcell__)r%   s   @r)   r   r      s  ø… ñð< €GˆS�4‰ZÓØ€Dˆ$�‰+ÓØ$(Ð�s˜T‘zÓ(Ø"€J��t‘Ó"Ø€Hˆc�D‰jÓØ!€J��d‘
Ó!Ø€A€sˆT�zÓØ#'Ð�c˜D‘jÓ'Ø"€Dˆ#�‰*�tÑ
Ó"Ø€FˆC�$‰JÓð #Ø Ø(,Ø"&Ø#Ø!%ØØ'+Ø"&Ø!Ø$(Ø"ñ4à�t‘ð4ð �T‰kð4ð  ™:ð	4ð
 ˜4‘Kð4ð ˜‘*ð4ð ˜$‘Jð4ð �‰:ð4ð  ™*ð4ð �D‰j˜4Ñð4ð �d‘
ð4ð ˜T‘\ð4ð �t‰|ð4ð 
ó4ð( ó$ó ð$ð
 :>Ø6:ñ&à/°$Ñ6ð&ð  -¨tÑ3ó&ðP
°ð 
¸ó 
ð2
àð
ð Ð'Ñ(¨4Ð0OÑ+PÑPð
ð ð	
ð
 ð
ð 
÷
r+   r   N)rb   Útypingr   Ú/litellm.llms.base_llm.completion.transformationr   Úlitellm.types.llms.openair   r   Úlitellm.types.utilsr   r   r	   r
   Úchat.gpt_transformationr   Úutilsr   r   rW   r+   r)   ú<module>rr      s2   ðñõ å Tß Wß WÓ Wå 5Ý $ôO
Ð!9¸?õ O
r+   