fix(gemini): normalize nullable and literal tool schemas - #6777
fix(gemini): normalize nullable and literal tool schemas#6777hedgeho9X wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. WalkthroughThe change adds Gemini schema normalization for ChangesGemini schema normalization
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant OpenAI tool schema
participant OpenAI request converter
participant Gemini schema cleaner
participant Gemini function declaration
OpenAI tool schema->>OpenAI request converter: provide tool parameters
OpenAI request converter->>Gemini schema cleaner: pass converted schema
Gemini schema cleaner->>Gemini schema cleaner: normalize const and anyOf
Gemini schema cleaner->>Gemini function declaration: return cleaned parameters
Merge Risk: ⚪ Minimal · up to The change normalizes unsupported Gemini tool schemas while preserving nullable, literal, and constrained-value semantics. Current evidence shows no merge-blocking correctness or production-impact risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit checked the schema bright, Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
relaykit/relayconvert/internal/shared/gemini/schema_test.go (1)
10-53: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for same-type non-enum
anyOfbranches.Lines 160-168 preserve
anyOfwhile adding a parenttype. Add a test with twoSTRINGbranches that contain different constraints. Assert that the parent hastype: "STRING"and that both branch constraints remain inanyOf.As per coding guidelines: “Backend tests must protect real behavior, API contracts, billing/accounting invariants, compatibility, or regression paths.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@relaykit/relayconvert/internal/shared/gemini/schema_test.go` around lines 10 - 53, Add a focused test for CleanFunctionParameters using an anyOf with two string branches carrying different non-enum constraints, such as distinct pattern or format values. Assert the normalized parent has type "STRING", preserve both branch schemas in anyOf, and verify their constraints remain unchanged.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@relaykit/relayconvert/internal/shared/gemini/schema.go`:
- Around line 123-131: Update normalizeGeminiSchemaConst to preserve the const
restriction when schema["enum"] already exists: replace the enum with the single
const value or intersect it so values other than constValue are removed before
const is later deleted.
---
Nitpick comments:
In `@relaykit/relayconvert/internal/shared/gemini/schema_test.go`:
- Around line 10-53: Add a focused test for CleanFunctionParameters using an
anyOf with two string branches carrying different non-enum constraints, such as
distinct pattern or format values. Assert the normalized parent has type
"STRING", preserve both branch schemas in anyOf, and verify their constraints
remain unchanged.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5d1c8d67-4788-4e2e-ae5a-63256a40784e
📒 Files selected for processing (4)
relaykit/relayconvert/internal/oai_chat/to_gemini_chat_req_test.gorelaykit/relayconvert/internal/oai_responses/to_gemini_chat_req_test.gorelaykit/relayconvert/internal/shared/gemini/schema.gorelaykit/relayconvert/internal/shared/gemini/schema_test.go
51fdfc5 to
2b6f1df
Compare
Important
📝 变更描述 / Description
修复 OpenAI Chat Completions / Responses 转 Gemini
generateContent时,tool function parameters 中的 JSON Schema union 不符合 Gemini OpenAPI Schema 约束的问题。之前
string | null会被转换成一个本身没有type的anyOf,导致 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。type+enum。anyOf补充父层type,同时保留原有分支约束。const。修复位于
relaykit共享转换层,因此同时覆盖 Gemini 渠道、Vertex Gemini 模式和使用相同 converter 的 Advanced Custom 路由。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
📸 运行证明 / Proof of Work
cd relaykit && GOWORK=off go test ./...cd relaykit && GOWORK=off go build ./...cd relaykit && GOWORK=off go vet ./...mainpackage 外的 Go packages 测试通过;mainpackage 在本地因未生成web/distembed 产物而无法 setup,与本次 relaykit 改动无关。Summary by CodeRabbit
Bug Fixes
Tests