Skip to content

feat: map OpenAI developer role to Gemini system instructions - #2536

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
RedwindA:feat/oaiDevRole2Gemini
Dec 28, 2025
Merged

seefs001 merged 1 commit into
QuantumNous:mainfrom
RedwindA:feat/oaiDevRole2Gemini

Conversation

@RedwindA

@RedwindA RedwindA commented Dec 26, 2025 •

Copy link
Copy Markdown
Contributor

close #2506

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced system message processing to treat developer-role messages the same as system-role messages in Gemini API integration, ensuring proper system instruction handling.

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

@coderabbitai

coderabbitai Bot commented Dec 26, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Modified the CovertOpenAI2Gemini function in the Gemini relay to treat messages with role "developer" identically to "system" role messages when collecting system content for Gemini API requests.

Changes

Cohort / File(s) Summary
Developer role handling in OpenAI-to-Gemini conversion
relay/channel/gemini/relay-gemini.go
Updated system content collection logic to include "developer" role messages alongside "system" role messages when building Gemini system instructions

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A developer's voice now finds its place,
In system instructions, right alongside grace,
No longer lost in parts and redirects,
The Gemini conversion now truly connects! ✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: mapping OpenAI's developer role to Gemini's system instructions, which aligns with the PR's core objective.
Linked Issues check ✅ Passed The code change treats developer role messages as system content in CovertOpenAI2Gemini, directly addressing issue #2506's requirement to include developer role messages in Gemini's systemInstruction field.
Out of Scope Changes check ✅ Passed All changes are scoped to the developer role to system instruction mapping in the relay-gemini.go file, with no extraneous modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9aeef6a and 1de78f8.

📒 Files selected for processing (1)
  • relay/channel/gemini/relay-gemini.go
🧰 Additional context used
🧠 Learnings (3)
📓 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:

  • relay/channel/gemini/relay-gemini.go
📚 Learning: 2025-06-21T03:37:41.726Z
Learnt from: 9Ninety
Repo: QuantumNous/new-api PR: 1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.

Applied to files:

  • relay/channel/gemini/relay-gemini.go
🔇 Additional comments (1)
relay/channel/gemini/relay-gemini.go (1)

377-379: Implementation correctly maps developer role to system instructions.

The change appropriately treats "developer" role messages the same as "system" role messages, collecting them into system_content which is later used to populate Gemini's SystemInstructions field (lines 611-619). This directly addresses issue #2506 and enables proper mapping of modern OpenAI models (o-series, gpt-5) which use "developer" as the system-level role.

When both "system" and "developer" messages exist, they'll be concatenated in the order they appear in the message array, joined with newlines. This behavior is correct and necessary since OpenAI's adaptor converts system role to developer for compatible models before the request reaches the Gemini relay handler.


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.

@seefs001
seefs001 merged commit 1a69a93 into QuantumNous:main Dec 28, 2025
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
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.

支持OpenAI格式到Gemini格式时把role为developer的消息加入systemInstruction

2 participants