
    j                         d Z ddlmZ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 dd	lmZ er	dd
lmZ eZneZ G d de      Zy)z,
CompactifAI chat completion transformation
    )TYPE_CHECKINGAnyListOptionalTupleUnionNget_secret_str)ModelResponseOpenAIError)BaseLLMException   )OpenAIGPTConfig)Loggingc                       e Zd ZdZdee   dee   deee   ee   f   fdZ	 	 ddedej                  d	e
d
ededededededee   dee   de
fdZdededeeej&                  f   defdZy)CompactifAIChatConfigz
    Configuration class for CompactifAI chat completions.
    Since CompactifAI is OpenAI-compatible, we extend OpenAIGPTConfig.
    api_baseapi_keyreturnc                 <    |xs d}|xs t        d      xs d}||fS )z@
        Get API base and key for CompactifAI provider.
        zhttps://api.compactif.ai/v1COMPACTIFAI_API_KEY r	   )selfr   r   dynamic_api_keys       /Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/litellm/llms/compactifai/chat/transformation.py$_get_openai_compatible_provider_infoz:CompactifAIChatConfig._get_openai_compatible_provider_info   s/     <<!P^4I%JPb((    Nmodelraw_responsemodel_responselogging_objrequest_datamessagesoptional_paramslitellm_paramsencoding	json_modec                 x   |j                  ||
|j                  d|i       |j                         }|rq|d   D ]i  }|j                  d      }|s|j                  d      s)|j                  dg       }t	        |      dk(  sJ|d   d   j                  d	d
      |d<   d|d<   k t        di |}d| |_        |S )z
        Transform CompactifAI response to LiteLLM format.
        Since CompactifAI is OpenAI-compatible, we can use the standard OpenAI transformation.
        complete_input_dict)inputr   original_responseadditional_argschoicesmessage
tool_calls   r   function	argumentsr   contentNzcompactifai/ )	post_calltextjsongetlenr   r   )r   r   r    r!   r"   r#   r$   r%   r&   r'   r   r(   response_jsonchoicer/   r0   returned_responses                    r   transform_responsez(CompactifAIChatConfig.transform_response*   s    & 	*//2LA	 	 	
 %))+ '	2 **Y/w{{<8!(\2!>J:!+-7]:-F-J-J;XZ-[	*04- 3 *:M: %1"8  r   error_messagestatus_codeheadersc                     t        |||      S )z
        Get the appropriate error class for CompactifAI errors.
        Since CompactifAI is OpenAI-compatible, we use OpenAI error handling.
        )r@   r/   rA   r   )r   r?   r@   rA   s       r   get_error_classz%CompactifAIChatConfig.get_error_classY   s     #!
 	
r   )NN)__name__
__module____qualname____doc__r   strr   r   httpxResponser   LiteLLMLoggingObjdictr   r   boolr>   intr   Headersr   rC   r5   r   r   r   r      s   

)3-
) #
) 
x}hsm+	,	
). "&$(-!-! nn-! &	-!
 '-! -! -! -! -! -! #-! D>-! 
-!^
 
/2
=B4CV=W
	
r   r   )rG   typingr   r   r   r   r   r   rI   litellm.secret_managers.mainr
   litellm.types.utilsr    litellm.llms.openai.common_utilsr   )litellm.llms.base_llm.chat.transformationr   openai.chat.gpt_transformationr   *litellm.litellm_core_utils.litellm_loggingr   _LiteLLMLoggingObjrK   r   r5   r   r   <module>rX      sE    D C  7 - 8 F =X*L
O L
r   