Fix Harmony tool descriptions for optional fields (#44686)
Signed-off-by: Varun Shenoy <varun.vinayak.shenoy@oracle.com> Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
co-authored by
Codex
parent
7a74f31d2e
commit
5828a205ef
@@ -2,11 +2,14 @@
|
|||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from openai.types.responses import FunctionTool
|
||||||
from openai_harmony import DeveloperContent, Message, Role
|
from openai_harmony import DeveloperContent, Message, Role
|
||||||
|
|
||||||
from tests.entrypoints.openai.utils import verify_harmony_messages
|
from tests.entrypoints.openai.utils import verify_harmony_messages
|
||||||
|
from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionToolsParam
|
||||||
from vllm.entrypoints.openai.parser.harmony_utils import (
|
from vllm.entrypoints.openai.parser.harmony_utils import (
|
||||||
auto_drop_analysis_messages,
|
auto_drop_analysis_messages,
|
||||||
|
create_tool_definition,
|
||||||
extract_function_from_recipient,
|
extract_function_from_recipient,
|
||||||
get_encoding,
|
get_encoding,
|
||||||
get_system_message,
|
get_system_message,
|
||||||
@@ -20,6 +23,58 @@ from vllm.entrypoints.openai.responses.harmony import (
|
|||||||
response_previous_input_to_harmony,
|
response_previous_input_to_harmony,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_TOOL_PARAMETERS = {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {"status": {"type": "string"}},
|
||||||
|
"required": ["status"],
|
||||||
|
"additionalProperties": False,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestCreateToolDefinition:
|
||||||
|
def test_chat_completion_omitted_description_defaults_to_empty_string(self):
|
||||||
|
tool = ChatCompletionToolsParam(
|
||||||
|
function={
|
||||||
|
"name": "report_status",
|
||||||
|
"parameters": _TOOL_PARAMETERS,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
tool_definition = create_tool_definition(tool)
|
||||||
|
|
||||||
|
assert tool_definition.name == "report_status"
|
||||||
|
assert tool_definition.description == ""
|
||||||
|
assert tool_definition.parameters == _TOOL_PARAMETERS
|
||||||
|
|
||||||
|
def test_chat_completion_none_description_defaults_to_empty_string(self):
|
||||||
|
tool = ChatCompletionToolsParam(
|
||||||
|
function={
|
||||||
|
"name": "report_status",
|
||||||
|
"description": None,
|
||||||
|
"parameters": _TOOL_PARAMETERS,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
tool_definition = create_tool_definition(tool)
|
||||||
|
|
||||||
|
assert tool_definition.name == "report_status"
|
||||||
|
assert tool_definition.description == ""
|
||||||
|
assert tool_definition.parameters == _TOOL_PARAMETERS
|
||||||
|
|
||||||
|
def test_response_tool_none_description_defaults_to_empty_string(self):
|
||||||
|
tool = FunctionTool(
|
||||||
|
name="report_status",
|
||||||
|
description=None,
|
||||||
|
parameters=_TOOL_PARAMETERS,
|
||||||
|
type="function",
|
||||||
|
)
|
||||||
|
|
||||||
|
tool_definition = create_tool_definition(tool)
|
||||||
|
|
||||||
|
assert tool_definition.name == "report_status"
|
||||||
|
assert tool_definition.description == ""
|
||||||
|
assert tool_definition.parameters == _TOOL_PARAMETERS
|
||||||
|
|
||||||
|
|
||||||
class TestIsFunctionRecipient:
|
class TestIsFunctionRecipient:
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|||||||
@@ -150,12 +150,12 @@ def create_tool_definition(tool: ChatCompletionToolsParam | Tool):
|
|||||||
if isinstance(tool, ChatCompletionToolsParam):
|
if isinstance(tool, ChatCompletionToolsParam):
|
||||||
return ToolDescription.new(
|
return ToolDescription.new(
|
||||||
name=tool.function.name,
|
name=tool.function.name,
|
||||||
description=tool.function.description,
|
description=tool.function.description or "",
|
||||||
parameters=tool.function.parameters,
|
parameters=tool.function.parameters,
|
||||||
)
|
)
|
||||||
return ToolDescription.new(
|
return ToolDescription.new(
|
||||||
name=tool.name,
|
name=tool.name,
|
||||||
description=tool.description,
|
description=tool.description or "",
|
||||||
parameters=tool.parameters,
|
parameters=tool.parameters,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user