Skip to content

fix: 支持传入system_instruction和systemInstruction两种风格系统提示词参数名 - #2450

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/gemini-system-prompt
Dec 26, 2025
Merged

Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/gemini-system-prompt

Conversation

@seefs001

@seefs001 seefs001 commented Dec 16, 2025 •

Copy link
Copy Markdown
Collaborator

fix #2448
https://github.com/googleapis/go-genai/blob/a7c0ed8b1fcade06ffcc62a91344e36e56d17f37/types.go#L2075
Golang SDK支持传入systemInstruction,Python SDK支持传入system_instruction,兼容两种方式,最终以systemInstruction作为参数发送

Summary by CodeRabbit

  • Improvements
    • API now accepts system configuration parameters in multiple naming formats for improved compatibility with diverse integration styles.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 16, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

A new UnmarshalJSON method was added to GeminiChatRequest in dto/gemini.go to support deserializing JSON with both snake_case (system_instruction) and camelCase (systemInstruction) field names, using an alias type to conditionally map between the two naming conventions.

Changes

Cohort / File(s) Summary
JSON Deserialization Enhancement
dto/gemini.go
Added UnmarshalJSON method to GeminiChatRequest to accept both snake_case and camelCase field naming during JSON deserialization while preserving existing field structure.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5–10 minutes

  • Verify the alias type pattern correctly handles both naming conventions without edge cases
  • Confirm that the conditional mapping between system_instruction and SystemInstructions preserves existing behavior

Poem

🐰 Hop, skip, and a snake to camel bound—
Two naming styles, now both are found!
No breaking changes, just harmony,
Flexibility's the key, you see! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding support for both snake_case (system_instruction) and camelCase (systemInstruction) parameter names for system prompts in Gemini requests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11593bd and 2a511c6.

📒 Files selected for processing (1)
  • dto/gemini.go (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: RedwindA
Repo: QuantumNous/new-api PR: 1537
File: relay/gemini_handler.go:330-342
Timestamp: 2025-08-08T17:12:43.157Z
Learning: In the new-api repository, the `GeminiEmbeddingHandler` function in `relay/gemini_handler.go` is designed specifically for native Gemini embedding requests and therefore does not require the `ConvertGeminiRequest` step that is used in the chat handler. The embedding requests are already in the native Gemini format and don't need conversion.
📚 Learning: 2025-08-08T17:12:43.157Z
Learnt from: RedwindA
Repo: QuantumNous/new-api PR: 1537
File: relay/gemini_handler.go:330-342
Timestamp: 2025-08-08T17:12:43.157Z
Learning: In the new-api repository, the `GeminiEmbeddingHandler` function in `relay/gemini_handler.go` is designed specifically for native Gemini embedding requests and therefore does not require the `ConvertGeminiRequest` step that is used in the chat handler. The embedding requests are already in the native Gemini format and don't need conversion.

Applied to files:

  • dto/gemini.go
🧬 Code graph analysis (1)
dto/gemini.go (3)
relay/common/relay_info.go (1)
  • Alias (534-534)
dto/openai_image.go (2)
  • Alias (50-50)
  • Alias (70-70)
common/json.go (1)
  • Unmarshal (9-11)
🔇 Additional comments (1)
dto/gemini.go (1)

25-44: Implementation correctly supports both parameter naming conventions.

The custom unmarshaler follows the established pattern in this file and correctly:

  • Accepts both system_instruction (snake_case) and systemInstruction (camelCase) on input
  • Marshals output using systemInstruction (camelCase) as specified in the JSON tag on line 21
  • Uses the type alias pattern to avoid recursion
  • Handles precedence (snake_case takes priority if both are provided)

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Calcium-Ion
Calcium-Ion merged commit a4cd84f into QuantumNous:main Dec 26, 2025
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…rompt

fix: 支持传入system_instruction和systemInstruction两种风格系统提示词参数名
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…rompt

fix: 支持传入system_instruction和systemInstruction两种风格系统提示词参数名
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
…rompt

fix: 支持传入system_instruction和systemInstruction两种风格系统提示词参数名
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.

gemini原生格式请求gemini模型,system_instruction根本不生效

2 participants