Skip to content

feat(go-models): migrate batch 4 model drivers to unified handlers - #17699

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

JinHai-CN merged 6 commits into
infiniflow:mainfrom
jay77721:pr/migrate-models-batch4

Conversation

@jay77721

@jay77721 jay77721 commented Aug 3, 2026 •

Copy link
Copy Markdown
Member

Summary

Relate to #17284

Migrate 10 OpenAI-compatible drivers (orcarouter, perplexity, ppio, qiniu, ragcon, stepfun, togetherai, tokenhub, tokenpony, upstage) to use the unified response handlers (HandleNonStreamingResponse / HandleStreamingResponse), following the same pattern established by deepseek in #17634.

  • Cut ~150 lines per driver (1436 lines removed, 62 added across 10 files).
  • No functional changes — pure deduplication of HTTP plumbing.
  • Each driver now routes through baseModel.doRequest() and HandleNonStreamingResponse().

Migrate 10 model drivers to use shared doRequest/HandleNonStreamingResponse/HandleStreamingResponse helpers:
- orcarouter (OrcaRouterModel)
- perplexity (PerplexityModel)
- ppio (PPIOModel)
- qiniu (QiniuModel)
- ragcon (RagconModel)
- stepfun (StepfunModel)
- togetherai (TogetherAIModel)
- tokenhub (TokenHubModel)
- tokenpony (TokenPonyModel)
- upstage (UpstageModel)
@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

📝 Walkthrough

Walkthrough

Ten provider model implementations now delegate non-streaming and streaming chat handling to shared BaseModel and OpenAI-compatible helpers. Provider-specific response types, HTTP logic, SSE parsing, and stream usage handling were removed.

Changes

Provider chat migration

Layer / File(s) Summary
Shared response-handler contracts
internal/entity/models/response_handler.go, internal/entity/models/response_handler_test.go
Shared handling now returns upstream errors, supports tolerant streams and root-level finish_reason values, accepts thinking reasoning content, and tests bare finish events.
Non-streaming handler migration
internal/entity/models/{orcarouter,perplexity,ppio,qiniu,ragcon,stepfun,togetherai,tokenhub,tokenpony,upstage}.go, internal/entity/models/{perplexity,ppio,stepfun,togetherai,upstage}_test.go
Chat methods now use shared request execution and HandleNonStreamingResponse. Obsolete provider response types and unused imports were removed. Fixtures use reasoning_content and updated usage expectations.
Streaming handler migration and validation
internal/entity/models/{orcarouter,perplexity,ppio,qiniu,ragcon,stepfun,togetherai,tokenhub,tokenpony,upstage}.go, internal/entity/models/{perplexity,ppio,stepfun,togetherai,upstage}_test.go
Streaming methods now use shared stream requests and HandleStreamingResponse. Requests include usage metadata. Tests update reasoning fields and Accept header expectations.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested labels: 🧪 test

Suggested reviewers: haruko386

Poem

A rabbit shares one stream-wide plan,
Ten model paths now use it.
Old parsers hop away,
Usage joins each day,
And reasoning fields stay fit.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.36% 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
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.
Description check ✅ Passed The description includes the required Summary section, explains the migration purpose, identifies affected drivers, and provides relevant scope and context.
Title check ✅ Passed The title clearly and concisely identifies the migration of model drivers to unified handlers.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

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: 2

