fix: model arguments fixed
This commit is contained in:
@@ -98,3 +98,48 @@ def test_nanobot_chat_stream_syncs_project_id(monkeypatch) -> None:
|
||||
assert "stream-complete" in content
|
||||
assert calls == [{"session_key": "api:test-3", "project_id": 202}]
|
||||
assert process_kwargs and process_kwargs[0]["project_id"] == 202
|
||||
|
||||
|
||||
def test_nanobot_chat_stream_emits_reasoning_flags_and_final_reasoning(monkeypatch) -> None:
|
||||
async def fake_process_message(*args, **kwargs):
|
||||
on_progress = kwargs.get("on_progress")
|
||||
on_stream = kwargs.get("on_stream")
|
||||
if on_progress:
|
||||
await on_progress("模型正在拆解问题", is_reasoning=True)
|
||||
await on_progress("开始执行工具", tool_hint=True)
|
||||
if on_stream:
|
||||
await on_stream("answer-token")
|
||||
return "final-answer"
|
||||
|
||||
class _DummySession:
|
||||
def __init__(self):
|
||||
self.metadata = {}
|
||||
self.messages = [
|
||||
{"role": "assistant", "content": "final-answer", "reasoning_content": "完整思考过程"}
|
||||
]
|
||||
|
||||
class _DummySessions:
|
||||
def get_or_create(self, _key):
|
||||
return _DummySession()
|
||||
|
||||
class _DummyAgent:
|
||||
def __init__(self):
|
||||
self.sessions = _DummySessions()
|
||||
|
||||
async def collect_stream_chunks(response) -> list[str]:
|
||||
chunks: list[str] = []
|
||||
async for chunk in response.body_iterator:
|
||||
chunks.append(chunk.decode("utf-8") if isinstance(chunk, bytes) else chunk)
|
||||
return chunks
|
||||
|
||||
monkeypatch.setattr(main.nanobot_service, "process_message", fake_process_message)
|
||||
monkeypatch.setattr(main.nanobot_service, "agent", _DummyAgent())
|
||||
|
||||
request = main.ChatRequest(message="hello", session_id="api:test-4", project_id=303)
|
||||
response = asyncio.run(main.nanobot_chat_stream(request))
|
||||
chunks = asyncio.run(collect_stream_chunks(response))
|
||||
content = "".join(chunks)
|
||||
|
||||
assert '"type": "progress", "content": "模型正在拆解问题", "is_reasoning": true' in content
|
||||
assert '"type": "progress", "content": "开始执行工具", "tool_hint": true' in content
|
||||
assert '"type": "final", "content": "final-answer", "reasoning_content": "完整思考过程"' in content
|
||||
|
||||
Reference in New Issue
Block a user