Implement initial generated opener logic in DuplexPipeline to utilize tool-capable assistant turns when tools are available. Update tests to verify the correct behavior of the generated opener under various conditions, ensuring proper handling of user input and task management.
This commit is contained in:
@@ -246,6 +246,42 @@ async def test_generated_opener_prompt_uses_system_prompt_only(monkeypatch):
|
||||
assert "额外风格提示" not in user_prompt
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generated_opener_uses_tool_capable_turn_when_tools_available(monkeypatch):
|
||||
pipeline, _events = _build_pipeline(monkeypatch, [[LLMStreamEvent(type="done")]])
|
||||
pipeline.apply_runtime_overrides(
|
||||
{
|
||||
"generatedOpenerEnabled": True,
|
||||
"tools": [
|
||||
{
|
||||
"type": "function",
|
||||
"executor": "client",
|
||||
"function": {
|
||||
"name": "text_msg_prompt",
|
||||
"description": "Show a prompt",
|
||||
"parameters": {"type": "object", "properties": {}},
|
||||
},
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
called: Dict[str, Any] = {}
|
||||
waiter = asyncio.Event()
|
||||
|
||||
async def _fake_handle_turn(user_text: str) -> None:
|
||||
called["user_text"] = user_text
|
||||
waiter.set()
|
||||
|
||||
monkeypatch.setattr(pipeline, "_handle_turn", _fake_handle_turn)
|
||||
pipeline.conversation.greeting = "fallback greeting"
|
||||
|
||||
await pipeline.emit_initial_greeting()
|
||||
await asyncio.wait_for(waiter.wait(), timeout=1.0)
|
||||
|
||||
assert called.get("user_text") == ""
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ws_message_parses_tool_call_results():
|
||||
msg = parse_client_message(
|
||||
|
||||
Reference in New Issue
Block a user