修复 Gemini 和第三方异步生图接口的兼容性问题 - #125
Open
Hiro674 wants to merge 3 commits into
Open
Conversation
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.
本次修改主要用于修复在线生图在 Gemini 协议和第三方异步协议接口下的图片生成兼容性问题,并优化 Gemini 协议下的图片传入逻辑以达到能够理解图片的效果。
问题说明
部分 Gemini 协议返回的图片内容无法被正确解析,导致前端提示生成结果为空*¹。
在 API 提供商支持异步协议的前提下,部分第三方异步生图接口虽然可以正常返回任务 ID,但最终生成结果可能与提示词或参考图不相关。经核实,目前原有异步生图接口格式主要适配 APIMart,不适用于其他第三方异步协议接口*²。
Gemini 多图参考场景下,虽然图片已传入接口,但多图传入结构对部分接口不够稳定,可能导致接口无法正确识别图片顺序或参考图内容*³。
主要修改:
扩展 Gemini 返回结果的解析兼容性,支持以下图片返回格式:
inlineData/inline_datafileData.fileUri/file_data.file_uri通过以上兼容处理,降低 Gemini 图片结果无法被识别、前端显示为空的概率。
扩展异步任务 ID 的识别范围,兼容更多第三方接口返回字段,包括:
task_idtaskIdjob_idrequest_idgeneration_iddata、result、task、job、output等嵌套结构中提取任务 ID,提升不同异步接口返回结构下的兼容性。针对非 APIMart 的第三方异步生图接口,新增更通用的 OpenAI-compatible JSON 请求格式。
prompt、input、image、image_urls、images本修改未移除 APIMart 的原有异步请求格式。
这样既保证 APIMart 平台的原有逻辑不受影响,也提升了第三方异步接口的可用性。
/v1/tasks/{task_id}/v1/images/tasks/{task_id}以适配不同第三方接口的任务查询路径。
本地测试情况:
这次修改没有针对某个固定模型或固定平台做硬编码,主要是增强不同中转接口和不同返回格式的兼容性。
*¹

修改前结果(实际上是有返回的,本地因为兼容问题无法捕获报错,上游渠道成功捕获并正确返回了生成图片图片)
修改后结果

*²

修改前结果
修改后结果

*³

修改前结果(无法判别图片顺序)
修改后结果(经过测试,绝大多情况下gemini协议的模型可以理清图片顺序,这里我直接使用旧版模型也能理解)

修改后结果2(这种方法的约束力更强,输出结果第一张是修改前结果,无法理解图片顺序和蒙版生成,第二张是修改后能够正确理解各个图片的关系)
