Ë
    uPêjØ  ã                   ó‚   — d dl Z d dlmZ d dlmZmZmZmZmZ d dl	Z	d dl
mZ d dlmZ d dlmZ d dlmZ  G d„ d	e«      Zy)
é    N)Ú	Coroutine)ÚAnyÚFinalÚLiteralÚcastÚoverload)ÚMIN_NON_ZERO_TEMPERATURE)ÚOpenAIGPTConfig©Úget_secret_str)ÚAllMessageValuesc                   óR  ‡ — e Zd ZU dZededz  fd„«       ZdZedz  e	d<   dZ
eez  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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%dedz  deez  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edz  deez  dz  ddfd„Zeˆ fd„«       Zdefd„Zdededededef
d„Zdee   dee   fd„Ze dee   dede!d   de"e#e#ee   f   fd„«       Z$e 	 d&dee   dede!d   dee   fd „«       Z$	 d&dee   dededee   e"e#e#ee   f   z  fˆ fd!„Z$d"edz  d#edz  de%edz  edz  f   fd$„Z&ˆ xZ'S )'ÚDeepInfraConfigzÃ
    Reference: https://deepinfra.com/docs/advanced/openai_api

    The class `DeepInfra` provides configuration for the DeepInfra's Chat Completions API interface. Below are the parameters:
    ÚreturnNc                  ó   — y)NÚ	deepinfra© )Úselfs    úo/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/deepinfra/chat/transformation.pyÚcustom_llm_providerz#DeepInfraConfig.custom_llm_provider   s   € àó    Úfrequency_penaltyÚfunction_callÚ	functionsÚ
logit_biasÚ
max_tokensÚnÚpresence_penaltyÚstopÚtemperatureÚtop_pÚresponse_formatÚtoolsÚtool_choicec                 ó¤   — t        «       j                  «       }|j                  «       D ]%  \  }}|dk7  sŒ|€Œt        | j                  ||«       Œ' y )Nr   )ÚlocalsÚcopyÚitemsÚsetattrÚ	__class__)r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   Úlocals_ÚkeyÚvalues                    r   Ú__init__zDeepInfraConfig.__init__%   sF   € ô   ›Ÿ™›ˆØ!Ÿ-™-›/ò 	4‰JˆC�Ø�f‹} Ñ!2Ü˜Ÿ™¨¨UÕ3ñ	4r   c                 ó    •— t         ‰| �  «       S ©N)ÚsuperÚ
get_config)Úclsr*   s    €r   r2   zDeepInfraConfig.get_config:   s   ø€ ä‰wÑ!Ó#Ð#r   Úmodelc                 ór   — g d¢}t        j                  || j                  ¬«      r|j                  d«       |S )N)Ústreamr   r   r   r   r   Úmax_completion_tokensr   r   r   r    r!   r"   r#   r$   )r4   r   Úreasoning_effort)ÚlitellmÚsupports_reasoningr   Úappend)r   r4   Úsupported_openai_paramss      r   Úget_supported_openai_paramsz+DeepInfraConfig.get_supported_openai_params>   s=   € ò*
Ðô$ ×%Ñ%ØØ $× 8Ñ 8õ
ð $×*Ñ*Ð+=Ô>Ø&Ð&r   Únon_default_paramsÚoptional_paramsÚdrop_paramsc                 óR  — | j                  |¬«      }|j                  «       D ]�  \  }}|dk(  r|dk(  r|dk(  rt        }|dk(  rJ|dk7  sŒ&|dk7  sŒ,t        j                  du s|du rd }ŒEt        j
                  j                  d	|› d
�d¬«      ‚|dk(  r||d<   Œu||v sŒz|€Œ}|||<   Œƒ |S )N)r4   r    r   z"mistralai/Mistral-7B-Instruct-v0.1r$   ÚautoÚnoneTz&Deepinfra doesn't support tool_choice=zS. To drop unsupported openai params from the call, set `litellm.drop_params = True`i�  )ÚmessageÚstatus_coder7   r   )r=   r(   r	   r9   r@   ÚutilsÚUnsupportedParamsError)r   r>   r?   r4   r@   r<   Úparamr-   s           r   Úmap_openai_paramsz!DeepInfraConfig.map_openai_paramsX   sé   € ð *.×)IÑ)IÐPUÐ)IÓ)VÐØ.×4Ñ4Ó6ò 	3‰LˆE�5à˜Ò&¨5°Aª:¸%ÐCgÒ:gä0�Ø˜Ò%Ø˜F“? u°£ä×*Ñ*¨dÑ2°kÀTÑ6IØ $™ä%Ÿm™m×BÑBØ&LÈUÈGð  Tgð  %hØ(+ð Có ð ð Ð1Ò1Ø05� Ò-ØÐ1Ò1ØÑ$Ø-2�O EÒ*ð'	3ð( Ðr   Úmessagesc                 óH  — |D ]œ  }|j                  d«      dk(  sŒ|j                  d«      }t        |t        «      sŒ:t        |«      dk(  r=t        |d   t        «      r*|d   j                  d«      dk(  rd|d   v r|d   d   |d<   Œ…t        j                  |«      |d<   Œž |S )a€  
        Transform tool message content from array to string format for DeepInfra compatibility.

        DeepInfra requires tool message content to be a string, not an array.
        This method converts tool message content from array format to string format.

        Example transformation:
        - Input:  {"role": "tool", "content": [{"type": "text", "text": "20"}]}
        - Output: {"role": "tool", "content": "20"}

        Or if content is complex:
        - Input:  {"role": "tool", "content": [{"type": "text", "text": "result"}]}
        - Output: {"role": "tool", "content": "[{"type": "text", "text": "result"}]"}
        ÚroleÚtoolÚcontenté   r   ÚtypeÚtext)ÚgetÚ
