mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
Merge 964c4a0884 into 6fa0477d84
This commit is contained in:
commit
94dd0c58c8
3 changed files with 51 additions and 7 deletions
|
|
@ -358,9 +358,7 @@ PLANS: Final[Mapping[str, Plan]] = MappingProxyType(
|
|||
sync=True,
|
||||
splits_stream_timeout=True,
|
||||
stamp="deployment",
|
||||
total_key=None,
|
||||
success_key=None,
|
||||
fail_key=None,
|
||||
# The sync path updates the same deployment counters as ``acompletion``.
|
||||
named=("messages",),
|
||||
),
|
||||
"atext_completion": Plan(
|
||||
|
|
|
|||
|
|
@ -424,8 +424,17 @@ async def test_acompletion_counts_total_success_and_failed_calls_per_deployment_
|
|||
assert counts == (2, 1, 1)
|
||||
|
||||
|
||||
def test_sync_completion_does_not_count_calls(make_core: MakeCore, host: ScriptedHost) -> None:
|
||||
"""Oddity: only the async path updates ``total_calls``/``success_calls``/``fail_calls``."""
|
||||
core: Final = make_core(model_list=[deployment("g", "d1")])
|
||||
def test_sync_completion_counts_total_success_and_failed_calls_per_deployment_model(
|
||||
make_core: MakeCore, host: ScriptedHost
|
||||
) -> None:
|
||||
core: Final = make_core(model_list=[deployment("g", "d1")], num_retries=0)
|
||||
core.completion(model="g", messages=MESSAGES) # pyright: ignore[reportAttributeAccessIssue]
|
||||
assert core.total_calls["openai/d1"] == 0 # pyright: ignore[reportAttributeAccessIssue]
|
||||
host.answer("openai/d1", rate_limit())
|
||||
with pytest.raises(litellm.RateLimitError):
|
||||
core.completion(model="g", messages=MESSAGES) # pyright: ignore[reportAttributeAccessIssue]
|
||||
counts: Final = (
|
||||
core.total_calls["openai/d1"], # pyright: ignore[reportAttributeAccessIssue]
|
||||
core.success_calls["openai/d1"], # pyright: ignore[reportAttributeAccessIssue]
|
||||
core.fail_calls["openai/d1"], # pyright: ignore[reportAttributeAccessIssue]
|
||||
)
|
||||
assert counts == (2, 1, 1)
|
||||
|
|
|
|||
|
|
@ -19900,3 +19900,40 @@ def test_router_warns_when_a_deployment_enforces_endpoints_without_a_list(caplog
|
|||
|
||||
assert "Deployment 'embed-from-config' sets enforce_supported_endpoints without" in caplog.text
|
||||
assert "Deployment 'embed-from-api' sets enforce_supported_endpoints without" in caplog.text
|
||||
|
||||
|
||||
def test_sync_completion_tracks_router_metrics():
|
||||
"""
|
||||
Regression: sync router.completion() must update router.total_calls /
|
||||
router.success_calls / router.fail_calls, same as router.acompletion() does.
|
||||
"""
|
||||
router = Router(
|
||||
model_list=[
|
||||
{
|
||||
"model_name": "gpt-4o",
|
||||
"litellm_params": {"model": "openai/gpt-4o", "num_retries": 0},
|
||||
}
|
||||
],
|
||||
num_retries=0,
|
||||
)
|
||||
|
||||
## success: total/success track the deployment model
|
||||
router.completion(
|
||||
model="gpt-4o",
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
mock_response="Hello",
|
||||
)
|
||||
assert router.total_calls["openai/gpt-4o"] == 1
|
||||
assert router.success_calls["openai/gpt-4o"] == 1
|
||||
assert router.fail_calls.get("openai/gpt-4o", 0) == 0
|
||||
|
||||
## failure: fail tracks the deployment model
|
||||
with pytest.raises(Exception):
|
||||
router.completion(
|
||||
model="gpt-4o",
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
mock_response="litellm.InternalServerError",
|
||||
)
|
||||
assert router.fail_calls["openai/gpt-4o"] == 1
|
||||
assert router.total_calls["openai/gpt-4o"] == 2
|
||||
assert router.success_calls["openai/gpt-4o"] == 1
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue