🐛 Bug: Fix the bug that the official Claude API cannot use PNG format images.
Browse files- request.py +6 -2
request.py
CHANGED
@@ -3,6 +3,10 @@ from models import RequestModel
|
|
3 |
from utils import c35s, c3s, c3o, c3h, gem, BaseAPI
|
4 |
|
5 |
async def get_image_message(base64_image, engine = None):
|
|
|
|
|
|
|
|
|
6 |
if "gpt" == engine:
|
7 |
return {
|
8 |
"type": "image_url",
|
@@ -15,14 +19,14 @@ async def get_image_message(base64_image, engine = None):
|
|
15 |
"type": "image",
|
16 |
"source": {
|
17 |
"type": "base64",
|
18 |
-
"media_type":
|
19 |
"data": base64_image.split(",")[1],
|
20 |
}
|
21 |
}
|
22 |
if "gemini" == engine or "vertex-gemini" == engine:
|
23 |
return {
|
24 |
"inlineData": {
|
25 |
-
"mimeType":
|
26 |
"data": base64_image.split(",")[1],
|
27 |
}
|
28 |
}
|
|
|
3 |
from utils import c35s, c3s, c3o, c3h, gem, BaseAPI
|
4 |
|
5 |
async def get_image_message(base64_image, engine = None):
|
6 |
+
colon_index = base64_image.index(":")
|
7 |
+
semicolon_index = base64_image.index(";")
|
8 |
+
image_type = base64_image[colon_index + 1:semicolon_index]
|
9 |
+
# print("image_type", image_type)
|
10 |
if "gpt" == engine:
|
11 |
return {
|
12 |
"type": "image_url",
|
|
|
19 |
"type": "image",
|
20 |
"source": {
|
21 |
"type": "base64",
|
22 |
+
"media_type": image_type,
|
23 |
"data": base64_image.split(",")[1],
|
24 |
}
|
25 |
}
|
26 |
if "gemini" == engine or "vertex-gemini" == engine:
|
27 |
return {
|
28 |
"inlineData": {
|
29 |
+
"mimeType": image_type,
|
30 |
"data": base64_image.split(",")[1],
|
31 |
}
|
32 |
}
|