mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-12 09:01:18 +00:00
fix(openai): preserve image detail in responses conversion
This commit is contained in:
parent
8faaf2cd1e
commit
91d4049a97
2 changed files with 47 additions and 2 deletions
|
|
@ -1092,8 +1092,13 @@ def convert_to_responses_payload(payload: dict) -> dict:
|
|||
content_parts.append({'type': text_type, 'text': part.get('text', '')})
|
||||
elif part.get('type') == 'image_url':
|
||||
url_data = part.get('image_url', {})
|
||||
url = url_data.get('url', '') if isinstance(url_data, dict) else url_data
|
||||
content_parts.append({'type': 'input_image', 'image_url': url})
|
||||
if isinstance(url_data, dict):
|
||||
url = url_data.get('url', '')
|
||||
detail = url_data.get('detail') or 'auto'
|
||||
else:
|
||||
url = url_data
|
||||
detail = 'auto'
|
||||
content_parts.append({'type': 'input_image', 'image_url': url, 'detail': detail})
|
||||
else:
|
||||
content_parts = [{'type': text_type, 'text': str(content)}]
|
||||
|
||||
|
|
|
|||
40
backend/test/routers/test_openai.py
Normal file
40
backend/test/routers/test_openai.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
from copy import deepcopy
|
||||
|
||||
from open_webui.routers.openai import convert_to_responses_payload
|
||||
|
||||
|
||||
def _convert(image_url: object) -> dict:
|
||||
payload = {
|
||||
'messages': [
|
||||
{
|
||||
'role': 'user',
|
||||
'content': [{'type': 'image_url', 'image_url': image_url}],
|
||||
}
|
||||
]
|
||||
}
|
||||
result = convert_to_responses_payload(deepcopy(payload))
|
||||
return result['input'][0]['content'][0]
|
||||
|
||||
|
||||
def test_image_object_without_detail_defaults_to_auto() -> None:
|
||||
assert _convert({'url': 'data:image/png;base64,abc'}) == {
|
||||
'type': 'input_image',
|
||||
'image_url': 'data:image/png;base64,abc',
|
||||
'detail': 'auto',
|
||||
}
|
||||
|
||||
|
||||
def test_image_object_preserves_explicit_detail() -> None:
|
||||
assert _convert({'url': 'https://example.test/image.png', 'detail': 'high'}) == {
|
||||
'type': 'input_image',
|
||||
'image_url': 'https://example.test/image.png',
|
||||
'detail': 'high',
|
||||
}
|
||||
|
||||
|
||||
def test_string_image_url_defaults_to_auto() -> None:
|
||||
assert _convert('https://example.test/image.png') == {
|
||||
'type': 'input_image',
|
||||
'image_url': 'https://example.test/image.png',
|
||||
'detail': 'auto',
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue