mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-06-13 22:34:06 +00:00
fix: add regression tests for bare-dict coercion, update stale comment
This commit is contained in:
parent
98be0de919
commit
b2e43955e3
@ -1166,7 +1166,7 @@ def _run_gateway(
|
|||||||
console.print(f"[green]✓[/green] Health endpoint: http://{host}:{health_port}/health")
|
console.print(f"[green]✓[/green] Health endpoint: http://{host}:{health_port}/health")
|
||||||
async with server:
|
async with server:
|
||||||
await server.serve_forever()
|
await server.serve_forever()
|
||||||
# Register Dream system job (always-on, idempotent on restart)
|
# Register Dream system job (idempotent on restart)
|
||||||
dream_cfg = config.agents.defaults.dream
|
dream_cfg = config.agents.defaults.dream
|
||||||
if dream_cfg.model_override:
|
if dream_cfg.model_override:
|
||||||
agent.dream.model = dream_cfg.model_override
|
agent.dream.model = dream_cfg.model_override
|
||||||
|
|||||||
@ -5,6 +5,9 @@ Regression for: tool results containing OpenAI-format image_url blocks
|
|||||||
were passed to Anthropic unconverted, causing silent image drops with a
|
were passed to Anthropic unconverted, causing silent image drops with a
|
||||||
"Non-transient LLM error with image content, retrying without images"
|
"Non-transient LLM error with image content, retrying without images"
|
||||||
warning.
|
warning.
|
||||||
|
|
||||||
|
Also tests that bare dicts without a "type" field are coerced to text
|
||||||
|
blocks, fixing Anthropic "content.0.type: Field required" rejections (#3993).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from nanobot.providers.anthropic_provider import AnthropicProvider
|
from nanobot.providers.anthropic_provider import AnthropicProvider
|
||||||
@ -55,3 +58,25 @@ def test_tool_result_block_preserves_string_content():
|
|||||||
assert block["type"] == "tool_result"
|
assert block["type"] == "tool_result"
|
||||||
assert block["tool_use_id"] == "call_2"
|
assert block["tool_use_id"] == "call_2"
|
||||||
assert block["content"] == "plain tool output"
|
assert block["content"] == "plain tool output"
|
||||||
|
|
||||||
|
|
||||||
|
def test_convert_user_content_coerces_typeless_dict():
|
||||||
|
"""Bare dicts without a "type" field must be coerced to text blocks.
|
||||||
|
Regression for #3993: tools returning plain dicts caused Anthropic to
|
||||||
|
reject the request with "content.0.type: Field required"."""
|
||||||
|
result = AnthropicProvider._convert_user_content([
|
||||||
|
{"foo": "bar"},
|
||||||
|
{"type": "text", "text": "ok"},
|
||||||
|
])
|
||||||
|
assert result[0] == {"type": "text", "text": str({"foo": "bar"})}
|
||||||
|
assert result[1] == {"type": "text", "text": "ok"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_convert_user_content_coerces_mixed_typeless():
|
||||||
|
"""Multiple typeless items and non-dict items are all handled."""
|
||||||
|
result = AnthropicProvider._convert_user_content([
|
||||||
|
42,
|
||||||
|
{"key": "val"},
|
||||||
|
])
|
||||||
|
assert result[0] == {"type": "text", "text": "42"}
|
||||||
|
assert result[1] == {"type": "text", "text": str({"key": "val"})}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user