isinstanceÚlistÚlenÚdictÚjsonÚdumps)r   rJ   rD   rN   s       r   Ú_transform_tool_message_contentz/DeepInfraConfig._transform_tool_message_contentv   s®   € ð  ò 	AˆGØ�{‰{˜6Ó" fÓ,Ø!Ÿ+™+ iÓ0�ô ˜g¤tÕ,ô ˜G›¨Ò)Ü& w¨q¡z´4Ô8Ø# A™JŸN™N¨6Ó2°fÒ<Ø" g¨a¡jÑ0ð .5°Q©Z¸Ñ-?˜ 	Ò*ô .2¯Z©Z¸Ó-@˜ 	Ò*ð#	Að& ˆr   Úis_asyncTc                  ó   — y r0   r   ©r   rJ   r4   rZ   s       r   Ú_transform_messagesz#DeepInfraConfig._transform_messagesš   s   € ð 7:r   Fc                  ó   — y r0   r   r\   s       r   r]   z#DeepInfraConfig._transform_messagesŸ   s   € ð "%r   c                 ó”   •‡ ‡‡— |rˆˆˆˆ fd„} |«       S t         ‰‰ �  ‰‰t        t        d   d«      ¬«      }‰ j	                  |«      S )zv
        Transform messages for DeepInfra compatibility.
        Handles both sync and async transformations.
        c               “   ó”   •K  — t         t        ‰�  ‰‰t        t        d   d«      ¬«      } | ƒ d {  –—† }‰j                  |«      S 7 Œ­w)NT©rJ   r4   rZ   )r1   r   r]   r   r   rY   )Úparent_resultÚtransformed_messagesr*   rJ   r4   r   s     €€€€r   Ú_async_transformz=DeepInfraConfig._transform_messages.<locals>._async_transform°   sU   øè ø€ ä',¬_¸dÑ'WØ%¨U¼TÄ'È$Á-ÐQUÓ=Vð (Xó (�ð 5B×.AÐ$Ø×;Ñ;Ð<PÓQÐQð /Bús   ƒ-A°A±AFra   )r1   r]   r   r   rY   )r   rJ   r4   rZ   rd   rb   r*   s   ```   €r   r]   z#DeepInfraConfig._transform_messages§   sT   û€ ñ ÷Rñ $Ó%Ð%ô $)¡7Ñ#>Ø!¨¼¼gÀe¹nÈeÓ9Tð $?ó $ˆMð ×7Ñ7¸ÓFÐFr   Úapi_baseÚapi_keyc                 óN   — |xs t        d«      xs d}|xs t        d«      }||fS )NÚDEEPINFRA_API_BASEz#https://api.deepinfra.com/v1/openaiÚDEEPINFRA_API_KEYr   )r   re   rf   Údynamic_api_keys       r   Ú$_get_openai_compatible_provider_infoz4DeepInfraConfig._get_openai_compatible_provider_infoÁ   s5   € ð Òlœ~Ð.BÓCÒlÐGlˆØ!(Ò!O¬NÐ;NÓ,OˆØ˜Ð(Ð(r   )NNNNNNNNNNNNN)F)(Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚpropertyÚstrr   r   ÚintÚ__annotations__r   rV   r   rT   r   r   r   r   r   r    r!   r"   r#   r$   r.   Úclassmethodr2   r=   ÚboolrI   r   rY   r   r   r   r   r]   Útuplerk   Ú__classcell__)r*   s   @r   r   r      s‹  ø… ñð ð S¨4¡Zò ó ðð %)Ð�s˜T‘zÓ(Ø'+€M�3˜‘: Ñ$Ó+Ø!€Iˆt�d‰{Ó!Ø"€J��t‘Ó"Ø!€J��d‘
Ó!Ø€A€sˆT�zÓØ#'Ð�c˜D‘jÓ'Ø"€Dˆ#�‰*�tÑ
Ó"Ø"€K��t‘Ó"Ø€Eˆ3�‰:ÓØ#'€O�T˜D‘[Ó'Ø€Eˆ4�$‰;ÓØ%)€K��t‘˜dÑ"Ó)ð )-Ø+/Ø!%Ø"&Ø!%ØØ'+Ø"&Ø"&Ø Ø'+Ø!Ø)-ñ4à ™:ð4ð ˜T‘z DÑ(ð4ð ˜$‘;ð	4ð
 ˜4‘Kð4ð ˜$‘Jð4ð �‰:ð4ð  ™*ð4ð �D‰j˜4Ñð4ð ˜4‘Zð4ð �T‰zð4ð  ™ð4ð �d‰{ð4ð ˜4‘Z $Ñ&ð4ð 
ó4ð* ó$ó ð$ð'°ó 'ð4à ðð ðð ð	ð
 ðð 
óð<"¸Ð=MÑ8Nð "ÐSWÐXhÑSió "ðH ð:ØÐ-Ñ.ð:Ø7:ð:ØFMÈdÁmð:à	�3˜˜TÐ"2Ñ3Ð3Ñ	4ò:ó ð:ð ð
 $)ñ	%àÐ'Ñ(ð%ð ð%ð ˜%‘.ð	%ð
 
ÐÑ	ò%ó ð%ð NSñGØÐ-Ñ.ðGØ7:ðGØFJðGà	ÐÑ	 )¨C°°dÐ;KÑ6LÐ,LÑ"MÑ	MõGð4)Ø˜d™
ð)Ø-0°4©Zð)à	ˆs�T‰z˜3 ™:Ð%Ñ	&÷)r   r   )rW   Úcollections.abcr   Útypingr   r   r   r   r   r9   Úlitellm.constantsr	   Ú+litellm.llms.openai.chat.gpt_transformationr
   Úlitellm.secret_managers.mainr   Úlitellm.types.llms.openair   r   r   r   r   ú<module>r~      s.   ðÛ Ý %ß 6Õ 6ã Ý 6Ý GÝ 7Ý 6ô{)�oõ {)r   