mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
fix(batches): skip undecodable batch output lines when costing
This commit is contained in:
parent
51cafe4365
commit
5eeccf69b6
2 changed files with 6 additions and 1 deletions
|
|
@ -426,7 +426,7 @@ def _iter_batch_output_entries(file_content: bytes) -> Iterator[dict]:
|
|||
def _parse_batch_output_line(line: bytes) -> dict | None:
|
||||
try:
|
||||
parsed: Final = json.loads(line)
|
||||
except json.JSONDecodeError as e:
|
||||
except ValueError as e:
|
||||
verbose_logger.warning("skipping malformed batch output line: %s", str(e))
|
||||
return None
|
||||
if isinstance(parsed, dict):
|
||||
|
|
|
|||
|
|
@ -186,6 +186,11 @@ def test_iter_output_entries_skips_malformed_and_non_object_lines():
|
|||
assert list(bu._iter_batch_output_entries(content)) == [{"ok": 1}, {"ok": 2}]
|
||||
|
||||
|
||||
def test_iter_output_entries_skips_undecodable_line():
|
||||
content = b'{"ok": 1}\n{"note": "\xff-bad"}\n{"ok": 2}\n'
|
||||
assert list(bu._iter_batch_output_entries(content)) == [{"ok": 1}, {"ok": 2}]
|
||||
|
||||
|
||||
# =========================================================================== #
|
||||
# _estimate_batch_entry_tokens (regression: an uncountable/malformed row must
|
||||
# never contribute zero tokens, or a crafted batch could evade the TPM limit)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue