mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
guard against non-dict entries in words array
This commit is contained in:
parent
a85061d45d
commit
fd40828950
2 changed files with 6 additions and 0 deletions
|
|
@ -130,6 +130,8 @@ class ElevenLabsAudioTranscriptionConfig(BaseAudioTranscriptionConfig):
|
|||
if "words" in response_json:
|
||||
response["words"] = []
|
||||
for word_data in response_json["words"]:
|
||||
if not isinstance(word_data, dict):
|
||||
continue
|
||||
# Only include actual words, skip spacing and audio events
|
||||
if word_data.get("type") == "word":
|
||||
response["words"].append(
|
||||
|
|
@ -146,6 +148,8 @@ class ElevenLabsAudioTranscriptionConfig(BaseAudioTranscriptionConfig):
|
|||
# instead of 0.
|
||||
duration = 0.0
|
||||
for word_data in response_json.get("words") or []:
|
||||
if not isinstance(word_data, dict):
|
||||
continue
|
||||
try:
|
||||
duration = max(duration, float(word_data.get("end") or 0.0))
|
||||
except (TypeError, ValueError):
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@ class TestElevenLabsTransformResponse:
|
|||
"words": [
|
||||
{"type": "word", "text": "hello", "start": 0.0, "end": None},
|
||||
{"type": "word", "text": "x", "start": 0.0, "end": "bad"},
|
||||
None,
|
||||
"not-a-dict",
|
||||
{"type": "word", "text": "y", "start": 0.0, "end": 2.5},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue