mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
fixes for cost calc
This commit is contained in:
parent
233d1d5303
commit
6d25b8e32b
1 changed files with 21 additions and 21 deletions
|
@ -1111,27 +1111,27 @@ def default_image_cost_calculator(
|
||||||
f"Looking up cost for models: {model_name_with_quality}, {base_model_name}"
|
f"Looking up cost for models: {model_name_with_quality}, {base_model_name}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Try model with quality first, fall back to base model name
|
|
||||||
if model_name_with_quality in litellm.model_cost:
|
|
||||||
cost_info = litellm.model_cost[model_name_with_quality]
|
|
||||||
elif base_model_name in litellm.model_cost:
|
|
||||||
cost_info = litellm.model_cost[base_model_name]
|
|
||||||
elif model_name_with_v2_quality in litellm.model_cost:
|
|
||||||
cost_info = litellm.model_cost[model_name_with_v2_quality]
|
|
||||||
else:
|
|
||||||
# Try without provider prefix
|
|
||||||
model_without_provider = f"{size_str}/{model.split('/')[-1]}"
|
model_without_provider = f"{size_str}/{model.split('/')[-1]}"
|
||||||
model_with_quality_without_provider = (
|
model_with_quality_without_provider = (
|
||||||
f"{quality}/{model_without_provider}" if quality else model_without_provider
|
f"{quality}/{model_without_provider}" if quality else model_without_provider
|
||||||
)
|
)
|
||||||
|
|
||||||
if model_with_quality_without_provider in litellm.model_cost:
|
# Try model with quality first, fall back to base model name
|
||||||
cost_info = litellm.model_cost[model_with_quality_without_provider]
|
cost_info: Optional[dict] = None
|
||||||
elif model_without_provider in litellm.model_cost:
|
models_to_check = [
|
||||||
cost_info = litellm.model_cost[model_without_provider]
|
model_name_with_quality,
|
||||||
else:
|
base_model_name,
|
||||||
|
model_name_with_v2_quality,
|
||||||
|
model_with_quality_without_provider,
|
||||||
|
model_without_provider,
|
||||||
|
]
|
||||||
|
for model in models_to_check:
|
||||||
|
if model in litellm.model_cost:
|
||||||
|
cost_info = litellm.model_cost[model]
|
||||||
|
break
|
||||||
|
if cost_info is None:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"Model not found in cost map. Tried {model_name_with_quality}, {base_model_name}, {model_with_quality_without_provider}, and {model_without_provider}"
|
f"Model not found in cost map. Tried checking {models_to_check}"
|
||||||
)
|
)
|
||||||
|
|
||||||
return cost_info["input_cost_per_pixel"] * height * width * n
|
return cost_info["input_cost_per_pixel"] * height * width * n
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue