Repository navigation
go: add Qiniu model provider - #15280
Conversation
📝 WalkthroughWalkthroughThis PR integrates Qiniu as a new model provider. It adds provider configuration defining URLs and models, wires the provider into the factory dispatcher, implements the QiniuModel driver with synchronous and streaming chat methods, thinking/reasoning mode configuration, and model listing capability. ChangesQiniu Model Provider Integration
Sequence DiagramsequenceDiagram
participant Caller
participant QiniuModel
participant QiniuAPI as Qiniu HTTP API
participant Sender as Sender Callback
Caller->>QiniuModel: ChatStreamlyWithSender(modelName, messages, apiConfig, chatConfig, sender)
Note over QiniuModel: Validate API key & messages
QiniuModel->>QiniuModel: applyQiniuThinkingConfig(request)
QiniuModel->>QiniuAPI: POST with stream: true (Bearer auth)
activate QiniuAPI
QiniuAPI-->>QiniuModel: 200 + streaming body
deactivate QiniuAPI
Note over QiniuModel: Scan response line-by-line
loop For each data: event
QiniuModel->>QiniuModel: Unmarshal delta (reasoning_content, content)
alt Has reasoning_content
QiniuModel->>Sender: sender(nil, &reasoning_content)
end
alt Has content
QiniuModel->>Sender: sender(&content, nil)
end
end
Note over QiniuModel: On [DONE] termination
QiniuModel->>Sender: sender(nil, nil) with "[DONE]" marker
QiniuModel-->>Caller: error (if any)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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: 3
🤖 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/qiniu.go`:
- Around line 334-337: The loop that calls scanner.Scan() currently logs the
full payload via common.Info(line), which can leak sensitive data and bloat
logs; remove that raw logging and either delete the common.Info(line) call or
replace it with a non-sensitive log such as common.Debug or common.Info that
only records metadata (e.g., "stream chunk received", length: len(line), or a
safely truncated/redacted snippet) so the raw contents of the variable line are
never logged; update the scanner.Scan() loop in qiniu.go (the block referencing
variable line and common.Info) accordingly.
- Around line 237-242: When parsing messageMap in the code path guarded by
chatModelConfig and chatModelConfig.Thinking, do not return an error if
"reasoning_content" is absent or not a string; instead attempt to cast
messageMap["reasoning_content"] to string and if the cast fails set
reasonContent = "" (or leave it nil/empty) and continue processing so valid
"content" does not cause the whole sync to fail; update the block around
reasonContent, messageMap, chatModelConfig.Thinking to tolerate missing/invalid
reasoning_content and only use it when present and correctly typed.
- Around line 144-149: The code builds url := fmt.Sprintf("%s/%s",
q.BaseURL[region], q.URLSuffix.Chat) without verifying that q.BaseURL has an
entry for the computed region, which can cause opaque runtime errors; update the
ChatWithMessages flow to check that baseURL, e.g. base, exists for the chosen
region (lookup q.BaseURL[region] into a variable), return a clear configuration
error if missing, and only then build the URL using base and q.URLSuffix.Chat
(mirroring the validation already used for stream/list paths).
🪄 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
Run ID: 26a9e3f8-057b-44af-a491-be98d8872261
📒 Files selected for processing (3)
conf/models/qiniu.jsoninternal/entity/models/factory.gointernal/entity/models/qiniu.go
| var region = "default" | ||
| if apiConfig.Region != nil && *apiConfig.Region != "" { | ||
| region = *apiConfig.Region | ||
| } | ||
| url := fmt.Sprintf("%s/%s", q.BaseURL[region], q.URLSuffix.Chat) | ||
|
|
There was a problem hiding this comment.
Validate base URL in sync chat like stream/list paths do.
ChatWithMessages directly uses q.BaseURL[region] without checking for missing region mapping. This can produce opaque request errors instead of a clear configuration error.
Suggested fix
var region = "default"
if apiConfig.Region != nil && *apiConfig.Region != "" {
region = *apiConfig.Region
}
- url := fmt.Sprintf("%s/%s", q.BaseURL[region], q.URLSuffix.Chat)
+ baseURL := strings.TrimSuffix(q.BaseURL[region], "/")
+ if baseURL == "" {
+ return nil, fmt.Errorf("qiniu: no base URL configured for region %q", region)
+ }
+ url := fmt.Sprintf("%s/%s", baseURL, q.URLSuffix.Chat)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| var region = "default" | |
| if apiConfig.Region != nil && *apiConfig.Region != "" { | |
| region = *apiConfig.Region | |
| } | |
| url := fmt.Sprintf("%s/%s", q.BaseURL[region], q.URLSuffix.Chat) | |
| var region = "default" | |
| if apiConfig.Region != nil && *apiConfig.Region != "" { | |
| region = *apiConfig.Region | |
| } | |
| baseURL := strings.TrimSuffix(q.BaseURL[region], "/") | |
| if baseURL == "" { | |
| return nil, fmt.Errorf("qiniu: no base URL configured for region %q", region) | |
| } | |
| url := fmt.Sprintf("%s/%s", baseURL, q.URLSuffix.Chat) |
🤖 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/qiniu.go` around lines 144 - 149, The code builds url
:= fmt.Sprintf("%s/%s", q.BaseURL[region], q.URLSuffix.Chat) without verifying
that q.BaseURL has an entry for the computed region, which can cause opaque
runtime errors; update the ChatWithMessages flow to check that baseURL, e.g.
base, exists for the chosen region (lookup q.BaseURL[region] into a variable),
return a clear configuration error if missing, and only then build the URL using
base and q.URLSuffix.Chat (mirroring the validation already used for stream/list
paths).
| var reasonContent string | ||
| if chatModelConfig != nil && chatModelConfig.Thinking != nil && *chatModelConfig.Thinking { | ||
| reasonContent, ok = messageMap["reasoning_content"].(string) | ||
| if !ok { | ||
| return nil, fmt.Errorf("invalid reasoning content format") | ||
| } |
There was a problem hiding this comment.
Don’t fail sync chat when reasoning_content is absent.
When thinking is enabled, the current parser returns an error if reasoning_content is missing or non-string, even if content is valid. That makes otherwise successful responses fail.
Suggested fix
var reasonContent string
if chatModelConfig != nil && chatModelConfig.Thinking != nil && *chatModelConfig.Thinking {
- reasonContent, ok = messageMap["reasoning_content"].(string)
- if !ok {
- return nil, fmt.Errorf("invalid reasoning content format")
- }
+ if raw, exists := messageMap["reasoning_content"]; exists {
+ if parsed, ok := raw.(string); ok {
+ reasonContent = parsed
+ }
+ }
if reasonContent != "" && reasonContent[0] == '\n' {
reasonContent = reasonContent[1:]
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| var reasonContent string | |
| if chatModelConfig != nil && chatModelConfig.Thinking != nil && *chatModelConfig.Thinking { | |
| reasonContent, ok = messageMap["reasoning_content"].(string) | |
| if !ok { | |
| return nil, fmt.Errorf("invalid reasoning content format") | |
| } | |
| var reasonContent string | |
| if chatModelConfig != nil && chatModelConfig.Thinking != nil && *chatModelConfig.Thinking { | |
| if raw, exists := messageMap["reasoning_content"]; exists { | |
| if parsed, ok := raw.(string); ok { | |
| reasonContent = parsed | |
| } | |
| } | |
| if reasonContent != "" && reasonContent[0] == '\n' { | |
| reasonContent = reasonContent[1:] | |
| } | |
| } |
🤖 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/qiniu.go` around lines 237 - 242, When parsing
messageMap in the code path guarded by chatModelConfig and
chatModelConfig.Thinking, do not return an error if "reasoning_content" is
absent or not a string; instead attempt to cast messageMap["reasoning_content"]
to string and if the cast fails set reasonContent = "" (or leave it nil/empty)
and continue processing so valid "content" does not cause the whole sync to
fail; update the block around reasonContent, messageMap,
chatModelConfig.Thinking to tolerate missing/invalid reasoning_content and only
use it when present and correctly typed.
| for scanner.Scan() { | ||
| line := scanner.Text() | ||
| common.Info(line) | ||
|
|
There was a problem hiding this comment.
Remove raw stream payload logging from info logs.
Line 336 logs full streamed content/reasoning chunks, which can leak sensitive user data and inflate logs in production.
Suggested fix
- common.Info(line)
+ // Avoid logging raw SSE payloads (may contain user content / reasoning text).📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| for scanner.Scan() { | |
| line := scanner.Text() | |
| common.Info(line) | |
| for scanner.Scan() { | |
| line := scanner.Text() | |
| // Avoid logging raw SSE payloads (may contain user content / reasoning text). |
🤖 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/qiniu.go` around lines 334 - 337, The loop that calls
scanner.Scan() currently logs the full payload via common.Info(line), which can
leak sensitive data and bloat logs; remove that raw logging and either delete
the common.Info(line) call or replace it with a non-sensitive log such as
common.Debug or common.Info that only records metadata (e.g., "stream chunk
received", length: len(line), or a safely truncated/redacted snippet) so the raw
contents of the variable line are never logged; update the scanner.Scan() loop
in qiniu.go (the block referencing variable line and common.Info) accordingly.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15280 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
Related to #14736
This PR adds Qiniu provider integration for the Go model driver layer in RAGFlow.
Supported capabilities:
Verified examples from the CLI:
Type of change