Repository navigation
refactor: the request body build - #17286
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (8)
📝 WalkthroughWalkthroughChat model integrations now use shared helpers for non-streaming and streaming request payloads. Provider-specific reasoning, thinking, tool, URL, and stream-option handling remains where required, while several legacy request builders and request types are removed. ChangesChat request refactor
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (1 warning, 2 inconclusive)
✅ Passed checks (2 passed)
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: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (5)
internal/entity/models/futurmix.go (2)
112-120: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winMissing
modelNamevalidation inChatWithMessages.Unlike every sibling provider migrated in this same layer (avian, cometapi, n1n, ppio),
ChatWithMessagesno longer validates thatmodelNameis non-empty before building the request. This was dropped during the request-building rewrite.🤖 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 `@internal/entity/models/futurmix.go` around lines 112 - 120, Add a non-empty modelName validation to FuturMixModel.ChatWithMessages before request construction, matching the validation behavior used by the sibling provider implementations. Return the established validation error for an empty modelName while preserving the existing APIConfigCheck and messages validation.
180-188: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick winValidation guards dropped in FuturMix's request-building rewrite. Both
ChatWithMessagesandChatStreamlyWithSenderlost guards that every sibling provider (avian, cometapi, n1n, ppio, modelscope, xinference) retained after the samebuildRequestBodymigration.
internal/entity/models/futurmix.go#L180-L188: restore thesender == nil,modelNameempty, andchatModelConfig.Stream == falseguards inChatStreamlyWithSenderbefore building the request —senderis invoked unconditionally later (sender(nil, &r),sender(&endOfStream, nil)), so a nilsenderwill panic.internal/entity/models/futurmix.go#L112-L120: restore themodelNamenon-empty validation inChatWithMessagesbefore building the request, matching the sibling providers.🛡️ Proposed fix restoring the dropped guards
func (f *FuturMixModel) ChatWithMessages(ctx context.Context, modelName string, messages []Message, apiConfig *APIConfig, chatModelConfig *ChatConfig, modelUsage *common.ModelUsage) (*ChatResponse, error) { if err := f.baseModel.APIConfigCheck(apiConfig); err != nil { return nil, err } + + if strings.TrimSpace(modelName) == "" { + return nil, fmt.Errorf("model name is required") + } if len(messages) == 0 { return nil, fmt.Errorf("messages is empty") }func (f *FuturMixModel) ChatStreamlyWithSender(ctx context.Context, modelName string, messages []Message, apiConfig *APIConfig, chatModelConfig *ChatConfig, modelUsage *common.ModelUsage, sender func(*string, *string) error) error { if err := f.baseModel.APIConfigCheck(apiConfig); err != nil { return err } + + if sender == nil { + return fmt.Errorf("sender is required") + } + if strings.TrimSpace(modelName) == "" { + return fmt.Errorf("model name is required") + } if len(messages) == 0 { return fmt.Errorf("messages is empty") } + if chatModelConfig != nil && chatModelConfig.Stream != nil && !*chatModelConfig.Stream { + return fmt.Errorf("stream must be true in ChatStreamlyWithSender") + }🤖 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 `@internal/entity/models/futurmix.go` around lines 180 - 188, Restore the dropped request validations in internal/entity/models/futurmix.go at ChatStreamlyWithSender (lines 180-188): reject a nil sender, empty modelName, and chatModelConfig.Stream == false before building the request. Also update ChatWithMessages (lines 112-120) to reject an empty modelName before request construction, matching sibling providers.internal/entity/models/cohere.go (1)
70-89: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winRemap Cohere generic-body fields to Cohere v2 payload names.
buildRequestBodywritestop_p,stop,tools, andtool_choicebefore Cohere remapping. Cohere usespfor nucleus sampling andstop_sequencesfor stop strings, but the request only addspwhile leavingtop_pand sendingstop/tools/tool_choiceunchanged. Apply this remapping/removal in bothChatWithMessagesandChatStreamlyWithSender.🤖 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 `@internal/entity/models/cohere.go` around lines 70 - 89, Update ChatWithMessages and ChatStreamlyWithSender after buildRequestBody to remap Cohere fields: move top_p to p, rename stop to stop_sequences, and map tools and tool_choice to their Cohere v2 payload names, removing the generic keys so both request paths send only the correct fields.internal/entity/models/openrouter.go (1)
177-184: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
reasoningis overwritten when bothThinkingandEffortare set.Each
ifassigns a fresh map toreqBody["reasoning"], so when both are non-nil theEffortbranch discards the{"enabled": ...}set by theThinkingbranch. Merge into a single map instead of two independent assignments.🔧 Merge reasoning fields
if modelConfig != nil { - if modelConfig.Thinking != nil { - reqBody["reasoning"] = map[string]interface{}{"enabled": *modelConfig.Thinking} - } - if modelConfig.Effort != nil { - reqBody["reasoning"] = map[string]interface{}{"effort": *modelConfig.Effort} - } + reasoning := map[string]interface{}{} + if modelConfig.Thinking != nil { + reasoning["enabled"] = *modelConfig.Thinking + } + if modelConfig.Effort != nil { + reasoning["effort"] = *modelConfig.Effort + } + if len(reasoning) > 0 { + reqBody["reasoning"] = reasoning + } }🤖 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 `@internal/entity/models/openrouter.go` around lines 177 - 184, Update the reasoning construction in the model request body so Thinking and Effort fields are merged into one map when both are non-nil. Initialize or reuse a single reqBody["reasoning"] map, then assign each applicable field without replacing previously added values.internal/entity/models/ollama.go (1)
182-190: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick winGuard
modelConfigbefore readingEffort/Thinking.
buildRequestBodyaccepts a nilChatConfig, but the streaming block dereferencesmodelConfig.Effortbefore null checks, so a nil config can panic after request body construction. Wrap this section inif modelConfig != nil { ... }, like the non-streaming path.🤖 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 `@internal/entity/models/ollama.go` around lines 182 - 190, Guard the Effort/Thinking handling in buildRequestBody with a modelConfig != nil check before accessing either field. Preserve the existing GPT-OSS effort and boolean Thinking behavior inside this guard, matching the non-streaming path so nil ChatConfig values do not panic.
🧹 Nitpick comments (3)
internal/entity/models/astraflow.go (1)
88-89: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove leftover empty
if chatModelConfig != nil {}block.This conditional is now a no-op after the refactor to
buildRequestBody.As per coding guidelines, "Remove dead tests, commented-out code, stale documentation, and 'move later' notes."🧹 Suggested cleanup
reqBody := buildRequestBody(chatModelConfig, modelName, messages, false) - if chatModelConfig != nil { - } - jsonData, err := json.Marshal(reqBody)🤖 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 `@internal/entity/models/astraflow.go` around lines 88 - 89, Remove the empty no-op if chatModelConfig != nil conditional from buildRequestBody, leaving the surrounding request-body construction unchanged.Source: Coding guidelines
internal/entity/models/huaweicloud.go (1)
190-192: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueMake Huawei Cloud tool configuration consistent between streaming and non-streaming requests.
buildRequestBodyalready setstoolsandtool_choice, but both Huawei Cloud paths also callhuaweiCloudApplyChatConfig. Remove the redundant calls from both paths, or add the missing stream path call before marshaling if that helper applies Huawei-specific tool semantics.🤖 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 `@internal/entity/models/huaweicloud.go` around lines 190 - 192, Make tool configuration consistent in both Huawei Cloud streaming and non-streaming request paths: inspect huaweiCloudApplyChatConfig and buildRequestBody, then either remove the redundant helper calls from both paths or invoke the helper in the streaming path before marshaling if it applies required Huawei-specific tool semantics. Preserve a single consistent source of tool and tool_choice configuration.internal/entity/models/openrouter.go (1)
72-78: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueNit: pass the dereferenced value for consistency. The non-stream path stores
chatModelConfig.Effort(a*string) while the stream path stores*modelConfig.Effort. JSON marshaling dereferences the pointer so output is equivalent, but aligning the two avoids confusion.🤖 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 `@internal/entity/models/openrouter.go` around lines 72 - 78, Update the non-stream reasoning payload in the chatModelConfig handling to store the dereferenced Effort value rather than the pointer, matching the stream path’s use of *modelConfig.Effort while preserving the existing reasoning structure.
🤖 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 `@internal/entity/models/base_model.go`:
- Around line 253-260: Converge HuaweiCloud tool configuration to a single
application point: update HuaweiCloudModel.ChatWithMessages and the
buildRequestBody/applyChatToolConfig flow so tool settings are not applied
twice. Preserve explicit and default "auto" ToolChoice values and the configured
tools, using one helper as the sole source of request-body tool configuration.
- Around line 225-239: Remove the hardcoded temperature: 1 entry from the shared
request body built by buildRequestBody, allowing cfg.Temperature to be included
only when explicitly configured. Preserve provider-specific defaults by applying
any required fallback in the relevant provider path rather than the generic
payload.
In `@internal/entity/models/deepseek.go`:
- Around line 78-108: Add a default branch to the non-stream effort switch that
returns the same unknown-effort error as the streaming path, preventing an empty
thinking.type from being sent. Remove the redundant break statements from the
switch cases while preserving the existing mappings for recognized efforts.
In `@internal/entity/models/siliconflow.go`:
- Around line 188-194: Update ChatStreamlyWithSender to forward an explicitly
configured chatModelConfig.Thinking value into reqBody["enable_thinking"],
matching ChatWithMessages and the corresponding provider implementations.
Preserve the existing qwen3 fallback that sets enable_thinking to false only
when Thinking is nil.
---
Outside diff comments:
In `@internal/entity/models/cohere.go`:
- Around line 70-89: Update ChatWithMessages and ChatStreamlyWithSender after
buildRequestBody to remap Cohere fields: move top_p to p, rename stop to
stop_sequences, and map tools and tool_choice to their Cohere v2 payload names,
removing the generic keys so both request paths send only the correct fields.
In `@internal/entity/models/futurmix.go`:
- Around line 112-120: Add a non-empty modelName validation to
FuturMixModel.ChatWithMessages before request construction, matching the
validation behavior used by the sibling provider implementations. Return the
established validation error for an empty modelName while preserving the
existing APIConfigCheck and messages validation.
- Around line 180-188: Restore the dropped request validations in
internal/entity/models/futurmix.go at ChatStreamlyWithSender (lines 180-188):
reject a nil sender, empty modelName, and chatModelConfig.Stream == false before
building the request. Also update ChatWithMessages (lines 112-120) to reject an
empty modelName before request construction, matching sibling providers.
In `@internal/entity/models/ollama.go`:
- Around line 182-190: Guard the Effort/Thinking handling in buildRequestBody
with a modelConfig != nil check before accessing either field. Preserve the
existing GPT-OSS effort and boolean Thinking behavior inside this guard,
matching the non-streaming path so nil ChatConfig values do not panic.
In `@internal/entity/models/openrouter.go`:
- Around line 177-184: Update the reasoning construction in the model request
body so Thinking and Effort fields are merged into one map when both are
non-nil. Initialize or reuse a single reqBody["reasoning"] map, then assign each
applicable field without replacing previously added values.
---
Nitpick comments:
In `@internal/entity/models/astraflow.go`:
- Around line 88-89: Remove the empty no-op if chatModelConfig != nil
conditional from buildRequestBody, leaving the surrounding request-body
construction unchanged.
In `@internal/entity/models/huaweicloud.go`:
- Around line 190-192: Make tool configuration consistent in both Huawei Cloud
streaming and non-streaming request paths: inspect huaweiCloudApplyChatConfig
and buildRequestBody, then either remove the redundant helper calls from both
paths or invoke the helper in the streaming path before marshaling if it applies
required Huawei-specific tool semantics. Preserve a single consistent source of
tool and tool_choice configuration.
In `@internal/entity/models/openrouter.go`:
- Around line 72-78: Update the non-stream reasoning payload in the
chatModelConfig handling to store the dereferenced Effort value rather than the
pointer, matching the stream path’s use of *modelConfig.Effort while preserving
the existing reasoning structure.
🪄 Autofix (Beta)
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: e76e504c-f623-4945-a6e2-28613e0a1a04
📒 Files selected for processing (51)
internal/entity/models/302ai.gointernal/entity/models/aliyun.gointernal/entity/models/astraflow.gointernal/entity/models/avian.gointernal/entity/models/baichuan.gointernal/entity/models/baidu.gointernal/entity/models/base_model.gointernal/entity/models/cohere.gointernal/entity/models/cometapi.gointernal/entity/models/deepinfra.gointernal/entity/models/deepseek.gointernal/entity/models/futurmix.gointernal/entity/models/gitee.gointernal/entity/models/gpustack.gointernal/entity/models/groq.gointernal/entity/models/huaweicloud.gointernal/entity/models/huggingface.gointernal/entity/models/hunyuan.gointernal/entity/models/jiekouai.gointernal/entity/models/jina.gointernal/entity/models/lmstudio.gointernal/entity/models/localai.gointernal/entity/models/longcat.gointernal/entity/models/minimax.gointernal/entity/models/mistral.gointernal/entity/models/modelscope.gointernal/entity/models/moonshot.gointernal/entity/models/n1n.gointernal/entity/models/novita.gointernal/entity/models/nvidia.gointernal/entity/models/ollama.gointernal/entity/models/openai.gointernal/entity/models/openrouter.gointernal/entity/models/orcarouter.gointernal/entity/models/perplexity.gointernal/entity/models/ppio.gointernal/entity/models/qiniu.gointernal/entity/models/ragcon.gointernal/entity/models/siliconflow.gointernal/entity/models/stepfun.gointernal/entity/models/togetherai.gointernal/entity/models/tokenhub.gointernal/entity/models/tokenpony.gointernal/entity/models/upstage.gointernal/entity/models/vllm.gointernal/entity/models/volcengine.gointernal/entity/models/xai.gointernal/entity/models/xiaomi.gointernal/entity/models/xinference.gointernal/entity/models/xunfei.gointernal/entity/models/zhipu-ai.go
Summary
As title