Repository navigation
feat(go-models): migrate batch 2 model drivers to unified handlers - #17697
Conversation
Migrate 10 model drivers (and add shared Chat methods to GreenPT): - gitee (GiteeModel) - gpustack (GPUStackModel) - greenpt (GreenPTModel) - also adds new ChatWithMessages + ChatStreamlyWithSender - huaweicloud (HuaweicloudModel) - huggingface (HuggingfaceModel) - hunyuan (HunyuanModel) - jiekouai (JiekouAIModel) - jina (JinaModel) - lmstudio (LMStudioModel) - localai (LocalAIModel) GreenPT's new shared methods are included here as they are used by the unified handler infrastructure.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe PR migrates ten model drivers to shared ChangesChat handling migration
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant ProviderModel
participant BaseModel
participant ResponseHandler
participant Sender
ProviderModel->>BaseModel: Send chat request
BaseModel->>ResponseHandler: Provide response or SSE events
ResponseHandler->>Sender: Forward streamed content and tool calls
ResponseHandler-->>ProviderModel: Return response or completion status
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 (2)
internal/entity/models/huggingface.go (1)
90-97: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winAdd the missing
sendernil guard in three streaming methods. The migration moved sender invocation intoHandleStreamingResponse, so each caller must reject a nilsenderbefore it starts the request.gpustack.go,hunyuan.go,huaweicloud.go,jiekouai.go, andlocalai.goreturnfmt.Errorf("sender is required"). These three drivers do not, so a nilsenderreaches the shared handler and causes a nil function call at the first stream event.
internal/entity/models/huggingface.go#L90-L97: addif sender == nil { return fmt.Errorf("sender is required") }after theAPIConfigCheckcall.internal/entity/models/lmstudio.go#L103-L110: add the same guard after theAPIConfigCheckcall.internal/entity/models/jina.go#L127-L133: add the same guard in the newChatStreamlyWithSendermethod after theAPIConfigCheckcall.🤖 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/huggingface.go` around lines 90 - 97, Add a nil sender guard after APIConfigCheck in ChatStreamlyWithSender for internal/entity/models/huggingface.go lines 90-97, internal/entity/models/lmstudio.go lines 103-110, and internal/entity/models/jina.go lines 127-133; return fmt.Errorf("sender is required") before starting the request.internal/entity/models/gpustack.go (1)
108-139: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick winUse
baseModel.doStreamRequestfor this stream path.
ChatStreamlyWithSenderrepeats the same timeout,newJSONPostRequestbody, HTTP client call, status check, and response handling asBaseModel.doStreamRequest. Switch this call tog.baseModel.doStreamRequest(...), then remove the now-unused imports if no other code ingpustack.gouses them.If the shared helper becomes SSE-specific, add
Accept: text/event-streamto the common request builder instead of setting it per driver.🤖 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/gpustack.go` around lines 108 - 139, Update ChatStreamlyWithSender to delegate streaming requests to g.baseModel.doStreamRequest, passing the existing request data, model usage, chat configuration, parser configuration, and sender instead of duplicating timeout, request creation, HTTP execution, status validation, and response handling. Remove imports used only by the deleted duplicate logic; if doStreamRequest lacks SSE support, set the text/event-stream Accept header in the shared request builder.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/greenpt.go`:
- Around line 110-118: Update ChatStreamlyWithSender to clear
chatModelConfig.ToolCallsResult and chatModelConfig.UsageResult before starting
the request, matching the shared-handler behavior in gitee.go. Ensure the fields
are reset for every stream, including failed streams and streams without tool
calls.
In `@internal/entity/models/huaweicloud.go`:
- Around line 265-272: Clear UsageResult alongside ToolCallsResult before each
stream in the reset blocks of internal/entity/models/huaweicloud.go lines
265-272 and internal/entity/models/jina.go lines 145-150, preserving the
existing nil guard on chatModelConfig so stale usage data cannot carry into a
new call.
- Around line 225-230: Remove the unused HuaweiCloudChatResponse struct from the
Huawei Cloud model definitions, leaving the HandleNonStreamingResponse flow and
OpenAIParserConfig usage unchanged.
In `@internal/entity/models/jina.go`:
- Around line 127-133: Update JinaModel.ChatStreamlyWithSender to validate
modelName using the same empty-name behavior as ChatWithMessages, and call the
existing validateStreamConfig helper to reject configurations with Stream set to
false before contacting the provider.
---
Outside diff comments:
In `@internal/entity/models/gpustack.go`:
- Around line 108-139: Update ChatStreamlyWithSender to delegate streaming
requests to g.baseModel.doStreamRequest, passing the existing request data,
model usage, chat configuration, parser configuration, and sender instead of
duplicating timeout, request creation, HTTP execution, status validation, and
response handling. Remove imports used only by the deleted duplicate logic; if
doStreamRequest lacks SSE support, set the text/event-stream Accept header in
the shared request builder.
In `@internal/entity/models/huggingface.go`:
- Around line 90-97: Add a nil sender guard after APIConfigCheck in
ChatStreamlyWithSender for internal/entity/models/huggingface.go lines 90-97,
internal/entity/models/lmstudio.go lines 103-110, and
internal/entity/models/jina.go lines 127-133; return fmt.Errorf("sender is
required") before starting the request.
🪄 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: b04f221e-94fa-421e-845c-20ea5c0a8496
📒 Files selected for processing (10)
internal/entity/models/gitee.gointernal/entity/models/gpustack.gointernal/entity/models/greenpt.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.go
HandleStreamingResponse only sets these fields at the end and never clears them at the start, so a failed stream or one without tool calls leaks stale values from a prior request. Clear them up front, matching the shared-handler behavior in gitee.go. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The struct was left behind after ChatWithMessages was migrated to HandleNonStreamingResponse; nothing references it anymore. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ina stream entry - huaweicloud/jina: clear chatModelConfig.UsageResult alongside ToolCallsResult before each stream so stale usage data cannot carry into a new call. HandleStreamingResponse only sets these fields at the end and never clears them at the start. - jina ChatStreamlyWithSender: validate modelName is non-empty (matching ChatWithMessages) and call validateStreamConfig to reject Stream=false before contacting the provider. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- jina ChatStreamlyWithSender: validate modelName is non-empty (matching ChatWithMessages) and call validateStreamConfig to reject Stream=false before contacting the provider. - localai_test.go: remove tests that depend on the idle-watchdog and multi-field reasoning extraction (extractLocalAIReasoning) that were removed when localai was migrated to the unified response handlers. Keep the cases that exercise reasoning_content and the request-side reasoning params, which the unified handlers still support. - jina_test.go: delete the obsolete TestJinaChatStreamIsNotSupported, which asserts that streaming is unsupported — jina now supports it. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…sions - base_model doStreamRequest: set Accept: text/event-stream on every streaming call. The pre-batch2 per-driver implementations (jiekouai, 302ai, replicate, …) all sent this header; dropping it in the shared helper broke their contract tests. - gitee_test / hunyuan_test: terminate the SSE fixture with a [DONE] line, matching the unified HandleStreamingResponse requirement and real upstream behavior. - localai_test.go: rewrite to remove cases that depend on the removed idle-watchdog and extractLocalAIReasoning helper, keeping the reasoning_content and request-side reasoning coverage. - jina_test.go: delete the obsolete TestJinaChatStreamIsNotSupported (jina now supports streaming). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
Relate to #17284
Migrate 10 OpenAI-compatible drivers (
gitee,gpustack,greenpt,huaweicloud,huggingface,hunyuan,jiekouai,jina,lmstudio,localai) to use the unified response handlers (HandleNonStreamingResponse/HandleStreamingResponse), following the same pattern established bydeepseekin #17634.greenptgainsChatWithMessages+ChatStreamlyWithSenderrequired by the unified handler infrastructure.