Repository navigation
feat(go-models): migrate batch 4 model drivers to unified handlers - #17699
Conversation
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)
📝 WalkthroughWalkthroughTen provider model implementations now delegate non-streaming and streaming chat handling to shared ChangesProvider chat migration
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
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: 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
📒 Files selected for processing (10)
internal/entity/models/orcarouter.gointernal/entity/models/perplexity.gointernal/entity/models/ppio.gointernal/entity/models/qiniu.gointernal/entity/models/ragcon.gointernal/entity/models/stepfun.gointernal/entity/models/togetherai.gointernal/entity/models/tokenhub.gointernal/entity/models/tokenpony.gointernal/entity/models/upstage.go
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]>
…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]>
There was a problem hiding this comment.
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 winAccept reasoning-only responses that use
reasoning.The new fallback assigns
ReasonContentfrommessage.reasoning, but Lines 202-206 only create an emptyAnswerforreasoning_content. A response withcontent: nulland non-emptyreasoningreaches Line 55 withcontent == niland fails as “no choices in response.”Create the empty
Answerfor non-emptyreasoningtoo. 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
📒 Files selected for processing (11)
internal/entity/models/orcarouter.gointernal/entity/models/perplexity_test.gointernal/entity/models/ppio.gointernal/entity/models/ppio_test.gointernal/entity/models/qiniu.gointernal/entity/models/response_handler.gointernal/entity/models/stepfun.gointernal/entity/models/stepfun_test.gointernal/entity/models/togetherai.gointernal/entity/models/togetherai_test.gointernal/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
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/entity/models/response_handler_test.go (1)
26-30: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove 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
📒 Files selected for processing (2)
internal/entity/models/response_handler.gointernal/entity/models/response_handler_test.go
5e68165 to
d714016
Compare
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 bydeepseekin #17634.baseModel.doRequest()andHandleNonStreamingResponse().