Skip to content

feat(go-models): migrate batch 2 model drivers to unified handlers - #17697

Merged
JinHai-CN merged 8 commits into
infiniflow:mainfrom
jay77721:pr/migrate-models-batch2
Aug 3, 2026
Merged

JinHai-CN merged 8 commits into
infiniflow:mainfrom
jay77721:pr/migrate-models-batch2

Conversation

@jay77721

@jay77721 jay77721 commented Aug 3, 2026 •

Copy link
Copy Markdown
Member

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 by deepseek in #17634.

  • Cut ~150 lines per driver (1398 lines removed, 155 added across 10 files).
  • greenpt gains ChatWithMessages + ChatStreamlyWithSender required by the unified handler infrastructure.
  • All other drivers: pure deduplication of HTTP plumbing.

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.
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code labels Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR migrates ten model drivers to shared BaseModel request and response handlers. It removes provider-specific HTTP and SSE parsing. It adds GreenPT chat methods and enables Jina streaming with thinking configuration.

Changes

Chat handling migration

Layer / File(s) Summary
Non-streaming request migration
internal/entity/models/gitee.go, internal/entity/models/gpustack.go, internal/entity/models/huaweicloud.go, internal/entity/models/huggingface.go, internal/entity/models/hunyuan.go, internal/entity/models/jiekouai.go, internal/entity/models/jina.go, internal/entity/models/lmstudio.go, internal/entity/models/localai.go
Non-streaming chat methods now use BaseModel.doRequest and HandleNonStreamingResponse. Provider-specific response types and parsing logic were removed.
Streaming request migration
internal/entity/models/gitee.go, internal/entity/models/gpustack.go, internal/entity/models/huaweicloud.go, internal/entity/models/huggingface.go, internal/entity/models/hunyuan.go, internal/entity/models/jiekouai.go, internal/entity/models/lmstudio.go, internal/entity/models/localai.go
Streaming methods now use doStreamRequest and HandleStreamingResponse. Several providers request usage data. GPUStack applies an explicit stream timeout. LocalAI removes its custom idle-timeout logic.
Provider chat coverage
internal/entity/models/greenpt.go, internal/entity/models/jina.go
GreenPT gains non-streaming and streaming chat methods. Jina gains streaming support and forwards the thinking option.
Streaming test updates
internal/entity/models/jina_test.go, internal/entity/models/localai_test.go
Jina removes the unsupported-streaming test. LocalAI removes watchdog and legacy thinking-field tests while retaining reasoning_content coverage.

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
Loading

Possibly related PRs

Suggested labels: 💞 feature

Suggested reviewers: jinhai-cn, haruko386

Poem

A rabbit checks the shared chat trail,
GreenPT sends and streams without fail.
Jina joins the streaming line,
Common handlers keep the flow in time.
Old parsers rest. 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the migration of model drivers to unified handlers, which is the main change.
Description check ✅ Passed The description includes the required Summary section and clearly states the migration scope, motivation, and key changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Add the missing sender nil guard in three streaming methods. The migration moved sender invocation into HandleStreamingResponse, so each caller must reject a nil sender before it starts the request. gpustack.go, hunyuan.go, huaweicloud.go, jiekouai.go, and localai.go return fmt.Errorf("sender is required"). These three drivers do not, so a nil sender reaches the shared handler and causes a nil function call at the first stream event.

  • internal/entity/models/huggingface.go#L90-L97: add if sender == nil { return fmt.Errorf("sender is required") } after the APIConfigCheck call.
  • internal/entity/models/lmstudio.go#L103-L110: add the same guard after the APIConfigCheck call.
  • internal/entity/models/jina.go#L127-L133: add the same guard in the new ChatStreamlyWithSender method after the APIConfigCheck call.
🤖 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 win

Use baseModel.doStreamRequest for this stream path.

ChatStreamlyWithSender repeats the same timeout, newJSONPostRequest body, HTTP client call, status check, and response handling as BaseModel.doStreamRequest. Switch this call to g.baseModel.doStreamRequest(...), then remove the now-unused imports if no other code in gpustack.go uses them.

If the shared helper becomes SSE-specific, add Accept: text/event-stream to 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

📥 Commits

Reviewing files that changed from the base of the PR and between 288be80 and 2dadbed.

📒 Files selected for processing (10)
  • internal/entity/models/gitee.go
  • internal/entity/models/gpustack.go
  • internal/entity/models/greenpt.go
  • internal/entity/models/huaweicloud.go
  • internal/entity/models/huggingface.go
  • internal/entity/models/hunyuan.go
  • internal/entity/models/jiekouai.go
  • internal/entity/models/jina.go
  • internal/entity/models/lmstudio.go
  • internal/entity/models/localai.go

Comment thread internal/entity/models/greenpt.go Resolved
Comment thread internal/entity/models/huaweicloud.go Resolved
Comment thread internal/entity/models/huaweicloud.go Resolved
Comment thread internal/entity/models/jina.go Resolved
jay77721 and others added 5 commits August 3, 2026 10:53
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]>
@jay77721
jay77721 marked this pull request as draft August 3, 2026 04:33
@jay77721
jay77721 marked this pull request as ready for review August 3, 2026 04:33
…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]>
@jay77721
jay77721 marked this pull request as draft August 3, 2026 05:06
@jay77721
jay77721 marked this pull request as ready for review August 3, 2026 05:06
@jay77721

jay77721 commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@jay77721
jay77721 marked this pull request as draft August 3, 2026 05:13
@jay77721
jay77721 marked this pull request as ready for review August 3, 2026 05:14
@jay77721
jay77721 marked this pull request as draft August 3, 2026 05:14
@jay77721
jay77721 marked this pull request as ready for review August 3, 2026 05:14
@jay77721
jay77721 requested a review from Haruko386 August 3, 2026 05:24
@JinHai-CN
JinHai-CN merged commit 75586c0 into infiniflow:main Aug 3, 2026
3 checks passed
@jay77721
jay77721 deleted the pr/migrate-models-batch2 branch August 5, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration ☯️ refactor Pull request that refactor/refine code size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants