mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-04 00:18:36 +00:00
fix(providers): keep serde errors explicit
This commit is contained in:
parent
6eda67b50c
commit
44b7e1bf41
@ -1082,16 +1082,6 @@ class OpenAICompatProvider(LLMProvider):
|
|||||||
"not supported",
|
"not supported",
|
||||||
"unknown parameter",
|
"unknown parameter",
|
||||||
"unrecognized request argument",
|
"unrecognized request argument",
|
||||||
# Serde-style body rejection: the endpoint could not parse the
|
|
||||||
# Responses wire format (e.g. DeepSeek's Responses gateway
|
|
||||||
# rejecting an input item shape with "Failed to deserialize the
|
|
||||||
# JSON body ... expected a sequence"). These are compatibility
|
|
||||||
# failures: fall back to Chat Completions for the same model.
|
|
||||||
"failed to deserialize",
|
|
||||||
"invalid type",
|
|
||||||
"expected a sequence",
|
|
||||||
"expected a struct",
|
|
||||||
"unknown field",
|
|
||||||
)
|
)
|
||||||
return any(marker in body_text for marker in compatibility_markers)
|
return any(marker in body_text for marker in compatibility_markers)
|
||||||
|
|
||||||
|
|||||||
@ -166,8 +166,9 @@ class _FakeAPIError(Exception):
|
|||||||
self.response = None
|
self.response = None
|
||||||
|
|
||||||
|
|
||||||
def test_serde_deserialize_error_triggers_fallback():
|
def test_serde_deserialize_error_does_not_trigger_fallback():
|
||||||
# DeepSeek Responses gateway rejecting the wire body (observed Aug 2026).
|
# Serde errors can also identify malformed user-provided request fields.
|
||||||
|
# The known DeepSeek wire-shape bug is fixed at serialization time instead.
|
||||||
err = _FakeAPIError(400, {
|
err = _FakeAPIError(400, {
|
||||||
"message": (
|
"message": (
|
||||||
"Failed to deserialize the JSON body into the target type: "
|
"Failed to deserialize the JSON body into the target type: "
|
||||||
@ -177,17 +178,7 @@ def test_serde_deserialize_error_triggers_fallback():
|
|||||||
"type": "invalid_request_error",
|
"type": "invalid_request_error",
|
||||||
"param": None,
|
"param": None,
|
||||||
})
|
})
|
||||||
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is True
|
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is False
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_type_error_triggers_fallback():
|
|
||||||
err = _FakeAPIError(422, "input[0]: invalid type: map, expected a string")
|
|
||||||
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is True
|
|
||||||
|
|
||||||
|
|
||||||
def test_unknown_field_error_triggers_fallback():
|
|
||||||
err = _FakeAPIError(400, "unknown field `foo`, expected one of `input`, `instructions`")
|
|
||||||
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is True
|
|
||||||
|
|
||||||
|
|
||||||
def test_legacy_compatibility_markers_still_trigger_fallback():
|
def test_legacy_compatibility_markers_still_trigger_fallback():
|
||||||
@ -195,16 +186,6 @@ def test_legacy_compatibility_markers_still_trigger_fallback():
|
|||||||
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is True
|
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is True
|
||||||
|
|
||||||
|
|
||||||
def test_unrelated_400_does_not_trigger_fallback():
|
|
||||||
err = _FakeAPIError(400, {"message": "rate limit exceeded", "type": "rate_limit_error"})
|
|
||||||
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is False
|
|
||||||
|
|
||||||
|
|
||||||
def test_server_error_does_not_trigger_fallback():
|
|
||||||
err = _FakeAPIError(500, {"message": "internal server error"})
|
|
||||||
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is False
|
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
# DeepSeek Responses wire shape (PR #5214 root cause)
|
# DeepSeek Responses wire shape (PR #5214 root cause)
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user