mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 17:31:15 -04:00
Use ToolResult in openai_conversation (#182544)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
6177c711d2
commit
621bec37a1
@@ -192,7 +192,7 @@ def _convert_content_to_param(
|
||||
and content.tool_call_id in web_search_calls
|
||||
):
|
||||
web_search_call = web_search_calls.pop(content.tool_call_id)
|
||||
web_search_call["status"] = content.tool_result.get( # type: ignore[typeddict-item]
|
||||
web_search_call["status"] = content.result.data.get( # type: ignore[typeddict-item]
|
||||
"status", "completed"
|
||||
)
|
||||
messages.append(web_search_call)
|
||||
@@ -201,7 +201,12 @@ def _convert_content_to_param(
|
||||
FunctionCallOutput(
|
||||
type="function_call_output",
|
||||
call_id=content.tool_call_id,
|
||||
output=json_dumps(content.tool_result),
|
||||
output=json_dumps(
|
||||
{
|
||||
"data": content.result.data,
|
||||
"error": content.result.error,
|
||||
}
|
||||
),
|
||||
)
|
||||
)
|
||||
continue
|
||||
@@ -342,13 +347,16 @@ async def _transform_stream( # noqa: C901 - This is complex, but better to have
|
||||
"role": "tool_result",
|
||||
"tool_call_id": event.item.id,
|
||||
"tool_name": "code_interpreter",
|
||||
"tool_result": {
|
||||
"output": (
|
||||
[output.to_dict() for output in event.item.outputs] # type: ignore[misc]
|
||||
if event.item.outputs is not None
|
||||
else None
|
||||
)
|
||||
},
|
||||
"result": llm.ToolResult(
|
||||
data={
|
||||
"output": (
|
||||
[output.to_dict() for output in event.item.outputs] # type: ignore[misc]
|
||||
if event.item.outputs is not None
|
||||
else None
|
||||
)
|
||||
},
|
||||
error=event.item.status == "failed",
|
||||
),
|
||||
}
|
||||
last_role = "tool_result"
|
||||
elif isinstance(event.item, ResponseFunctionWebSearch):
|
||||
@@ -370,7 +378,10 @@ async def _transform_stream( # noqa: C901 - This is complex, but better to have
|
||||
"role": "tool_result",
|
||||
"tool_call_id": event.item.id,
|
||||
"tool_name": "web_search_call",
|
||||
"tool_result": {"status": event.item.status},
|
||||
"result": llm.ToolResult(
|
||||
data={"status": event.item.status},
|
||||
error=event.item.status == "failed",
|
||||
),
|
||||
}
|
||||
last_role = "tool_result"
|
||||
elif isinstance(event.item, ImageGenerationCall):
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
}),
|
||||
dict({
|
||||
'call_id': 'ci_A',
|
||||
'output': '{"output":[{"logs":"235.70108188126758\\n","type":"logs"}]}',
|
||||
'output': '{"data":{"output":[{"logs":"235.70108188126758\\n","type":"logs"}]},"error":false}',
|
||||
'type': 'function_call_output',
|
||||
}),
|
||||
dict({
|
||||
@@ -204,7 +204,7 @@
|
||||
}),
|
||||
dict({
|
||||
'call_id': 'mock-tool-call-id',
|
||||
'output': '{"speech":{"plain":{"speech":"12:00 PM","extra_data":null}},"response_type":"action_done","speech_slots":{"time":"12:00:00"},"data":{"success":[],"failed":[]}}',
|
||||
'output': '{"data":{"speech":{"plain":{"speech":"12:00 PM","extra_data":null}},"response_type":"action_done","speech_slots":{"time":"12:00:00"},"data":{"success":[],"failed":[]}},"error":false}',
|
||||
'type': 'function_call_output',
|
||||
}),
|
||||
dict({
|
||||
@@ -240,7 +240,7 @@
|
||||
}),
|
||||
dict({
|
||||
'call_id': 'call_call_1',
|
||||
'output': '"value1"',
|
||||
'output': '{"data":"value1","error":false}',
|
||||
'type': 'function_call_output',
|
||||
}),
|
||||
dict({
|
||||
@@ -251,7 +251,7 @@
|
||||
}),
|
||||
dict({
|
||||
'call_id': 'call_call_2',
|
||||
'output': '"value2"',
|
||||
'output': '{"data":"value2","error":false}',
|
||||
'type': 'function_call_output',
|
||||
}),
|
||||
dict({
|
||||
|
||||
Reference in New Issue
Block a user