
    g"                         d dl mZmZmZmZ d dlZd dlmZ d dlmZ 	 	 ddgZ	de
de
d	eed
   e
f   ded   fdZ	 	 dde
de
dededee   dee   deeef   fdZde
de
dededeeef   f
dZy)    )LiteralOptionalTupleUnionN)verbose_logger)_is_above_128kzgemini-1.0-proz
gemini-promodelcustom_llm_provider	call_type)	embedding
aembeddingreturn)cost_per_charactercost_per_tokenc                 X    |dk(  rd| v sd| v sd| v sd| v sd| v ry|dk(  r|dk(  s|d	k(  ryy
)z
    Route the cost calc to the right place, based on model/call_type/etc.

    Returns
        - str, the specific google cost calc function it should route to.
    	vertex_aiclaudellamamistraljamba	codestralr   r   r   r    )r	   r
   r   s      [/var/www/openai/venv/lib/python3.12/site-packages/litellm/llms/vertex_ai/cost_calculator.pycost_routerr      sT     k)Eee%		+[ I$=    prompt_tokenscompletion_tokensprompt_characterscompletion_charactersc                    t        j                  | |      }t        j                  | |      }|t        | |||      \  }}nj	 t        |dz        r2| t        vr*d|v r|d   	 J dj                  | |             ||d   z  }n(d|v r|d   J d	j                  | |             ||d   z  }|t        | |||      \  }}
||
fS 	 t        |dz        r2| t        vr*d|v r|d   	 J dj                  | |             ||d   z  }
n(d|v r|d   J dj                  | |             ||d   z  }
||
fS # t        $ rI}	t        j                  d
j                  t        |	                   t        | |||      \  }}Y d}	~	d}	~	ww xY w# t        $ rL}	t        j                  d
j                  t        |	                   t        | |||      \  }}
Y d}	~	||
fS d}	~	ww xY w)a#  
    Calculates the cost per character for a given VertexAI model, input messages, and response object.

    Input:
        - model: str, the model name without provider prefix
        - custom_llm_provider: str, "vertex_ai-*"
        - prompt_characters: float, the number of input characters
        - completion_characters: float, the number of output characters

    Returns:
        Tuple[float, float] - prompt_cost_in_usd, completion_cost_in_usd

    Raises:
        Exception if model requires >128k pricing, but model cost not mapped
    r	   r
   N)r	   r
   r   r      tokens*input_cost_per_character_above_128k_tokenszzmodel info for model={} does not have 'input_cost_per_character_above_128k_tokens'-pricing for > 128k tokens
model_info={}input_cost_per_characterzVmodel info for model={} does not have 'input_cost_per_character'-pricing
model_info={}zslitellm.litellm_core_utils.llm_cost_calc.google.py::cost_per_character(): Exception occured - {}
Defaulting to None+output_cost_per_character_above_128k_tokenszimodel info for model={} does not have 'output_cost_per_character_above_128k_tokens' pricing
model_info={}output_cost_per_characterzWmodel info for model={} does not have 'output_cost_per_character'-pricing
model_info={})
litellmget_model_infor   r   models_without_dynamic_pricingformat	Exceptionr   debugstr)r	   r
   r   r   r   r   
model_infoprompt_cost_ecompletion_costs              r   r   r   4   s   . '')<J
 '')<J
  ' 3'/	
Q$	&7!&;<!?? AJN"#OP  Q  X  X:	  & !MNO  /*<"#=>J mss:K
 0*=W2XX $+ 3'/	
?\ ''O%	&;a&?@!?? BZO"#PQ  @  G  G:	  & !NOP   0:="#>?K ntt:L *J7R,SS    ''{  	   G  N  NF
 ,$7+"3	NK	`  	   G  N  NF
 "0$7+"3	"A ''	s2   A)D4 A)F	 4	F=?FF		G?GGc                 R   t        j                  | |      }t        |      r1| t        vr)d|v r|d   J dj	                  | |             ||d   z  }n||d   z  }t        |      r4| t        vr,d|v r|d   J dj	                  | |             ||d   z  }||fS ||d   z  }||fS )a  
    Calculates the cost per token for a given model, prompt tokens, and completion tokens.

    Input:
        - model: str, the model name without provider prefix
        - custom_llm_provider: str, either "vertex_ai-*" or "gemini"
        - prompt_tokens: float, the number of input tokens
        - completion_tokens: float, the number of output tokens

    Returns:
        Tuple[float, float] - prompt_cost_in_usd, completion_cost_in_usd

    Raises:
        Exception if model requires >128k pricing, but model cost not mapped
    r!   r#   &input_cost_per_token_above_128k_tokenszMmodel info for model={} does not have pricing for > 128k tokens
model_info={}input_cost_per_token'output_cost_per_token_above_128k_tokensoutput_cost_per_token)r)   r*   r   r+   r,   )r	   r
   r   r   r0   r1   r4   s          r   r   r      s   , '')<J 	m,77 5
BCDP	
 \bb:
	
Q J'OPP 	 $j1G&HH 	/077 6CDEQ	
 \bb:
	
R 
+T UU 	 '' ,j9P.QQ''r   )NN)typingr   r   r   r   r)   r   .litellm.litellm_core_utils.llm_cost_calc.utilsr   r+   r/   r   floatr   r   r   r   r   <module>r=      s   3 2  " I #3L!A     W67<=  34	 > *.-1((( ( 	(
  ( $E?( 5%<(D<(<(<( <( 	<(
 5%<<(r   