mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-26 06:03:19 +00:00
Merge a6f9e51881 into d29200fa05
This commit is contained in:
commit
350156287d
2 changed files with 44 additions and 1 deletions
|
|
@ -6356,7 +6356,7 @@ def get_model_info_helper(
|
|||
e,
|
||||
)
|
||||
|
||||
if custom_llm_provider == "huggingface":
|
||||
if custom_llm_provider == "huggingface" and get_model_cost_key(model) is None:
|
||||
max_tokens: Final = _get_max_position_embeddings(model_name=model)
|
||||
return ModelInfoBase(
|
||||
key=model,
|
||||
|
|
|
|||
|
|
@ -1492,6 +1492,49 @@ def test_tiered_pricing_only_deployment_completion_cost_is_nonzero():
|
|||
assert cost > 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("registered_model", "model"),
|
||||
[
|
||||
("hf-tei-rerank-deployment", "hf-tei-rerank-deployment"),
|
||||
("huggingface/hf-tei-rerank-deployment", "huggingface/hf-tei-rerank-deployment"),
|
||||
("hf-tei-rerank-deployment", "HF-TEI-RERANK-DEPLOYMENT"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("local_model_cost_map")
|
||||
def test_huggingface_rerank_uses_registered_input_cost_per_query(
|
||||
registered_model: str, model: str, request: pytest.FixtureRequest
|
||||
):
|
||||
"""Registered per-query price must apply for huggingface/TEI rerank (#45975).
|
||||
|
||||
``_get_model_info_helper`` used to return a synthetic zero-cost huggingface
|
||||
description before consulting ``litellm.model_cost``, so a deployment priced
|
||||
only via ``input_cost_per_query`` always billed $0 under that provider.
|
||||
"""
|
||||
from litellm.cost_calculator import rerank_cost
|
||||
from litellm.utils import cached_get_model_info_helper
|
||||
|
||||
cached_get_model_info_helper.cache_clear()
|
||||
request.addfinalizer(cached_get_model_info_helper.cache_clear)
|
||||
litellm.model_cost.pop(registered_model, None)
|
||||
litellm.register_model({registered_model: {"input_cost_per_query": 0.001}})
|
||||
|
||||
cost = rerank_cost(
|
||||
model=model,
|
||||
custom_llm_provider="huggingface",
|
||||
billed_units={"search_units": 1},
|
||||
)
|
||||
assert cost == (0.001, 0.0)
|
||||
|
||||
# Unregistered huggingface models still get the synthetic zero-cost fallback.
|
||||
cached_get_model_info_helper.cache_clear()
|
||||
info = litellm.get_model_info(
|
||||
model="unregistered-hf-tei-model-xyz",
|
||||
custom_llm_provider="huggingface",
|
||||
)
|
||||
assert info["input_cost_per_token"] == 0
|
||||
assert info["output_cost_per_token"] == 0
|
||||
|
||||
|
||||
def test_per_query_priced_rerank_deployment_completion_cost_is_nonzero():
|
||||
"""A rerank deployment priced only via ``input_cost_per_query`` must resolve
|
||||
cost against its ``router_model_id`` entry: the shared backend alias has
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue