|
@@ -139,7 +139,7 @@ def _event_tool_call_from_tools(
|
|
|
"query": content,
|
|
"query": content,
|
|
|
"title": content,
|
|
"title": content,
|
|
|
}
|
|
}
|
|
|
- return StreamItem.event(
|
|
|
|
|
|
|
+ return StreamItem.provider_tool_call(
|
|
|
ToolCallEvent(
|
|
ToolCallEvent(
|
|
|
id="event_agent_call_1",
|
|
id="event_agent_call_1",
|
|
|
name=tool_name,
|
|
name=tool_name,
|
|
@@ -442,7 +442,7 @@ class HistoryCapturingChatClient:
|
|
|
self.calls += 1
|
|
self.calls += 1
|
|
|
if self.calls == 1:
|
|
if self.calls == 1:
|
|
|
yield StreamItem.message_delta("Need event help.")
|
|
yield StreamItem.message_delta("Need event help.")
|
|
|
- yield StreamItem.event(
|
|
|
|
|
|
|
+ yield StreamItem.text_event(
|
|
|
ToolCallEvent(
|
|
ToolCallEvent(
|
|
|
id="call_1",
|
|
id="call_1",
|
|
|
name="handoff_note",
|
|
name="handoff_note",
|
|
@@ -544,6 +544,60 @@ async def test_openai_chat_client_streams_sse_chunks_through_parser():
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+@pytest.mark.asyncio
|
|
|
|
|
+async def test_openai_chat_client_flushes_one_provider_tool_call_at_done():
|
|
|
|
|
+ def handler(request: httpx.Request) -> httpx.Response:
|
|
|
|
|
+ return httpx.Response(
|
|
|
|
|
+ 200,
|
|
|
|
|
+ content=(
|
|
|
|
|
+ b'data: {"choices":[{"delta":{"tool_calls":[{"index":0,'
|
|
|
|
|
+ b'"id":"call_1","function":{"name":"mock_search",'
|
|
|
|
|
+ b'"arguments":"{\\"query\\":\\""}}]},"finish_reason":null}]}\n\n'
|
|
|
|
|
+ b'data: {"choices":[{"delta":{"tool_calls":[{"index":0,'
|
|
|
|
|
+ b'"function":{"arguments":"latency docs\\"}"}}]},'
|
|
|
|
|
+ b'"finish_reason":null}]}\n\n'
|
|
|
|
|
+ b"data: [DONE]\n\n"
|
|
|
|
|
+ ),
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ async with httpx.AsyncClient(
|
|
|
|
|
+ transport=httpx.MockTransport(handler),
|
|
|
|
|
+ base_url="https://llm.test/v1",
|
|
|
|
|
+ ) as http_client:
|
|
|
|
|
+ client = OpenAICompatibleChatClient(
|
|
|
|
|
+ api_key="",
|
|
|
|
|
+ base_url="https://llm.test/v1",
|
|
|
|
|
+ default_model="provider-default",
|
|
|
|
|
+ request_timeout_seconds=5,
|
|
|
|
|
+ http_client=http_client,
|
|
|
|
|
+ )
|
|
|
|
|
+ items = [
|
|
|
|
|
+ item
|
|
|
|
|
+ async for item in client.stream_chat(
|
|
|
|
|
+ messages=[ChatMessage(role="user", content="find docs")],
|
|
|
|
|
+ tools=[
|
|
|
|
|
+ {
|
|
|
|
|
+ "type": "function",
|
|
|
|
|
+ "function": {"name": "mock_search", "parameters": {}},
|
|
|
|
|
+ }
|
|
|
|
|
+ ],
|
|
|
|
|
+ params=AgentParams(model="provider-default"),
|
|
|
|
|
+ )
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ provider_calls = [
|
|
|
|
|
+ item.event for item in items if item.kind == "provider_tool_call"
|
|
|
|
|
+ ]
|
|
|
|
|
+ assert provider_calls == [
|
|
|
|
|
+ ToolCallEvent(
|
|
|
|
|
+ id="call_1",
|
|
|
|
|
+ name="mock_search",
|
|
|
|
|
+ arguments={"query": "latency docs"},
|
|
|
|
|
+ raw_arguments='{"query":"latency docs"}',
|
|
|
|
|
+ )
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
|
async def test_openai_chat_client_uses_default_model_when_request_model_is_blank():
|
|
async def test_openai_chat_client_uses_default_model_when_request_model_is_blank():
|
|
|
captured_payloads: list[dict] = []
|
|
captured_payloads: list[dict] = []
|