mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix(soniox): keep bracket-prefixed free-form context and move types under llms
Free-form context such as "[inaudible] consultation" is valid Soniox input, so a string that fails JSON parsing is now forwarded unchanged instead of returning a 400. The Soniox request types live next to the provider code.
This commit is contained in:
parent
fe6d6d9b7e
commit
cf33d3f47c
3 changed files with 5 additions and 9 deletions
|
|
@ -81,10 +81,8 @@ def _decode_form_value(key: str, value: object) -> object:
|
|||
if key in SONIOX_JSON_PARAMS and value.lstrip()[:1] in ("{", "["):
|
||||
try:
|
||||
return _JSON_CONTAINER.validate_json(value)
|
||||
except ValidationError as exc:
|
||||
raise SonioxException(
|
||||
message=f"`{key}` is not valid JSON: {exc.errors()[0]['msg']}", status_code=400, headers=None
|
||||
)
|
||||
except ValidationError:
|
||||
return value
|
||||
if key == "language_hints":
|
||||
return tuple(hint.strip() for hint in value.split(",") if hint.strip())
|
||||
return value
|
||||
|
|
|
|||
|
|
@ -707,11 +707,9 @@ class TestDecodeSonioxFormParams:
|
|||
assert result["enable_speaker_diarization"] is True
|
||||
assert result["language_hints"] == ["en", "es"]
|
||||
|
||||
def test_should_raise_400_on_malformed_json_context(self):
|
||||
with pytest.raises(SonioxException) as exc_info:
|
||||
decode_soniox_form_params({"context": '{"terms": ["Celebrex"'})
|
||||
assert exc_info.value.status_code == 400
|
||||
assert "context" in str(exc_info.value)
|
||||
@pytest.mark.parametrize("raw", ["[inaudible] consultation", "{unbalanced", '{"terms": ["Celebrex"'])
|
||||
def test_should_keep_bracket_prefixed_free_form_context_as_string(self, raw: str):
|
||||
assert decode_soniox_form_params({"context": raw})["context"] == raw
|
||||
|
||||
def test_should_decode_json_string_translation(self):
|
||||
result = decode_soniox_form_params({"translation": '{"type": "one_way", "target_language": "es"}'})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue