返回提交历史
Modified
g4f/image/__init__.py
+3
-1
XFEstudio/gpt4free
Support uploaded images
3024cc5c
代码差异
1 个文件
+3
-1
@@ -161,9 +161,11 @@ def is_data_uri_an_image(data_uri: str) -> bool:
161
161
Raises:
162
162
ValueError: If the data URI is invalid or the image format is not allowed.
163
163
"""
164
if data_uri.startswith("https:") or data_uri.startswith("http:"):
165
return True
164
166
# Check if the data URI starts with 'data:image' and contains an image format (e.g., jpeg, png, gif)
165
167
if not re.match(r'data:image/(\w+);base64,', data_uri):
166
raise ValueError("Invalid data URI image.")
168
raise ValueError(f"Invalid data URI image. {data_uri[:10]}...")
167
169
# Extract the image format from the data URI
168
170
image_format = re.match(r'data:image/(\w+);base64,', data_uri).group(1).lower()
169
171
# Check if the image format is one of the allowed formats (jpg, jpeg, png, gif)