Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ def to_responses_fnc_ctx(
schemas: list[dict[str, Any]] = []
for tool in tool_ctx.flatten():
if isinstance(tool, llm.RawFunctionTool):
schema = tool.info.raw_schema
schema["type"] = "function"
schema = {**tool.info.raw_schema, "type": "function"}
schemas.append(schema)
elif isinstance(tool, llm.FunctionTool):
schema = llm.utils.build_legacy_openai_schema(tool, internally_tagged=True)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,23 @@ def test_copy_equals_original(self):
ctx2 = ctx1.copy()
assert ctx1 == ctx2

def test_openai_responses_raw_schema_does_not_mutate_tool_schema(self):
ctx = ToolContext([raw_tool_1])
raw_schema = raw_tool_1.info.raw_schema.copy()

responses_tools = ctx.parse_function_tools("openai.responses")

assert responses_tools[0]["type"] == "function"
assert raw_tool_1.info.raw_schema == raw_schema
assert "type" not in raw_tool_1.info.raw_schema

chat_tools = ctx.parse_function_tools("openai")
assert chat_tools[0] == {
"type": "function",
"function": raw_tool_1.info.raw_schema,
}
assert "type" not in chat_tools[0]["function"]

def test_update_tools_changes_equality(self):
ctx1 = ToolContext([mock_tool_1])
ctx2 = ToolContext([mock_tool_1])
Expand Down
Loading