mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-12 09:01:18 +00:00
preserve loose tool schema compatibility
This commit is contained in:
parent
d4c9c83a36
commit
b4f9cbc435
2 changed files with 35 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
29
test/test_openai_responses_payload.py
Normal file
29
test/test_openai_responses_payload.py
Normal 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'})
|
||||
Loading…
Add table
Reference in a new issue