From 3a285217107f3042a4d6b7a60eedcdd07f73627d Mon Sep 17 00:00:00 2001 From: marko1616 <45327989+marko1616@users.noreply.github.com> Date: Fri, 23 Aug 2024 14:43:18 +0800 Subject: [PATCH] Force re check. --- src/llamafactory/api/chat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/llamafactory/api/chat.py b/src/llamafactory/api/chat.py index 5bad1af2..1f0c1e95 100644 --- a/src/llamafactory/api/chat.py +++ b/src/llamafactory/api/chat.py @@ -14,6 +14,7 @@ import base64 import io +import re import json import os import uuid @@ -105,7 +106,7 @@ def _process_request( input_messages.append({"role": ROLE_MAPPING[message.role], "content": input_item.text}) else: image_url = input_item.image_url.url - if image_url.startswith("data:image"): # base64 image + if re.match("^data:image\/(png|jpg|jpeg|gif|bmp);base64,(.+)$", data_url): image_data = base64.b64decode(image_url.split(",", maxsplit=1)[1]) image_path = io.BytesIO(image_data) elif os.path.isfile(image_url): # local file