🤖 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/ppio.go`:
- Line 141: Converge the remaining inline streaming implementations onto
baseModel.doStreamRequest, wrapping HandleStreamingResponse in
internal/entity/models/ppio.go (lines 114-141), togetherai.go (lines 141-168),
orcarouter.go (lines 104-131), qiniu.go (lines 193-220), and stepfun.go (lines
106-133); use each driver’s baseModel receiver and existing request parameters,
preserving the parser callback. Remove the now-unused bytes, encoding/json, and
net/http imports from each converted file while retaining io for io.ReadCloser.

In `@internal/entity/models/stepfun.go`:
- Around line 102-113: Reset ChatConfig.ToolCallsResult at the start of
StepFunModel.ChatStreamlyWithSender before constructing the streaming request
and invoking HandleStreamingResponse, matching the existing qiniu streaming path
so reused chat configurations cannot retain stale tool calls.
🪄 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: e38309e2-eab2-4f96-ba99-57ed13ce7379

📥 Commits

Reviewing files that changed from the base of the PR and between 288be80 and 10f66d9.

📒 Files selected for processing (10)
  • internal/entity/models/orcarouter.go
  • internal/entity/models/perplexity.go
  • internal/entity/models/ppio.go
  • internal/entity/models/qiniu.go
  • internal/entity/models/ragcon.go
  • internal/entity/models/stepfun.go
  • internal/entity/models/togetherai.go
  • internal/entity/models/tokenhub.go
  • internal/entity/models/tokenpony.go
  • internal/entity/models/upstage.go

Comment thread internal/entity/models/ppio.go Resolved
Comment thread internal/entity/models/stepfun.go Resolved
@jay77721 jay77721 added the ci Continue Integration label Aug 3, 2026
jay77721 and others added 3 commits August 3, 2026 14:50
Five model drivers (orcarouter, ppio, qiniu, stepfun, togetherai) still
had manual HTTP template code in their ChatStreamlyWithSender paths.
Replace them with the shared doStreamRequest helper so all ten batch-4
drivers now use the same code path for both streaming and non-streaming.

Also hardens HandleNonStreamingResponse with an upstream "error" field
check and HandleStreamingResponse with a root-level finish_reason check,
so provider-specific behaviors are preserved in the shared layer.

Co-authored-by: jay77721 <[email protected]>
@jay77721
jay77721 marked this pull request as draft August 3, 2026 08:35
@jay77721
jay77721 marked this pull request as ready for review August 3, 2026 08:35
@jay77721 jay77721 added ci Continue Integration and removed ci Continue Integration labels Aug 3, 2026
…rtions

gofmt-align map literals in perplexity/stepfun/togetherai tests, and update
the stream happy-path tests to expect Accept: text/event-stream now that
these drivers go through the unified doStreamRequest path.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@jay77721
jay77721 marked this pull request as draft August 3, 2026 08:42
@jay77721
jay77721 marked this pull request as ready for review August 3, 2026 08:42
@jay77721
jay77721 requested a review from Haruko386 August 3, 2026 08:44

@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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/entity/models/response_handler.go (1)

209-219: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Accept reasoning-only responses that use reasoning.

The new fallback assigns ReasonContent from message.reasoning, but Lines 202-206 only create an empty Answer for reasoning_content. A response with content: null and non-empty reasoning reaches Line 55 with content == nil and fails as “no choices in response.”

Create the empty Answer for non-empty reasoning too. Add a reasoning-only test for this field.

Proposed fix
 	} else if rc, ok := messageMap["reasoning_content"].(string); ok && rc != "" {
 		// content may be nil when the response only carries reasoning_content.
 		empty := ""
 		content = &empty
+	} else if rc, ok := messageMap["reasoning"].(string); ok && rc != "" {
+		// content may be nil when the response only carries reasoning.
+		empty := ""
+		content = &empty
 	}
🤖 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/response_handler.go` around lines 209 - 219, The
response normalization logic must treat non-empty messageMap["reasoning"] the
same as reasoning_content when content is null. Update the empty Answer creation
condition near the existing reasoning_content handling so reasoning-only
responses reach the normal response path, and add a test covering content: null
with non-empty reasoning.
🤖 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/response_handler.go`:
- Around line 145-147: Update the event handling flow in the response handler so
a non-empty root-level finish_reason sets sawTerminal before the choices
presence/validity guard and does not return early. Add coverage for an event
containing only finish_reason, ensuring the stream terminates successfully
without choices or a subsequent [DONE] marker.

In `@internal/entity/models/upstage_test.go`:
- Line 128: Update the Upstage response fixtures used by the relevant tests to
use the documented reasoning field: set non-streaming message payloads to
reasoning and streaming delta payloads to reasoning, including the fixtures
around the identified reasoning_content entries. If the driver intentionally
uses reasoning_content, update the associated comments and expectations to
reflect that deliberate schema choice instead.

---

Outside diff comments:
In `@internal/entity/models/response_handler.go`:
- Around line 209-219: The response normalization logic must treat non-empty
messageMap["reasoning"] the same as reasoning_content when content is null.
Update the empty Answer creation condition near the existing reasoning_content
handling so reasoning-only responses reach the normal response path, and add a
test covering content: null with non-empty reasoning.
🪄 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: 6a7ea0be-a9e6-4688-8f66-5faf59da5d45

📥 Commits

Reviewing files that changed from the base of the PR and between 10f66d9 and dff63ed.

📒 Files selected for processing (11)
  • internal/entity/models/orcarouter.go
  • internal/entity/models/perplexity_test.go
  • internal/entity/models/ppio.go
  • internal/entity/models/ppio_test.go
  • internal/entity/models/qiniu.go
  • internal/entity/models/response_handler.go
  • internal/entity/models/stepfun.go
  • internal/entity/models/stepfun_test.go
  • internal/entity/models/togetherai.go
  • internal/entity/models/togetherai_test.go
  • internal/entity/models/upstage_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • internal/entity/models/ppio.go
  • internal/entity/models/stepfun.go
  • internal/entity/models/qiniu.go
  • internal/entity/models/togetherai.go

Comment thread internal/entity/models/upstage_test.go Resolved

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 3, 2026
@Haruko386
Haruko386 marked this pull request as draft August 3, 2026 09:03
@Haruko386 Haruko386 removed the ci Continue Integration label Aug 3, 2026
@Haruko386
Haruko386 marked this pull request as ready for review August 3, 2026 09:03
@Haruko386 Haruko386 added the ci Continue Integration label Aug 3, 2026

@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.

🧹 Nitpick comments (1)
internal/entity/models/response_handler_test.go (1)

26-30: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the migration-history text from the test comment.

Lines 28-30 describe the previous implementation. Keep the comment limited to the current test behavior.

As per coding guidelines, “keep package and doc comments aligned with the current runtime path rather than migration history.”

Proposed fix
 // TestHandleStreamingResponseBareRootFinishReason verifies the shared handler
 // terminates the stream when an event carries only a root-level finish_reason
 // with no choices and no trailing [DONE]. Before the fix this event was
-// skipped by the choices guard and the handler returned "stream ended before
-// [DONE] or finish_reason".
 func TestHandleStreamingResponseBareRootFinishReason(t *testing.T) {
🤖 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/response_handler_test.go` around lines 26 - 30, Update
the comment for TestHandleStreamingResponseBareRootFinishReason to describe only
the current behavior: the handler terminates when an event contains a root-level
finish_reason without choices or trailing [DONE]. Remove the sentences
describing the prior implementation and failure behavior.

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.

Nitpick comments:
In `@internal/entity/models/response_handler_test.go`:
- Around line 26-30: Update the comment for
TestHandleStreamingResponseBareRootFinishReason to describe only the current
behavior: the handler terminates when an event contains a root-level
finish_reason without choices or trailing [DONE]. Remove the sentences
describing the prior implementation and failure behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2b8138ec-7600-40ff-9fb3-8ede784b089d

📥 Commits

Reviewing files that changed from the base of the PR and between d714016 and 5e68165.

📒 Files selected for processing (2)
  • internal/entity/models/response_handler.go
  • internal/entity/models/response_handler_test.go

@jay77721
jay77721 force-pushed the pr/migrate-models-batch4 branch from 5e68165 to d714016 Compare August 3, 2026 09:33
@JinHai-CN
JinHai-CN merged commit 31264ba into infiniflow:main Aug 3, 2026
12 checks passed
@jay77721
jay77721 deleted the pr/migrate-models-batch4 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 lgtm This PR has been approved by a maintainer ☯️ 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.

3 participants