Repository navigation
feat(go-models): migrate batch 1 model drivers to unified handlers - #17696
Conversation
Migrate 10 model drivers to use shared doRequest/HandleNonStreamingResponse/HandleStreamingResponse helpers: - 302ai (Model302ai) - aliyun (AliyunModel) - astraflow (AstraFlowModel) - avian (AvianModel) - azure_openai (AzureOpenAIModel) - baichuan (BaichuanModel) - baidu (BaiduModel) - cometapi (CometAPIModel) - deepinfra (DeepInfraModel) - futurmix (FuturmixModel) Each driver had ~150 lines of duplicated HTTP request building and response parsing logic replaced with calls to the shared base model helpers.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (13)
🚧 Files skipped from review as they are similar to previous changes (13)
📝 WalkthroughWalkthroughTen provider drivers now use shared ChangesProvider handler migration
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
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: 2
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/avian.go (1)
55-61: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winRestore the trailing-slash trim in
chatURL.
GetBaseURLreturns a user-configured base URL. If that value ends with/,fmt.Sprintf("%s/%s", ...)produces a double slash in the path. The other drivers in this batch still callstrings.TrimSuffix(baseURL, "/"). Removing the trim here changes the produced URL for existing configurations.🐛 Proposed fix
func (a *AvianModel) chatURL(apiConfig *APIConfig) (string, error) { baseURL, err := a.baseModel.GetBaseURL(apiConfig) if err != nil { return "", err } - return fmt.Sprintf("%s/%s", baseURL, a.baseModel.URLSuffix.Chat), nil + return fmt.Sprintf("%s/%s", strings.TrimSuffix(baseURL, "/"), a.baseModel.URLSuffix.Chat), nil }🤖 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/avian.go` around lines 55 - 61, Update AvianModel.chatURL to trim a trailing slash from the baseURL returned by GetBaseURL before joining it with URLSuffix.Chat, preserving the existing URL format and error propagation.internal/entity/models/azure_openai.go (1)
181-184: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winAdd
stream_options.include_usageto the Azure streaming request.
HandleStreamingResponseextractsmodelUsagefrom stream usage chunks, and Azure OpenAI returns those chunks when using API version2024-10-21withstream_options.include_usage=true. Add the option to the streamingreqBodyso Azure deployments record token usage.🤖 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/azure_openai.go` around lines 181 - 184, Update the streaming request body in the Azure OpenAI request flow to include stream_options with include_usage enabled, alongside messages and stream. Ensure HandleStreamingResponse receives Azure usage chunks for API version 2024-10-21 so modelUsage is recorded.
🧹 Nitpick comments (1)
internal/entity/models/futurmix.go (1)
51-58: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove
endpointURLfromFuturMixModel.This receiver-scoped helper is not called;
ChatWithMessagesandChatStreamlyWithSenderalready build the URL inline, so delete the stale helper to keep the model surface small.🤖 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/futurmix.go` around lines 51 - 58, Remove the unused FuturMixModel.endpointURL method, including its URL-building logic, while leaving ChatWithMessages and ChatStreamlyWithSender unchanged since they already construct their URLs inline.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/aliyun.go`:
- Line 168: The streaming implementations in
internal/entity/models/aliyun.go:168-168 and
internal/entity/models/baidu.go:210-210 still duplicate transport logic. Replace
each manual transport block with the corresponding baseModel.doStreamRequest
call, preserving the existing context, URL, API config, request body, timeout,
and streaming callback arguments; remove bytes, encoding/json, and net/http
imports from each file when unused.
In `@internal/entity/models/avian.go`:
- Around line 79-90: Remove the entire chatModelConfig.Thinking conditional from
the request-building flow, including both enabled and disabled assignments to
reqBody["thinking"]. Keep buildRequestBody and all other request fields
unchanged.
---
Outside diff comments:
In `@internal/entity/models/avian.go`:
- Around line 55-61: Update AvianModel.chatURL to trim a trailing slash from the
baseURL returned by GetBaseURL before joining it with URLSuffix.Chat, preserving
the existing URL format and error propagation.
In `@internal/entity/models/azure_openai.go`:
- Around line 181-184: Update the streaming request body in the Azure OpenAI
request flow to include stream_options with include_usage enabled, alongside
messages and stream. Ensure HandleStreamingResponse receives Azure usage chunks
for API version 2024-10-21 so modelUsage is recorded.
---
Nitpick comments:
In `@internal/entity/models/futurmix.go`:
- Around line 51-58: Remove the unused FuturMixModel.endpointURL method,
including its URL-building logic, while leaving ChatWithMessages and
ChatStreamlyWithSender unchanged since they already construct their URLs inline.
🪄 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: 4c200b62-7071-44cd-9795-e6f532aac5eb
📒 Files selected for processing (10)
internal/entity/models/302ai.gointernal/entity/models/aliyun.gointernal/entity/models/astraflow.gointernal/entity/models/avian.gointernal/entity/models/azure_openai.gointernal/entity/models/baichuan.gointernal/entity/models/baidu.gointernal/entity/models/cometapi.gointernal/entity/models/deepinfra.gointernal/entity/models/futurmix.go
…e avian dead Thinking block - aliyun.go: Replace manual SSE transport block with baseModel.doStreamRequest call. Preserves context, URL, API config, request body, timeout, and callback arguments. Imports (bytes, encoding/json, net/http) retained for other methods. - baidu.go: Same doStreamRequest migration as aliyun. Imports retained for other methods. - avian.go: Remove dead Thinking conditional block from ChatWithMessages. buildRequestBody does not handle thinking; the reqBody['thinking'] assignments were never consumed by doRequest. Net -10 lines. Part of infiniflow#17696 (batch 1).
986baf0 to
9dd80d0
Compare
…back, embed error - base_model.go: doStreamRequest now sets Accept: text/event-stream so providers that routed streaming through the shared handler (302ai, etc.) keep the header their old per-provider code set. Fixes TestAI302StreamForcesStreaming. - response_handler.go: extractContentAndChoices falls back to a top-level "reasoning" string field when "reasoning_content" is absent/empty, matching Avian's response shape. Fixes TestAvianChatFallsBackToReasoningField. - cometapi_test.go: assert the unified "status 401" error from doRequest instead of the removed provider-specific "CometAPI embeddings API error" prefix. Fixes TestCometAPIEmbedRejectsHTTPError. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ding (#17775) ## Summary Relate to #17284. Completes the migration of the four non-OpenAI-compatible model drivers (`anthropic`, `cohere`, `google`, `bedrock`) onto the shared usage-recording path. Earlier batches (#17634, #17643, #17696–#17700) covered only the OpenAI-compatible cluster; these four providers ship wire formats that do not fit the OpenAI `choices[0].delta` / `usage` block template and so were left for a separate pass. Per the maintainer's guidance for this batch, each driver is migrated on its own terms rather than forced through a single template. The shared machinery used is intentionally small: `recordResponseUsage`, `parseChatCompletionResponse`, `BaseModel.newJSONPostRequest`, and the existing `authHeader` hook for non-Bearer auth. Co-authored-by: Haruko386 <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Summary
Relate to #17284
Migrate 10 OpenAI-compatible drivers (
302ai,aliyun,astraflow,avian,azure_openai,baichuan,baidu,cometapi,deepinfra,futurmix) to use the unified response handlers (HandleNonStreamingResponse/HandleStreamingResponse), following the same pattern established bydeepseekin #17634.baseModel.doRequest()andHandleNonStreamingResponse().