(fix) prompt caching cost calculation OpenAI, Azure OpenAI (#6231)

* fix prompt caching cost calculation

* fix testing for prompt cache cost calc
This commit is contained in:
Ishaan Jaff 2024-10-15 18:55:31 +05:30 committed by GitHub
parent 700a87204a
commit c25733e28e
3 changed files with 13 additions and 7 deletions

View file

@ -27,7 +27,8 @@ def cost_per_token(
model_info = get_model_info(model=model, custom_llm_provider="openai")
## CALCULATE INPUT COST
prompt_cost: float = usage["prompt_tokens"] * model_info["input_cost_per_token"]
total_prompt_tokens: float = usage["prompt_tokens"] - usage._cache_read_input_tokens
prompt_cost: float = total_prompt_tokens * model_info["input_cost_per_token"]
## CALCULATE OUTPUT COST
completion_cost: float = (