mirror of
https://github.com/open-webui/open-webui.git
synced 2026-08-27 06:46:30 -05:00
refac
This commit is contained in:
@@ -1359,8 +1359,21 @@ 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 if isinstance(url_data, str) else ''
|
||||
detail = 'auto'
|
||||
content_parts.append({'type': 'input_image', 'image_url': url, 'detail': detail})
|
||||
elif part.get('type') == 'file':
|
||||
# OpenAI-compatible proxy path only. Open WebUI attachments are handled
|
||||
# separately via metadata.files/RAG and must not be converted here.
|
||||
file = part.get('file')
|
||||
if isinstance(file, dict):
|
||||
file_part = {k: file[k] for k in ('file_id', 'file_data', 'filename') if k in file}
|
||||
if 'file_id' in file_part or 'file_data' in file_part:
|
||||
content_parts.append({'type': 'input_file', **file_part})
|
||||
else:
|
||||
content_parts = [{'type': text_type, 'text': str(content)}]
|
||||
|
||||
|
||||
@@ -2123,7 +2123,13 @@ async def convert_url_images_to_base64(form_data, user=None):
|
||||
new_content.append(item)
|
||||
continue
|
||||
|
||||
image_url = item.get('image_url', {}).get('url', '')
|
||||
image_url_data = item.get('image_url', {})
|
||||
if isinstance(image_url_data, dict):
|
||||
image_url = image_url_data.get('url') or ''
|
||||
elif isinstance(image_url_data, str):
|
||||
image_url = image_url_data
|
||||
else:
|
||||
image_url = ''
|
||||
if image_url.startswith('data:image/'):
|
||||
new_content.append(item)
|
||||
continue
|
||||
@@ -2131,10 +2137,13 @@ async def convert_url_images_to_base64(form_data, user=None):
|
||||
try:
|
||||
base64_data = await get_image_base64_from_url(image_url, user=user)
|
||||
if base64_data:
|
||||
image_url_payload = {'url': base64_data}
|
||||
if isinstance(image_url_data, dict) and image_url_data.get('detail'):
|
||||
image_url_payload['detail'] = image_url_data['detail']
|
||||
new_content.append(
|
||||
{
|
||||
'type': 'image_url',
|
||||
'image_url': {'url': base64_data},
|
||||
'image_url': image_url_payload,
|
||||
}
|
||||
)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user