mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-05 02:41:56 +00:00
fix(transcription): reject nonfinite provider durations
This commit is contained in:
parent
9e1d36489e
commit
6a3c36fcc3
2 changed files with 10 additions and 3 deletions
|
|
@ -1038,9 +1038,7 @@ def _get_transcription_usage_duration(completion_response: object) -> float | No
|
|||
seconds: Final = (
|
||||
usage_object.get("seconds") if isinstance(usage_object, dict) else getattr(usage_object, "seconds", None)
|
||||
)
|
||||
if isinstance(seconds, bool) or not isinstance(seconds, (int, float)) or seconds < 0:
|
||||
return None
|
||||
return float(seconds)
|
||||
return normalized_audio_duration_seconds(seconds)
|
||||
|
||||
|
||||
def _is_known_usage_objects(usage_obj):
|
||||
|
|
|
|||
|
|
@ -334,6 +334,15 @@ def test_transcription_usage_cost_returns_zero_for_unknown_type():
|
|||
assert _transcription_usage_cost({}, {}) == 0.0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("malformed_seconds", [-1.0, float("nan"), float("inf"), 10**1000, True])
|
||||
def test_transcription_ignores_invalid_provider_duration(malformed_seconds: float | int | bool) -> None:
|
||||
from litellm.cost_calculator import _get_transcription_usage_duration
|
||||
|
||||
response: Final = SimpleNamespace(usage={"type": "duration", "seconds": malformed_seconds})
|
||||
|
||||
assert _get_transcription_usage_duration(response) is None
|
||||
|
||||
|
||||
def test_get_transcription_model_falls_back_to_session_model(monkeypatch):
|
||||
"""session.model is used when transcription-specific model fields are absent."""
|
||||
monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue