From 817866c9cfbe64f5e9cb14f62f8977564c97a539 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 22 Jan 2024 04:07:25 -0800 Subject: [PATCH] Lint --- extensions/openai/completions.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/extensions/openai/completions.py b/extensions/openai/completions.py index e100472c..19a8f893 100644 --- a/extensions/openai/completions.py +++ b/extensions/openai/completions.py @@ -158,15 +158,18 @@ def convert_history(history): 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: @@ -181,9 +184,11 @@ def convert_history(history): img = Image.open(BytesIO(my_res.content)) except Exception: raise 'Image cannot be loaded from the URL!' + buffered = BytesIO() if img.mode in ("RGBA", "P"): img = img.convert("RGB") + img.save(buffered, format="JPEG") img_str = base64.b64encode(buffered.getvalue()).decode('utf-8') content = f'' @@ -197,6 +202,7 @@ def convert_history(history): if current_message: chat_dialogue.append([current_message, '']) current_message = "" + current_message = content elif role == "assistant": current_reply = content