From 7323d8e86faa3a5e1588032aa676cebd9d06c105 Mon Sep 17 00:00:00 2001 From: Ashwin Bharambe Date: Mon, 28 Apr 2025 13:39:50 -0700 Subject: [PATCH] fix tool calling by not relying on finish reason but tool_calls --- .../inline/agents/meta_reference/openai_responses.py | 6 +++--- tests/verifications/openai-api-verification-run.yaml | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/llama_stack/providers/inline/agents/meta_reference/openai_responses.py b/llama_stack/providers/inline/agents/meta_reference/openai_responses.py index db1e32f8b..0690a15fe 100644 --- a/llama_stack/providers/inline/agents/meta_reference/openai_responses.py +++ b/llama_stack/providers/inline/agents/meta_reference/openai_responses.py @@ -143,7 +143,7 @@ class OpenAIResponsesImpl: stream=stream, ) - if isinstance(chat_response, AsyncIterator): + if stream: # TODO: refactor this into a separate method that handles streaming chat_response_id = "" chat_response_content = [] @@ -175,10 +175,10 @@ class OpenAIResponsesImpl: ) else: # dump and reload to map to our pydantic types - chat_response = OpenAIChatCompletion.model_validate_json(chat_response.model_dump_json()) + chat_response = OpenAIChatCompletion(**chat_response.model_dump()) output_messages: List[OpenAIResponseOutput] = [] - if chat_response.choices[0].finish_reason == "tool_calls": + if chat_response.choices[0].message.tool_calls: output_messages.extend( await self._execute_tool_and_return_final_output(model, stream, chat_response, messages) ) diff --git a/tests/verifications/openai-api-verification-run.yaml b/tests/verifications/openai-api-verification-run.yaml index 625228ca1..04675577d 100644 --- a/tests/verifications/openai-api-verification-run.yaml +++ b/tests/verifications/openai-api-verification-run.yaml @@ -1,3 +1,6 @@ +# This is a temporary run file because model names used by the verification tests +# are not quite consistent with various pre-existing distributions. +# version: '2' image_name: openai-api-verification apis: