refac
This commit is contained in:
1 parent
6330350a40
commit
ca4e07a40b
2 files changed
+26
-4
No files matched your search
@@ -1359,8 +1359,21 @@ def convert_to_responses_payload(payload: dict) -> dict:
|
|||||||
content_parts.append({'type': text_type, 'text': part.get('text', '')})
|
content_parts.append({'type': text_type, 'text': part.get('text', '')})
|
||||||
elif part.get('type') == 'image_url':
|
elif part.get('type') == 'image_url':
|
||||||
url_data = part.get('image_url', {})
|
url_data = part.get('image_url', {})
|
||||||
url = url_data.get('url', '') if isinstance(url_data, dict) else url_data
|
if isinstance(url_data, dict):
|
||||||
content_parts.append({'type': 'input_image', 'image_url': url})
|
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:
|
else:
|
||||||
content_parts = [{'type': text_type, 'text': str(content)}]
|
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)
|
new_content.append(item)
|
||||||
continue
|
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/'):
|
if image_url.startswith('data:image/'):
|
||||||
new_content.append(item)
|
new_content.append(item)
|
||||||
continue
|
continue
|
||||||
@@ -2131,10 +2137,13 @@ async def convert_url_images_to_base64(form_data, user=None):
|
|||||||
try:
|
try:
|
||||||
base64_data = await get_image_base64_from_url(image_url, user=user)
|
base64_data = await get_image_base64_from_url(image_url, user=user)
|
||||||
if base64_data:
|
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(
|
new_content.append(
|
||||||
{
|
{
|
||||||
'type': 'image_url',
|
'type': 'image_url',
|
||||||
'image_url': {'url': base64_data},
|
'image_url': image_url_payload,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in new issue
Block a user