preserve loose tool schema compatibility

This commit is contained in:
Sean 2026-08-14 21:00:16 +08:00
parent d4c9c83a36
commit b4f9cbc435
2 changed files with 35 additions and 2 deletions

View file

@ -1403,8 +1403,12 @@ def convert_to_responses_payload(payload: dict) -> dict:
# Responses tools default to strict mode when the field is
# omitted. Preserve the loose-schema semantics of Chat,
# MCP, and OpenAPI function tools unless strictness was
# explicitly requested by the caller.
converted_tool['strict'] = func.get('strict', False)
# explicitly requested by the caller. Keep the old wire
# format for tools without a parameters schema.
if 'strict' in func:
converted_tool['strict'] = func['strict']
elif 'parameters' in func:
converted_tool['strict'] = False
converted_tools.append(converted_tool)
else:
# Already in correct format or unknown format, pass through

View file

@ -0,0 +1,29 @@
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parents[1] / 'backend'))
from open_webui.routers.openai import convert_to_responses_payload
def _convert_tool(function: dict) -> dict:
payload = convert_to_responses_payload(
{
'messages': [],
'tools': [{'type': 'function', 'function': function}],
}
)
return payload['tools'][0]
def test_convert_to_responses_payload_preserves_explicit_strict_values():
assert _convert_tool({'name': 'strict', 'parameters': {}, 'strict': True})['strict'] is True
assert _convert_tool({'name': 'loose', 'parameters': {}, 'strict': False})['strict'] is False
def test_convert_to_responses_payload_defaults_schema_tools_to_loose():
assert _convert_tool({'name': 'default', 'parameters': {}})['strict'] is False
def test_convert_to_responses_payload_omits_strict_for_tools_without_parameters():
assert 'strict' not in _convert_tool({'name': 'no-schema'})