mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-25 09:19:23 +01:00
API: Allow content arrays for multimodal OpenAI requests (#5277)
This commit is contained in:
parent
166fdf09f3
commit
fbf8ae39f8
@ -144,6 +144,26 @@ def convert_history(history):
|
|||||||
user_input = ""
|
user_input = ""
|
||||||
system_message = ""
|
system_message = ""
|
||||||
|
|
||||||
|
if any(isinstance(entry['content'], list) for entry in history):
|
||||||
|
new_history = []
|
||||||
|
for entry in history:
|
||||||
|
if isinstance(entry['content'], list):
|
||||||
|
image_url = None
|
||||||
|
content = None
|
||||||
|
for item in entry['content']:
|
||||||
|
if not isinstance(item, dict):
|
||||||
|
continue
|
||||||
|
if item['type'] == 'image_url' and isinstance(item['image_url'], dict):
|
||||||
|
image_url = item['image_url']['url']
|
||||||
|
elif item['type'] == 'text' and isinstance(item['text'], str):
|
||||||
|
content = item['text']
|
||||||
|
if image_url and content:
|
||||||
|
new_history.append({"image_url": image_url, "role": "user"})
|
||||||
|
new_history.append({"content": content, "role": "user"})
|
||||||
|
else:
|
||||||
|
new_history.append(entry)
|
||||||
|
history = new_history
|
||||||
|
|
||||||
for entry in history:
|
for entry in history:
|
||||||
if "image_url" in entry:
|
if "image_url" in entry:
|
||||||
image_url = entry['image_url']
|
image_url = entry['image_url']
|
||||||
|
Loading…
Reference in New Issue
Block a user