Skip to content

fix(gemini): normalize nullable and literal tool schemas - #2

Open
jerry-airjelly wants to merge 2 commits into
mainfrom
fix/gemini-tool-schema-normalization
Open

fix(gemini): normalize nullable and literal tool schemas#2
jerry-airjelly wants to merge 2 commits into
mainfrom
fix/gemini-tool-schema-normalization

Conversation

@jerry-airjelly

Copy link
Copy Markdown
Member

⚠️ 提交说明 / PR Notice

Important

  • 本 PR 的实现与测试由提交者使用 AI Coding Agent 协助完成,描述已根据实际代码路径整理。

📝 变更描述 / Description

修复 OpenAI Chat Completions / Responses 转 Gemini generateContent 时,tool function parameters 中的 JSON Schema union 不符合 Gemini OpenAPI Schema 约束的问题。

之前 string | null 会被转换成一个本身没有 typeanyOf,导致 Gemini / Vertex 在提交 function declaration 时返回 schema didn't specify the schema type field。TypeBox literal union 里的 const 也会被 allowlist 静默丢弃,使枚举约束失效。

现在共享 Gemini schema cleaner 会:

  • 将单一具体类型与 null 的 union 折叠为明确 type + nullable: true
  • 将同类型 literal union 折叠为明确 type + enum
  • 对其他同类型 anyOf 补充父层 type,同时保留原有分支约束。
  • 在发送上游前删除 Gemini 不支持的 const

修复位于 relaykit 共享转换层,因此同时覆盖 Gemini 渠道、Vertex Gemini 模式和使用相同 converter 的 Advanced Custom 路由。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • 暂无对应 Issue;错误由 Gemini / Vertex function declaration 校验稳定复现。

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 已搜索现有 Issues 与 PRs,未发现相同的 nullable/literal tool schema 修复。
  • Bug fix 说明: 当前未关联 Issue;PR 中已写明上游 400 的稳定触发条件。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已运行 relaykit 定向与全量测试、独立 build 及 vet。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

  • cd relaykit && GOWORK=off go test ./...
  • cd relaykit && GOWORK=off go build ./...
  • cd relaykit && GOWORK=off go vet ./...
  • 根仓除 main package 外的 Go packages 测试通过;main package 在本地因未生成 web/dist embed 产物而无法 setup,与本次 relaykit 改动无关。
  • 回归测试覆盖共享 cleaner、Chat Completions 接线和 Responses 接线。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants