mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-04 04:04:14 +00:00
Fix: Ensure that tool calls with no arguments get handled correctly #3560
When a model decides to use an MCP tool call that requires no arguments, it sets the arguments field to None. This causes validation errors because this field gets removed when being parsed by an openai compatible inference provider like vLLM This PR ensures that, as soon as the tool call args are accumulated while streaming, we check to ensure no tool call function arguments are set to None - if they are we replace them with "{}" Closes #3456 Added new unit test to verify that any tool calls with function arguments set to None get handled correctly Signed-off-by: Jaideep Rao <jrao@redhat.com>
This commit is contained in:
parent
6cce553c93
commit
4aa586d7af
3 changed files with 163 additions and 1 deletions
|
@ -264,3 +264,36 @@ def test_function_call_output_response(openai_client, client_with_models, text_m
|
|||
assert (
|
||||
"sunny" in response2.output[0].content[0].text.lower() or "warm" in response2.output[0].content[0].text.lower()
|
||||
)
|
||||
|
||||
|
||||
def test_function_call_output_response_with_none_arguments(openai_client, client_with_models, text_model_id):
|
||||
"""Test handling of function call outputs in responses when function does not accept arguments."""
|
||||
if isinstance(client_with_models, LlamaStackAsLibraryClient):
|
||||
pytest.skip("OpenAI responses are not supported when testing with library client yet.")
|
||||
|
||||
client = openai_client
|
||||
|
||||
# First create a response that triggers a function call
|
||||
response = client.responses.create(
|
||||
model=text_model_id,
|
||||
input=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "what's the current time? You MUST call the `get_current_time` function to find out.",
|
||||
}
|
||||
],
|
||||
tools=[
|
||||
{
|
||||
"type": "function",
|
||||
"name": "get_current_time",
|
||||
"description": "Get the current time",
|
||||
"parameters": {},
|
||||
}
|
||||
],
|
||||
stream=False,
|
||||
)
|
||||
|
||||
# Verify we got a function call
|
||||
assert response.output[0].type == "function_call"
|
||||
assert response.output[0].arguments == "{}"
|
||||
_ = response.output[0].call_id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue