Repository navigation
Conversation
GeminiPart.Text is a string with omitempty, so a replayed closing chunk
{"text": ""} was re-marshaled as {}. Gemini treats Part.data as a oneof
and rejects such a part with "required oneof field 'data' must have one
initialized field".
GeminiPart now emits "text" when it is the only data field, except for
parts decoded from JSON without a text member, which still marshal as {}
so unrecognized content fails upstream instead of becoming empty text.
|
No actionable comments were generated in the recent review. WalkthroughGeminiPart now tracks whether decoded JSON omitted the ChangesGemini text round trips
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk:
|
English template:
.github/PULL_REQUEST_TEMPLATE/en.mdImportant
🔗 关联任务 / Related Issue
system_instruction,后来原生路径会清掉全空的 systemInstruction,但contents里的空 part 没有处理)。🚀 变更类型 / Type of change
📝 变更描述 / Description
Gemini 原生接口回放历史时,模型输出里常见的空文本尾块
{"text": ""}(开启 thinking + 工具调用时,签名挂在functionCall上,尾块就是裸的空 text)经过 new-api 重新序列化后变成{},上游返回:原因是
GeminiPart.Text为string+omitempty。{"text": "", "thoughtSignature": "..."}也会被改成{"thoughtSignature": "..."},同样丢了 text。修复:给
GeminiPart加MarshalJSON,当 text 是唯一的 data 字段时即使为空也输出"text"。从 JSON 解码时没有text成员的 part(例如无法识别的字段)仍然输出{},让上游报错,而不是悄悄变成空文本。没有把Text改成*string,避免改动所有转换器。📸 运行证明 / Proof of Work
本地 SQLite 起一个干净实例(
go build -o new-api . && ./new-api),建一个 Gemini 类型渠道,Base URL 填http://127.0.0.1:8081,模型gemini-2.5-flash,再建一个令牌。上游用下面的脚本(python3 mock_upstream.py 8081),它会打印收到的请求体。mock_upstream.py
请求:
上游收到的两个空 text part(
jq -c '[.contents[1].parts[2], .contents[3].parts[1]]'):cb074d31e):[{},{"thoughtSignature":"c2lnLTI="}]1efdfb593):[{"text":""},{"text":"","thoughtSignature":"c2lnLTI="}]同一请求里的
thought、带签名的functionCall、functionResponse修复前后一致。另外在 LibreChat + Gemini(thinking + 工具调用)的真实对话里,修复前第二轮(回传工具结果)报上述 400,修复后正常。
单元测试:
relaykit/dto/gemini_part_test.go覆盖各类 part 的解码再编码;common/json_test.go加了一条走宿主 JSON 编解码 +DeepCopy的用例(原生路径会经过这两步)。两者在 main 上均失败。✅ 提交前检查项 / Checklist
New feature,我已关联对应 Issue;若尚无 Issue,我已先自行创建。go build通过或测试通过,不视为有效证明。Summary by CodeRabbit