fix(api): improve multimodal compatibility (snake_case fields, URL-safe base64, GIF to PNG) - #22
Merged
Conversation
Contributor
Author
|
补充更新: 除 URL-safe Base64 容错外,本 PR 进一步补充了对 的自动转换支持:
|
…) and optimize base64 decoding
Owner
|
非常感谢~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题背景 (Background)
在多模态图片/媒体输入场景中,存在以下三个兼容性问题:
下划线字段兼容性缺失 (snake_case fields):
部分中转工具(如 CLIProxyAPI / CPA)或基于 Google Python SDK 的客户端在向 Gemini 原生接口 (/v1beta/models/...:streamGenerateContent) 发送附件时,会将字段命名为下划线风格(如 inline_data、ile_data、mime_type、ile_uri)。此前 geminiPart 结构体仅声明了驼峰 tag,导致 Go 的 JSON 反序列化后 MIMEType 为空,从而触发 HTTP 400 · inlineData requires mimeType and data 错误。
URL-safe Base64 编码与 Data URL 前缀容错:
部分官方 SDK(如 Python Google GenAI SDK)和第三方客户端在序列化 Base64 时会生成 URL-safe 编码(使用 -、_ 且省略尾部 = 填充),或者包含 data:image/...;base64, 前缀。此前直接调用 �ase64.StdEncoding.DecodeString 会抛出 illegal base64 data 400 错误。
Google AI Studio 对 GIF 格式的不支持:
Google AI Studio 官方网页与底层 API 不支持直接接收 image/gif 输入,上传或调用时会抛出协议错误码 3 (Unable to process input image)。
修复内容 (Changes)
ormalizeImagePayload):