v2.16.0 (#798)
Co-authored-by: Hdandria <henri.dandria@mistral.ai> Co-authored-by: Liam Lyons <65613603+lyons-liam@users.noreply.github.com> Co-authored-by: Mathias Gesbert <mathias.gesbert@mistral.ai> Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai> Co-authored-by: Quentin <quentin.torroba@mistral.ai> Co-authored-by: allansimon-mistral <allan.simon@ext.mistral.ai> Co-authored-by: angelapopopo <angele.lenglemetz@mistral.ai> Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
cafb6d4147
commit
c2cb612ac1
67 changed files with 2704 additions and 197 deletions
|
|
@ -17,7 +17,10 @@ def _make_payload_summary() -> PayloadSummary:
|
|||
|
||||
|
||||
def _make_error(
|
||||
*, status: int | None, headers: dict[str, str] | None = None
|
||||
*,
|
||||
status: int | None,
|
||||
headers: dict[str, str] | None = None,
|
||||
body_text: str = "body",
|
||||
) -> BackendError:
|
||||
return BackendError(
|
||||
provider="test-provider",
|
||||
|
|
@ -25,7 +28,7 @@ def _make_error(
|
|||
status=status,
|
||||
reason="some reason",
|
||||
headers=headers or {},
|
||||
body_text="body",
|
||||
body_text=body_text,
|
||||
parsed_error=None,
|
||||
model="test-model",
|
||||
payload_summary=_make_payload_summary(),
|
||||
|
|
@ -72,3 +75,49 @@ class TestBackendErrorFmt:
|
|||
msg = str(err)
|
||||
assert str(code) in msg
|
||||
assert "LLM backend error" in msg
|
||||
|
||||
|
||||
class TestBackendErrorIsContextTooLong:
|
||||
@pytest.mark.parametrize(
|
||||
("status", "body_text"),
|
||||
[
|
||||
(400, "context too long"),
|
||||
(400, "prompt is too long"),
|
||||
# orchestral_runtime wraps context errors as 422
|
||||
(422, '{"error":{"type":"model_context_exceeded"}}'),
|
||||
(422, '{"error":{"type":"prompt_too_long"}}'),
|
||||
],
|
||||
)
|
||||
def test_true(self, status: int, body_text: str) -> None:
|
||||
err = _make_error(status=status, body_text=body_text)
|
||||
assert err.is_context_too_long
|
||||
|
||||
def test_false_on_unrelated_status(self) -> None:
|
||||
err = _make_error(status=500, body_text="context too long")
|
||||
assert not err.is_context_too_long
|
||||
|
||||
def test_false_on_max_tokens(self) -> None:
|
||||
# max-tokens truncation must not be misread as context-too-long
|
||||
err = _make_error(status=422, body_text="max_tokens_exceeded")
|
||||
assert not err.is_context_too_long
|
||||
|
||||
|
||||
class TestBackendErrorIsResponseTooLong:
|
||||
@pytest.mark.parametrize(
|
||||
"body_text",
|
||||
[
|
||||
'{"error":{"type":"max_tokens_exceeded"}}',
|
||||
"Generation truncated: finish_reason=length",
|
||||
],
|
||||
)
|
||||
def test_true_on_422_with_substring(self, body_text: str) -> None:
|
||||
err = _make_error(status=422, body_text=body_text)
|
||||
assert err.is_response_too_long
|
||||
|
||||
def test_false_when_status_not_422(self) -> None:
|
||||
err = _make_error(status=400, body_text="max_tokens_exceeded")
|
||||
assert not err.is_response_too_long
|
||||
|
||||
def test_false_when_substring_missing(self) -> None:
|
||||
err = _make_error(status=422, body_text="some unrelated error")
|
||||
assert not err.is_response_too_long
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue