
    i"                         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 dd	lmZ er	d d
lmZ eZneZ G d de      Zy)    )TYPE_CHECKINGAnyListOptionalTupleUnionNget_secret_str)ModelResponse)AllMessageValuesOpenAIError)BaseLLMException   )OpenAIGPTConfig)Loggingc                   z    e Zd ZdZdedefdZeddee   dee   fd       Z	eddee   de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 fdZ	 	 ddedej                   dededede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j6                  f   defdZ xZS )ClarifaiConfigz
    Configuration class for Clarifai chat completions.
    Since Clarifai is OpenAI-compatible, we extend OpenAIGPTConfig.
    modelreturnc                 
    g dS )zE
        Get the supported OpenAI params for the given model
        )
max_tokensmax_completion_tokensresponse_formatstreamtemperaturetop_ptool_choicetoolspresence_penaltyfrequency_penaltystream_options )selfr   s     z/Users/manta/Documents/Projects/TheRoad-I1/.venv/lib/python3.12/site-packages/litellm/llms/clarifai/chat/transformation.pyget_supported_openai_paramsz*ClarifaiConfig.get_supported_openai_params   s    
 	
    api_keyc                      | xs t        d      S )NCLARIFAI_API_KEYr	   )r(   s    r%   get_api_keyzClarifaiConfig.get_api_key/   s    <.);<<r'   api_basec                     | xs dS )N)https://api.clarifai.com/v2/ext/openai/v1r#   )r,   s    r%   get_api_basezClarifaiConfig.get_api_base3   s    FFFr'   c                 H    | r | j                  d      \  }}}d| d| d| S y )N.zhttps://clarifai.com//z/models/)split)r   user_idapp_idmodel_ids       r%   get_base_modelzClarifaiConfig.get_base_model7   s6    (-C(8%GVX*7)1VHHXJOOr'   c                 <    |xs d}|xs t        d      xs d}||fS )z=
        Get API base and key for Clarifai provider.
        r.   r*    r	   )r$   r,   r(   dynamic_api_keys       r%   $_get_openai_compatible_provider_infoz3ClarifaiConfig._get_openai_compatible_provider_info>   s/     JJ!M^4F%GM2((r'   c                 T    | j                  |      xs |}t        | 	  |||||      S N)r7   supertransform_request)r$   r   messagesoptional_paramslitellm_paramsheaders	__class__s         r%   r?   z ClarifaiConfig.transform_requestJ   s7     ##E*3ew(8_ng
 	
r'   raw_responsemodel_responselogging_objrequest_datar@   rA   rB   encoding	json_modec                 ,   |j                  ||
|j                  d|i       	 |j                         }t        di |}|j                  
d|z   |_	        |S # t        $ r4}t	        |j
                  dt        |       |j                        |d}~ww xY w)z
        Transform the Clarifai response to a standard ModelResponse.
        Since Clarifai is OpenAI-compatible, we use OpenAI response transformation.
        complete_input_dict)inputr(   original_responseadditional_argsz#Failed to parse Clarifai response: status_codemessagerC   Nz	clarifai/r#   )
	post_calltextjson	Exceptionr   rQ   strrC   r   r   )r$   r   rE   rF   rG   rH   r@   rA   rB   rI   r(   rJ   completion_responseeresponses                  r%   transform_responsez!ClarifaiConfig.transform_responseR   s    & 	*//2LA	 	 	
	"."3"3"5 !7#67>>%(50HN  	(44=c!fXF$,, 		s   A 	B/BBerror_messagerQ   rC   c                     t        |||      S )z
        Get the appropriate error class for Clarifai errors.
        Since Clarifai is OpenAI-compatible, we use OpenAI error handling.
        rP   r   )r$   r\   rQ   rC   s       r%   get_error_classzClarifaiConfig.get_error_class|   s     #!
 	
r'   r=   )NN)__name__
__module____qualname____doc__rW   listr&   staticmethodr   r+   r/   r7   r   r;   r?   httpxResponser   LiteLLMLoggingObjdictr   r   r   boolr[   intr   Headersr   r^   __classcell__)rD   s   @r%   r   r      s   

 
 
$ =Xc] =hsm = = Gx} G G G hsm x}  
)3-
) #
) 
x}hsm+	,	
)
& "&$((( nn( &	(
 '( ( '(( ( ( ( #( D>( 
(T
 
/2
=B4CV=W
	
r'   r   )typingr   r   r   r   r   r   re   litellm.secret_managers.mainr
   litellm.types.utilsr   litellm.types.llms.openair    litellm.llms.openai.common_utilsr   )litellm.llms.base_llm.chat.transformationr   openai.chat.gpt_transformationr   *litellm.litellm_core_utils.litellm_loggingr   _LiteLLMLoggingObjrg   r   r#   r'   r%   <module>rv      sD    C C  7 - 9 F =X*p
_ p
r'   