feat: jimeng task query use correct req_key - #2364
Conversation
…-embedding-token-count fix: gemini batch embedding token not counted
fix: handle JSON parsing for thinking content in ollama stream
…-emotion 豆包语音2.0音色支持情感,情绪,音量
Comment out the debug log for MiniMax TTS Request.
增加MiniMax语音合成TTS支持
…ort-stream-options Ali channel support stream options
…ream feat: openai tts support streaming realtime audio
…ream feat: doubao tts support streaming realtime audio
multipart/form-data; boundary
…edit 修复豆包图像编辑(图生图)功能
…emini-image-edit Revert "Gemini Image系列支持图像编辑"
…ix-nano-banana-err Revert "fix: nano-banana not compatible imageSize"
…dd-gemini-3-pro-image-preview-oai Revert "OAI生图接口支持gemini 3 pro image preview"
…dels (Midjourney, Rerank, Suno). Add OpenAPI specifications for backend management and relay interfaces.
…i-turn feat(gemini): implement markdown image handling in text processing
chore: update openapi files
chore: update the relay openapi file
- Introduced new OpenAI text models in `common/model.go`. - Added `IsOpenAITextModel` function to check for OpenAI text models. - Refactored token estimation methods across various channels to use estimated prompt tokens instead of direct prompt token counts. - Updated related functions and structures to accommodate the new token estimation approach, enhancing overall token management.
fix: try resolve the high concurrency issue to a single host
…ken-counter feat: refactor token estimation logic
…king-level feat: gemini 3 thinking level gemini-3-pro-preview-high
WalkthroughAdded a "req_key" parameter to the FetchTask payload using UpstreamModelName from task properties. Refactored the jimeng adaptor to retrieve task requests via a centralized helper and extract req_key from the request body instead of manual parsing. Simplified key signing logic by removing combined key parsing. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
controller/task_video.go(1 hunks)relay/channel/task/jimeng/adaptor.go(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
controller/task_video.go (1)
model/task.go (1)
Properties(75-79)
relay/channel/task/jimeng/adaptor.go (1)
relay/common/relay_utils.go (1)
GetTaskRequest(62-72)
🔇 Additional comments (4)
relay/channel/task/jimeng/adaptor.go (3)
123-126: LGTM! Good refactoring to centralized helper.Using
relaycommon.GetTaskRequest(c)instead of direct context extraction improves maintainability and ensures consistent error handling across the codebase.
244-244: LGTM! Good simplification of signing logic.Using the pre-parsed
a.accessKeyanda.secretKey(set inInitat lines 89-94) instead of re-parsing the combined key improves efficiency and reduces code duplication.
166-166: Add validation for non-empty body.ReqKey.While
info.UpstreamModelNameis set frombody.ReqKeyto enable correct req_key propagation to task queries, there's no validation thatbody.ReqKeyis non-empty. If the original request has an emptymodelfield, this could propagate empty values through the system, eventually causing FetchTask failures.Consider adding validation before this assignment:
+ if body.ReqKey == "" { + return nil, fmt.Errorf("req_key cannot be empty") + } info.UpstreamModelName = body.ReqKey⛔ Skipped due to learnings
Learnt from: RedwindA Repo: QuantumNous/new-api PR: 1517 File: controller/channel.go:196-196 Timestamp: 2025-08-06T17:09:08.221Z Learning: In the channel management system, channel keys are validated as required during channel creation, so they are guaranteed to be non-empty in functions like FetchUpstreamModels. Additional validation for empty keys in downstream functions is not needed.controller/task_video.go (1)
76-80: Verify impact on existing tasks without UpstreamModelName.The addition of
req_keyderived fromtask.Properties.UpstreamModelNamemay break status queries for tasks created before this change. Verify that:
- Existing pending tasks have
UpstreamModelNamepopulated, or tasks fail gracefully when it's empty.- The validation in
adaptor.go(lines 223-227) handles empty/missingreq_keyappropriately—either by rejecting strictly or providing a fallback.- Whether a migration is needed for backward compatibility with tasks created before this field was added.
| if reqKey, ok := body["req_key"].(string); !ok { | ||
| return nil, fmt.Errorf("invalid req_key") | ||
| } else { | ||
| payload["req_key"] = reqKey | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major
Enhance validation to reject empty req_key.
The validation checks that req_key exists and is a string, but doesn't verify it's non-empty. An empty string would pass validation but likely cause upstream API failures.
Apply this diff to add empty string validation:
- if reqKey, ok := body["req_key"].(string); !ok {
+ if reqKey, ok := body["req_key"].(string); !ok || reqKey == "" {
- return nil, fmt.Errorf("invalid req_key")
+ return nil, fmt.Errorf("invalid or empty req_key")
} else {
payload["req_key"] = reqKey
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if reqKey, ok := body["req_key"].(string); !ok { | |
| return nil, fmt.Errorf("invalid req_key") | |
| } else { | |
| payload["req_key"] = reqKey | |
| } | |
| if reqKey, ok := body["req_key"].(string); !ok || reqKey == "" { | |
| return nil, fmt.Errorf("invalid or empty req_key") | |
| } else { | |
| payload["req_key"] = reqKey | |
| } |
🤖 Prompt for AI Agents
In relay/channel/task/jimeng/adaptor.go around lines 223 to 227, the current
validation only checks that body["req_key"] is a string but allows an empty
string; update the check to reject empty strings as well by verifying reqKey !=
"" and returning an error (e.g., fmt.Errorf("invalid req_key")) if it's empty,
otherwise assign payload["req_key"] = reqKey.
优化即梦任务查询, 严格按官方文档不同模型使用对应的req_key参数执行查询
文档: https://www.volcengine.com/docs/85621/1777001
Summary by CodeRabbit
Bug Fixes
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.