mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-17 13:12:36 +00:00
raise error if input has function_call_output with no matching function_call
This commit is contained in:
parent
012088e084
commit
e40a212af4
2 changed files with 18 additions and 7 deletions
|
|
@ -157,8 +157,10 @@ async def convert_response_input_to_chat_messages(
|
||||||
f"Llama Stack OpenAI Responses does not yet support message role '{input_item.role}' in this context"
|
f"Llama Stack OpenAI Responses does not yet support message role '{input_item.role}' in this context"
|
||||||
)
|
)
|
||||||
messages.append(message_type(content=content))
|
messages.append(message_type(content=content))
|
||||||
for result in tool_call_results.values():
|
if len(tool_call_results):
|
||||||
messages.append(result)
|
raise ValueError(
|
||||||
|
f"Received function_call_output(s) with call_id(s) {tool_call_results.keys()}, but no corresponding function_call"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
messages.append(OpenAIUserMessageParam(content=input))
|
messages.append(OpenAIUserMessageParam(content=input))
|
||||||
return messages
|
return messages
|
||||||
|
|
|
||||||
|
|
@ -115,18 +115,27 @@ class TestConvertResponseInputToChatMessages:
|
||||||
|
|
||||||
async def test_convert_function_tool_call_output(self):
|
async def test_convert_function_tool_call_output(self):
|
||||||
input_items = [
|
input_items = [
|
||||||
|
OpenAIResponseOutputMessageFunctionToolCall(
|
||||||
|
call_id="call_123",
|
||||||
|
name="test_function",
|
||||||
|
arguments='{"param": "value"}',
|
||||||
|
),
|
||||||
OpenAIResponseInputFunctionToolCallOutput(
|
OpenAIResponseInputFunctionToolCallOutput(
|
||||||
output="Tool output",
|
output="Tool output",
|
||||||
call_id="call_123",
|
call_id="call_123",
|
||||||
)
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
result = await convert_response_input_to_chat_messages(input_items)
|
result = await convert_response_input_to_chat_messages(input_items)
|
||||||
|
|
||||||
assert len(result) == 1
|
assert len(result) == 2
|
||||||
assert isinstance(result[0], OpenAIToolMessageParam)
|
assert isinstance(result[0], OpenAIAssistantMessageParam)
|
||||||
assert result[0].content == "Tool output"
|
assert result[0].tool_calls[0].id == "call_123"
|
||||||
assert result[0].tool_call_id == "call_123"
|
assert result[0].tool_calls[0].function.name == "test_function"
|
||||||
|
assert result[0].tool_calls[0].function.arguments == '{"param": "value"}'
|
||||||
|
assert isinstance(result[1], OpenAIToolMessageParam)
|
||||||
|
assert result[1].content == "Tool output"
|
||||||
|
assert result[1].tool_call_id == "call_123"
|
||||||
|
|
||||||
async def test_convert_function_tool_call(self):
|
async def test_convert_function_tool_call(self):
|
||||||
input_items = [
|
input_items = [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue