From 166fdf09f3000a9174c3176afa86895a7c2085f0 Mon Sep 17 00:00:00 2001 From: Ercan <62525303+ercanozer@users.noreply.github.com> Date: Mon, 22 Jan 2024 06:08:51 -0500 Subject: [PATCH] API: Properly handle Images with RGBA color format (#5332) --- extensions/openai/completions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/openai/completions.py b/extensions/openai/completions.py index b1bb0fff..35dd5d14 100644 --- a/extensions/openai/completions.py +++ b/extensions/openai/completions.py @@ -156,8 +156,9 @@ 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''