Compare commits

...

3 Commits

Author SHA1 Message Date
Hua
06ee68d871 Merge remote-tracking branch 'origin/main'
Some checks failed
Test Suite / test (3.11) (push) Failing after 1m2s
Test Suite / test (3.12) (push) Failing after 1m1s
Test Suite / test (3.13) (push) Failing after 59s
2026-03-17 14:47:40 +08:00
Xubin Ren
49fc50b1e6 test(custom): cover empty choices response handling 2026-03-17 14:24:55 +08:00
Jiajun Xie
2eb0c283e9 fix(providers): handle empty choices in custom provider response 2026-03-17 14:24:55 +08:00
2 changed files with 18 additions and 0 deletions

View File

@@ -54,6 +54,11 @@ class CustomProvider(LLMProvider):
return LLMResponse(content=f"Error: {e}", finish_reason="error") return LLMResponse(content=f"Error: {e}", finish_reason="error")
def _parse(self, response: Any) -> LLMResponse: def _parse(self, response: Any) -> LLMResponse:
if not response.choices:
return LLMResponse(
content="Error: API returned empty choices. This may indicate a temporary service issue or an invalid model response.",
finish_reason="error"
)
choice = response.choices[0] choice = response.choices[0]
msg = choice.message msg = choice.message
tool_calls = [ tool_calls = [

View File

@@ -0,0 +1,13 @@
from types import SimpleNamespace
from nanobot.providers.custom_provider import CustomProvider
def test_custom_provider_parse_handles_empty_choices() -> None:
provider = CustomProvider()
response = SimpleNamespace(choices=[])
result = provider._parse(response)
assert result.finish_reason == "error"
assert "empty choices" in result.content