
    h                     F    d Z ddlmZmZ ddlmZ ddlmZ  G d de      Zy)	z{
Support for OpenAI's `/v1/chat/completions` endpoint. 

Calls done in OpenAI/openai.py as DataRobot is openai-compatible.
    )OptionalTupleget_secret_str   )OpenAILikeChatConfigc                       e Zd Zeddee   defd       Zeddee   dee   fd       Zdee   dee   deee   ee   f   fdZ		 ddee   dee   ded	e
d
e
dee   defdZy)DataRobotConfigNapi_keyreturnc                 (    | xs t        d      xs dS )zAttempt to ensure that the API key is set, preferring the user-provided key
        over the secret manager key (``DATAROBOT_API_TOKEN``).

        If both are None, a fake API key is returned for testing.
        DATAROBOT_API_TOKENzfake-api-keyr   )r   s    f/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/llms/datarobot/chat/transformation.py_resolve_api_keyz DataRobotConfig._resolve_api_key   s     Q.)>?Q>Q    api_basec                 r    | xs t        d      } | d} d| vr	d| vr| dz  } | j                  d      s| dz  } | S )aM  Attempt to ensure that the API base is set, preferring the user-provided key
        over the secret manager key (``DATAROBOT_ENDPOINT``).

        If both are None, a default Llamafile server URL is returned.
        See: https://github.com/Mozilla-Ocho/llamafile/blob/bd1bbe9aabb1ee12dbdcafa8936db443c571eb9d/README.md#L61
        DATAROBOT_ENDPOINTzhttps://app.datarobot.comzapi/v2/deploymentsz#api/v2/genai/llmgw/chat/completionsz$/api/v2/genai/llmgw/chat/completions/)r   endswith)r   s    r   _resolve_api_basez!DataRobotConfig._resolve_api_base   sZ     C~.BC2H  x/4HDBB   %OHr   c                 ^    t         j                  |      }t         j                  |      }||fS )a4  Attempts to ensure that the API base and key are set, preferring user-provided values,
        before falling back to secret manager values (``DATAROBOT_ENDPOINT`` and ``DATAROBOT_API_TOKEN``
        respectively).

        If an API key cannot be resolved via either method, a fake key is returned.
        )r
   r   r   )selfr   r   dynamic_api_keys       r   $_get_openai_compatible_provider_infoz4DataRobotConfig._get_openai_compatible_provider_info/   s/     #44X>)::7C((r   modeloptional_paramslitellm_paramsstreamc                     t        |      S )a	  
        Get the complete URL for the API call. Datarobot's API base is set to
        the complete value, so it does not need to be updated to additionally add
        chat completions.

        Returns:
            str: The complete URL for the API call.
        )str)r   r   r   r   r   r   r   s          r   get_complete_urlz DataRobotConfig.get_complete_url?   s    " 8}r   )N)__name__
__module____qualname__staticmethodr   r!   r   r   r   r   dictboolr"    r   r   r
   r
      s    R(3- R3 R R HSM Xc]  0)3-) #) 
x}hsm+	,	). "&3- # 	
    
r   r
   N)	__doc__typingr   r   litellm.secret_managers.mainr   openai_like.chat.transformationr   r
   r)   r   r   <module>r.      s$    # 7 CD* Dr   