
    h                         d dl mZmZ d dlmZmZmZmZmZm	Z	m
Z
 d dlZd dlmZmZ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)    )ABCabstractmethod)TYPE_CHECKINGAnyDictListOptionalTupleUnionN)OptionalRerankParamsRerankBilledUnitsRerankResponse)	ModelInfo   BaseLLMException)Loggingc                      e Zd Ze	 d$dededee   defd       Zededededefd       Z	edi i i fded	e
j                  d
ededee   dedededefd       Zedee   dedefd       Zededefd       Ze	 	 	 	 	 	 d%dededededeeeeeef   f      dee   dee   deee      dee   dee   dee   defd       Zdededeee
j2                  f   defd Z	 	 	 d&dedee   d!ee   d"ee   deeef   f
d#Z y)'BaseRerankConfigNheadersmodelapi_keyreturnc                      y N )selfr   r   r   s       g/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/llms/base_llm/rerank/transformation.pyvalidate_environmentz%BaseRerankConfig.validate_environment   s     	    optional_rerank_paramsc                     i S r   r   )r   r   r!   r   s       r   transform_rerank_requestz)BaseRerankConfig.transform_rerank_request   s	     	r    raw_responsemodel_responselogging_objrequest_dataoptional_paramslitellm_paramsc	                     |S r   r   )	r   r   r$   r%   r&   r   r'   r(   r)   s	            r   transform_rerank_responsez*BaseRerankConfig.transform_rerank_response&   s
     r    api_basec                     |xs dS )z{
        OPTIONAL

        Get the complete url for the request

        Some providers need `model` in `api_base`
         r   )r   r,   r   s      r   get_complete_urlz!BaseRerankConfig.get_complete_url4   s     ~2r    c                      y r   r   )r   r   s     r   "get_supported_cohere_rerank_paramsz3BaseRerankConfig.get_supported_cohere_rerank_params?   s    r    non_default_paramsdrop_paramsquery	documentscustom_llm_providertop_nrank_fieldsreturn_documentsmax_chunks_per_docmax_tokens_per_docc                      y r   r   )r   r2   r   r3   r4   r5   r6   r7   r8   r9   r:   r;   s               r   map_cohere_rerank_paramsz)BaseRerankConfig.map_cohere_rerank_paramsC   s     	r    error_messagestatus_codec                     t        |||      )N)r?   messager   r   )r   r>   r?   r   s       r   get_error_classz BaseRerankConfig.get_error_classT   s     #!
 	
r    billed_units
model_infoc                 ^    |d|vs|d   |y|j                  d      }|y|d   |z  }|dfS )a%  
        Calculates the cost per query for a given rerank model.

        Input:
            - model: str, the model name without provider prefix
            - custom_llm_provider: str, the provider used for the model. If provided, used to check if the litellm model info is for that provider.
            - num_queries: int, the number of queries to calculate the cost for
            - model_info: ModelInfo, the model info for the given model

        Returns:
            Tuple[float, float] - prompt_cost_in_usd, completion_cost_in_usd
        input_cost_per_query)        rG   search_unitsrG   )get)r   r   r6   rC   rD   rH   prompt_costs          r   calculate_rerank_costz&BaseRerankConfig.calculate_rerank_cost]   s[    * %Z7019##''7 !78<GCr    r   )NNNTNN)NNN)!__name__
__module____qualname__r   dictstrr	   r   r   r#   httpxResponser   LiteLLMLoggingObjr+   r/   listr1   boolr   r   r   r   intr=   Headersr   rB   r   r   r
   floatrK   r   r    r   r   r      s   
 "&	  #	
 
   !5 	
 
   "& "! nn '	
 ' #    
  # s s        .2#+/+/,0,0   	
  c4S>123 &c] } d3i( #4. %SM %SM 
  
 
/2
=B4CV=W
	
 .248*.# #  &c]#  01	# 
 Y'#  
ue|	# r    r   )abcr   r   typingr   r   r   r   r	   r
   r   rQ   litellm.types.rerankr   r   r   litellm.types.utilsr   chat.transformationr   *litellm.litellm_core_utils.litellm_loggingr   _LiteLLMLoggingObjrS   r   r   r    r   <module>r`      s@    # I I I  X X ) 2X*m s m r    