mirror of https://github.com/Mai-with-u/MaiBot.git
Merge pull request #1429 from exynos967/dev
fix: 规范 OpenAI/Gemini 客户端图片 MIME(jpg/jpeg→image/jpeg)pull/1432/head
commit
e2ba3e324d
|
|
@ -98,7 +98,10 @@ def _convert_messages(
|
|||
content: List[Part] = []
|
||||
for item in message.content:
|
||||
if isinstance(item, tuple):
|
||||
image_format = "jpeg" if item[0].lower() == "jpg" else item[0].lower()
|
||||
image_format = item[0].lower()
|
||||
# 规范 JPEG MIME 类型后缀,统一使用 image/jpeg
|
||||
if image_format in ("jpg", "jpeg"):
|
||||
image_format = "jpeg"
|
||||
content.append(Part.from_bytes(data=base64.b64decode(item[1]), mime_type=f"image/{image_format}"))
|
||||
elif isinstance(item, str):
|
||||
content.append(Part.from_text(text=item))
|
||||
|
|
|
|||
|
|
@ -61,10 +61,16 @@ def _convert_messages(messages: list[Message]) -> list[ChatCompletionMessagePara
|
|||
content = []
|
||||
for item in message.content:
|
||||
if isinstance(item, tuple):
|
||||
image_format = item[0].lower()
|
||||
# 规范 JPEG MIME 类型后缀,统一使用 image/jpeg
|
||||
if image_format in ("jpg", "jpeg"):
|
||||
mime_suffix = "jpeg"
|
||||
else:
|
||||
mime_suffix = image_format
|
||||
content.append(
|
||||
{
|
||||
"type": "image_url",
|
||||
"image_url": {"url": f"data:image/{item[0].lower()};base64,{item[1]}"},
|
||||
"image_url": {"url": f"data:image/{mime_suffix};base64,{item[1]}"},
|
||||
}
|
||||
)
|
||||
elif isinstance(item, str):
|
||||
|
|
|
|||
Loading…
Reference in New Issue