o
    ưi                     @   s   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 deZdS )z,
CompactifAI chat completion transformation
    )TYPE_CHECKINGAnyListOptionalTupleUnionNget_secret_str)ModelResponseOpenAIError)BaseLLMException   )OpenAIGPTConfig)Loggingc                   @   s   e Zd ZdZdee dee deee ee f fd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dZdededeeejf defddZdS )CompactifAIChatConfigz
    Configuration class for CompactifAI chat completions.
    Since CompactifAI is OpenAI-compatible, we extend OpenAIGPTConfig.
    api_baseapi_keyreturnc                 C   s    |pd}|pt dpd}||fS )z@
        Get API base and key for CompactifAI provider.
        zhttps://api.compactif.ai/v1ZCOMPACTIFAI_API_KEY r   )selfr   r   Zdynamic_api_key r   c/home/app/Keep/.python/lib/python3.10/site-packages/litellm/llms/compactifai/chat/transformation.py$_get_openai_compatible_provider_info   s   z:CompactifAIChatConfig._get_openai_compatible_provider_infoNmodelraw_responsemodel_responselogging_objrequest_datamessagesoptional_paramslitellm_paramsencoding	json_modec                 C   s   |j ||
|jd|id | }|rA|d D ]*}|d}|r@|dr@|dg }t|dkr@|d d d	d
|d< d|d< qtdi |}d| |_|S )z
        Transform CompactifAI response to LiteLLM format.
        Since CompactifAI is OpenAI-compatible, we can use the standard OpenAI transformation.
        Zcomplete_input_dict)inputr   original_responseZadditional_argschoicesmessage
tool_calls   r   function	argumentsr   contentNzcompactifai/r   )Z	post_calltextjsongetlenr
   r   )r   r   r   r   r   r   r   r    r!   r"   r   r#   Zresponse_jsonchoicer'   r(   Zreturned_responser   r   r   transform_response*   s&   
z(CompactifAIChatConfig.transform_responseerror_messagestatus_codeheadersc                 C   s   t |||dS )z
        Get the appropriate error class for CompactifAI errors.
        Since CompactifAI is OpenAI-compatible, we use OpenAI error handling.
        )r4   r'   r5   r   )r   r3   r4   r5   r   r   r   get_error_classY   s
   z%CompactifAIChatConfig.get_error_class)NN)__name__
__module____qualname____doc__r   strr   r   httpxResponser
   LiteLLMLoggingObjdictr   r   boolr2   intr   ZHeadersr   r6   r   r   r   r   r      sZ    
	

/r   )r:   typingr   r   r   r   r   r   r<   Zlitellm.secret_managers.mainr	   Zlitellm.types.utilsr
   Z litellm.llms.openai.common_utilsr   Z)litellm.llms.base_llm.chat.transformationr   Zopenai.chat.gpt_transformationr   Z*litellm.litellm_core_utils.litellm_loggingr   Z_LiteLLMLoggingObjr>   r   r   r   r   r   <module>   s     