mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-22 08:07:56 +01:00
openai extension fix: Handle Multiple Content Items in Messages (#6528)
This commit is contained in:
parent
5fa9336dab
commit
9b3a3d8f12
@ -143,21 +143,20 @@ def convert_history(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
|
||||
|
||||
|
||||
image_url = None
|
||||
content = None
|
||||
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:
|
||||
new_history.append({"image_url": image_url, "role": "user"})
|
||||
if content:
|
||||
new_history.append({"content": content, "role": "user"})
|
||||
if image_url:
|
||||
new_history.append({"image_url": image_url, "role": "user"})
|
||||
if content:
|
||||
new_history.append({"content": content, "role": "user"})
|
||||
else:
|
||||
new_history.append(entry)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user