Repository navigation
Conversation
📝 WalkthroughWalkthroughThis PR centralizes chat request-body construction in ChangesChat request construction
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 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: 6
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
internal/entity/models/tokenhub.go (1)
153-170: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winReject non-streaming config before streaming requests.
buildRequestBody(..., true)always sets"stream": true, so these streaming entrypoints now ignore a caller-suppliedchatModelConfig.Stream == falseand proceed with SSE. Add a guard before building the request, or centralize this validation, for consistency acrossChatStreamlyWithSender.
internal/entity/models/tokenhub.go#L153internal/entity/models/tokenpony.go#L137internal/entity/models/stepfun.go#L137🤖 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/tokenhub.go` around lines 153 - 170, Reject configurations with Stream set to false before building or sending streaming requests in ChatStreamlyWithSender. Apply the same validation consistently at internal/entity/models/tokenhub.go:153-170, internal/entity/models/tokenpony.go:137-157, and internal/entity/models/stepfun.go:137-156, preserving the existing request flow for valid streaming configurations.internal/entity/models/ollama.go (1)
180-190: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winGuard
modelConfigbefore dereferencing it inChatStreamlyWithSender.The streaming path builds a request with a nil-safe
modelConfig, but then accessesmodelConfig.Effort/modelConfig.Thinkingwithout a nil check, whileChatWithMessagesguards that block. Mirror the non-stream guard or return early whenmodelConfig == nilbefore applyingthink.🤖 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 180 - 190, Guard the think-configuration logic in ChatStreamlyWithSender with a nil check for modelConfig before accessing Effort or Thinking. Mirror the existing modelConfig guard used by ChatWithMessages, preserving the current Effort and Thinking behavior when configuration is present.
🧹 Nitpick comments (1)
internal/entity/models/astraflow.go (1)
88-89: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove the empty
if chatModelConfig != nil {}block.This is a leftover no-op after the refactor and dead code.
As per coding guidelines: "Remove dead tests, commented-out code, stale documentation..."♻️ Proposed 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 {}` block from the surrounding model configuration logic, leaving the remaining `chatModelConfig` handling 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 `@internal/entity/models/base_model.go`:
- Around line 253-260: Update the tool injection condition in buildRequestBody
to use len(cfg.Tools) > 0 instead of only checking cfg.Tools != nil, so empty
tool collections add neither "tools" nor "tool_choice"; preserve the existing
tool-choice selection for non-empty tools.
In `@internal/entity/models/cohere.go`:
- Around line 71-76: Remove the generic top_p field from the request body before
applying the Cohere-specific p value in both ChatWithMessages and
ChatStreamlyWithSender. Update the request-building logic at
internal/entity/models/cohere.go lines 71-76 and 178-183 so only p is sent to
the native Cohere API.
In `@internal/entity/models/deepseek.go`:
- Around line 78-108: The ChatWithMessages effort handling switch must reject
unrecognized effort values instead of sending an empty thinking type. Add a Go
fallback branch to the switch around ChatWithMessages that returns
fmt.Errorf("invalid effort level"), matching ChatStreamlyWithSender, while
preserving all existing recognized effort mappings.
In `@internal/entity/models/futurmix.go`:
- Around line 186-207: Update the FuturMix streaming method around
buildRequestBody and the request creation: pass true for the stream flag, use
streamCallTimeout for the context, and set the required Content-Type and
Authorization headers on req before calling f.baseModel.httpClient.Do.
- Around line 116-140: Update the request construction in the FuturMix chat
method around http.NewRequestWithContext to restore the headers previously
applied by newFuturMixJSONRequest: set Content-Type to application/json and
Authorization to Bearer plus the configured API key before calling
f.baseModel.httpClient.Do(req).
In `@internal/entity/models/huggingface.go`:
- Around line 174-176: Guard the streaming thinking checks against nil model
configuration before reading Thinking. In internal/entity/models/huggingface.go
lines 174-176 and internal/entity/models/lmstudio.go lines 193-194, update the
conditions around modelConfig.Thinking to require modelConfig != nil while
preserving the existing thinking behavior when configuration is present.
---
Outside diff comments:
In `@internal/entity/models/ollama.go`:
- Around line 180-190: Guard the think-configuration logic in
ChatStreamlyWithSender with a nil check for modelConfig before accessing Effort
or Thinking. Mirror the existing modelConfig guard used by ChatWithMessages,
preserving the current Effort and Thinking behavior when configuration is
present.
In `@internal/entity/models/tokenhub.go`:
- Around line 153-170: Reject configurations with Stream set to false before
building or sending streaming requests in ChatStreamlyWithSender. Apply the same
validation consistently at internal/entity/models/tokenhub.go:153-170,
internal/entity/models/tokenpony.go:137-157, and
internal/entity/models/stepfun.go:137-156, preserving the existing request flow
for valid streaming configurations.
---
Nitpick comments:
In `@internal/entity/models/astraflow.go`:
- Around line 88-89: Remove the empty no-op `if chatModelConfig != nil {}` block
from the surrounding model configuration logic, leaving the remaining
`chatModelConfig` handling unchanged.
🪄 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: 9fe367e2-035d-4197-91bc-abb5d8dd6cc3
📒 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
|
github bug, can not update this PR, so, close and open a new PR |
Summary
As title