Repository navigation
feat(go-cli): support batch model add/remove and optional embedding dimension - #15631
Conversation
📝 WalkthroughWalkthroughThe CLI parser now accepts multiple model names in one quoted string and builds per-model configs into a ChangesMulti-model CLI command support
Sequence DiagramsequenceDiagram
participant CLI as CLI Parser
participant Client as RAGFlowClient.AddCustomModel
participant API as Backend API
CLI->>Client: build cmd.Params with provider_name, instance_name, models[]
Client->>API: POST /api/... {provider_name, instance_name, models}
API-->>Client: 200/JSON response with Code/Duration
Client-->>CLI: propagate response (Code, Duration, message)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
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: 2
🧹 Nitpick comments (1)
internal/cli/user_parser.go (1)
862-867: 💤 Low valueUnused struct
AddModelConfig.This struct is defined but never used in the implementation. The code uses
map[string]anyinstead for building model configurations. Either remove this dead code or refactor to use the struct for better type safety.🤖 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/cli/user_parser.go` around lines 862 - 867, The AddModelConfig struct is dead code because the implementation builds model configuration with map[string]any instead. Either remove AddModelConfig if it is not needed, or refactor the relevant parsing/building path in user_parser.go to use AddModelConfig consistently so the model config flow is type-safe and the struct is actually referenced.
🤖 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/cli/user_command.go`:
- Around line 2684-2687: The error message is misleading: the code checks
cmd.Params["models"] into variable models but returns "model name not provided";
update the returned error to accurately reference the parameter being validated
(e.g., "models parameter not provided" or "models not provided") in the block
that performs the type assertion on cmd.Params["models"] to make the error clear
when models is missing or wrong-typed.
In `@internal/cli/user_parser.go`:
- Around line 851-856: The duplicate detection in Parse logic uses
case-sensitive keys (seen[modelName]) but the backend normalizes names with
strings.ToLower; update the dedupe to normalize model names the same way before
checking/adding to seen (e.g., use strings.ToLower(modelName) when indexing the
seen map and when reporting the duplicate error) so inputs like "GPT4" and
"gpt4" are treated as duplicates; modify the block referencing modelNames and
the seen map accordingly (preserve the original modelName for error text if
desired).
---
Nitpick comments:
In `@internal/cli/user_parser.go`:
- Around line 862-867: The AddModelConfig struct is dead code because the
implementation builds model configuration with map[string]any instead. Either
remove AddModelConfig if it is not needed, or refactor the relevant
parsing/building path in user_parser.go to use AddModelConfig consistently so
the model config flow is type-safe and the struct is actually referenced.
🪄 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: 32e349b7-089c-4599-94d3-2116e460d8d7
📒 Files selected for processing (2)
internal/cli/user_command.gointernal/cli/user_parser.go
| models, ok := cmd.Params["models"].([]map[string]any) | ||
| if !ok { | ||
| return nil, fmt.Errorf("model name not provided") | ||
| } |
There was a problem hiding this comment.
Error message does not match parameter name.
The error says "model name not provided" but the parameter being checked is models. This is misleading for debugging.
🔧 Proposed fix
models, ok := cmd.Params["models"].([]map[string]any)
if !ok {
- return nil, fmt.Errorf("model name not provided")
+ return nil, fmt.Errorf("models not provided")
}📝 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.
| models, ok := cmd.Params["models"].([]map[string]any) | |
| if !ok { | |
| return nil, fmt.Errorf("model name not provided") | |
| } | |
| models, ok := cmd.Params["models"].([]map[string]any) | |
| if !ok { | |
| return nil, fmt.Errorf("models not provided") | |
| } |
🤖 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/cli/user_command.go` around lines 2684 - 2687, The error message is
misleading: the code checks cmd.Params["models"] into variable models but
returns "model name not provided"; update the returned error to accurately
reference the parameter being validated (e.g., "models parameter not provided"
or "models not provided") in the block that performs the type assertion on
cmd.Params["models"] to make the error clear when models is missing or
wrong-typed.
| seen := make(map[string]struct{}, len(modelNames)) | ||
| for _, modelName := range modelNames { | ||
| if _, ok := seen[modelName]; ok { | ||
| return nil, fmt.Errorf("duplicate model name: %s", modelName) | ||
| } | ||
| seen[modelName] = struct{}{} |
There was a problem hiding this comment.
Case-sensitive duplicate detection mismatches backend validation.
The CLI uses case-sensitive comparison (seen[modelName]), but the backend at model_service.go:2025-2029 uses case-insensitive detection via strings.ToLower(modelName). This allows CLI to accept inputs like 'GPT4 gpt4' that the backend will reject as duplicates.
🔧 Proposed fix to align with backend behavior
seen := make(map[string]struct{}, len(modelNames))
for _, modelName := range modelNames {
- if _, ok := seen[modelName]; ok {
+ key := strings.ToLower(modelName)
+ if _, ok := seen[key]; ok {
return nil, fmt.Errorf("duplicate model name: %s", modelName)
}
- seen[modelName] = struct{}{}
+ seen[key] = struct{}{}
}🤖 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/cli/user_parser.go` around lines 851 - 856, The duplicate detection
in Parse logic uses case-sensitive keys (seen[modelName]) but the backend
normalizes names with strings.ToLower; update the dedupe to normalize model
names the same way before checking/adding to seen (e.g., use
strings.ToLower(modelName) when indexing the seen map and when reporting the
duplicate error) so inputs like "GPT4" and "gpt4" are treated as duplicates;
modify the block referencing modelNames and the seen map accordingly (preserve
the original modelName for error text if desired).
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/cli/user_parser.go (1)
912-915:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winMisleading error message.
The error message says "expected provider name" but this code block is parsing the instance name.
🔧 Proposed fix
// instance name if p.curToken.Type != TokenQuotedString { - return nil, fmt.Errorf("expected provider name") + return nil, fmt.Errorf("expected instance name") }🤖 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/cli/user_parser.go` around lines 912 - 915, The error message in the instance-name parsing branch is misleading: when checking p.curToken.Type != TokenQuotedString (parsing the instance name) it currently returns fmt.Errorf("expected provider name"); change the error text to reflect the actual field (e.g., "expected instance name" or "expected quoted instance name") so callers of the parsing function get the correct failure context; update the error string in the block that uses p.curToken and TokenQuotedString (in user_parser.go) accordingly.
🧹 Nitpick comments (2)
internal/cli/user_parser.go (2)
928-930: 💤 Low valueInconsistent error message casing.
Other error messages in this file use uppercase for keywords (e.g., "expected FROM", "expected PROVIDER"). This one uses lowercase "expected with".
🔧 Proposed fix
if p.curToken.Type != TokenWith { - return nil, fmt.Errorf("expected with") + return nil, fmt.Errorf("expected WITH") }🤖 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/cli/user_parser.go` around lines 928 - 930, The error message for the TokenWith check is inconsistent with other messages; update the returned error in the block that checks p.curToken.Type != TokenWith (the TokenWith branch) to use uppercase keyword "WITH" (e.g., "expected WITH") so it matches the style used for "expected FROM" and "expected PROVIDER".
862-867: 💤 Low value
AddModelConfigstruct appears unused.This struct is defined but never instantiated. The
parseAddModelfunction builds[]map[string]anydirectly (lines 1021-1028) to satisfy the downstream contract inAddCustomModel. Consider removing this dead code or using it to improve type safety.🤖 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/cli/user_parser.go` around lines 862 - 867, The AddModelConfig struct is dead code; either delete it or use it to improve type safety by modifying parseAddModel to construct []AddModelConfig (populate ModelName, ModelTypes, MaxTokens, Thinking) instead of building []map[string]any directly, then convert that slice to the []map[string]any expected by AddCustomModel before calling it; update any callers or tests accordingly so references use the new typed slice or remove the unused AddModelConfig type if you prefer the map-based contract.
🤖 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.
Outside diff comments:
In `@internal/cli/user_parser.go`:
- Around line 912-915: The error message in the instance-name parsing branch is
misleading: when checking p.curToken.Type != TokenQuotedString (parsing the
instance name) it currently returns fmt.Errorf("expected provider name"); change
the error text to reflect the actual field (e.g., "expected instance name" or
"expected quoted instance name") so callers of the parsing function get the
correct failure context; update the error string in the block that uses
p.curToken and TokenQuotedString (in user_parser.go) accordingly.
---
Nitpick comments:
In `@internal/cli/user_parser.go`:
- Around line 928-930: The error message for the TokenWith check is inconsistent
with other messages; update the returned error in the block that checks
p.curToken.Type != TokenWith (the TokenWith branch) to use uppercase keyword
"WITH" (e.g., "expected WITH") so it matches the style used for "expected FROM"
and "expected PROVIDER".
- Around line 862-867: The AddModelConfig struct is dead code; either delete it
or use it to improve type safety by modifying parseAddModel to construct
[]AddModelConfig (populate ModelName, ModelTypes, MaxTokens, Thinking) instead
of building []map[string]any directly, then convert that slice to the
[]map[string]any expected by AddCustomModel before calling it; update any
callers or tests accordingly so references use the new typed slice or remove the
unused AddModelConfig type if you prefer the map-based contract.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8cbf2c56-26ae-461e-ac86-f22f10cd8e82
📒 Files selected for processing (1)
internal/cli/user_parser.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15631 +/- ##
=======================================
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 Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
internal/cli/user_parser.go (1)
844-859:⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftWhitespace splitting breaks single model names that contain spaces.
strings.Fields(raw)turns a previously valid quoted single name like'my custom model'into three model names. That regresses bothADD MODELandDROP/REMOVE MODEL, so the new multi-name syntax is no longer backward-compatible for any model name containing whitespace.🤖 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/cli/user_parser.go` around lines 844 - 859, parseModelNames currently uses strings.Fields which breaks quoted names; replace that with a tokenization that respects quotes and preserves spaces inside quoted tokens (e.g., iterate raw and build tokens, treating text inside single or double quotes as a single token and allowing commas/whitespace as separators). Keep the rest of the logic (nil/empty check and duplicate detection using seen) intact and return the collected tokens as modelNames from parseModelNames.internal/cli/user_command.go (1)
1871-1882:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDon't reintroduce
dimension: 0when the user omittedDIMENSION.
parseEmbedCommand()now leavescmd.Params["dimension"]unset when the CLI uses the new no-dimension form, but this method always serializes"dimension": 0. That collapses “unset” back into an explicit value, so the new optional syntax can still override backend defaults or trip validation that distinguishes missing from zero.Proposed fix
- dimension, ok := cmd.Params["dimension"].(int) - if !ok { - dimension = 0 - } + dimension, hasDimension := cmd.Params["dimension"].(int) payload := map[string]interface{}{ "provider_name": providerName, "instance_name": instanceName, "model_name": modelName, "texts": texts, - "dimension": dimension, } + if hasDimension { + payload["dimension"] = dimension + }🤖 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/cli/user_command.go` around lines 1871 - 1882, The payload always includes "dimension": 0 because the code forces a zero when cmd.Params["dimension"] is missing; instead, preserve absence by only adding the "dimension" key to payload when cmd.Params["dimension"] exists and is an int. Locate the cmd.Params["dimension"] check and the payload map creation in user_command.go (the variables dimension, ok and payload map) and change the logic so that if ok is false you do not set "dimension" in payload (only include it when ok is true and the value is an int).
🤖 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.
Outside diff comments:
In `@internal/cli/user_command.go`:
- Around line 1871-1882: The payload always includes "dimension": 0 because the
code forces a zero when cmd.Params["dimension"] is missing; instead, preserve
absence by only adding the "dimension" key to payload when
cmd.Params["dimension"] exists and is an int. Locate the cmd.Params["dimension"]
check and the payload map creation in user_command.go (the variables dimension,
ok and payload map) and change the logic so that if ok is false you do not set
"dimension" in payload (only include it when ok is true and the value is an
int).
In `@internal/cli/user_parser.go`:
- Around line 844-859: parseModelNames currently uses strings.Fields which
breaks quoted names; replace that with a tokenization that respects quotes and
preserves spaces inside quoted tokens (e.g., iterate raw and build tokens,
treating text inside single or double quotes as a single token and allowing
commas/whitespace as separators). Keep the rest of the logic (nil/empty check
and duplicate detection using seen) intact and return the collected tokens as
modelNames from parseModelNames.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 58b1aae1-1ccd-49de-b13a-d3cccd54d3e5
📒 Files selected for processing (2)
internal/cli/user_command.gointernal/cli/user_parser.go
|
LGTM |
Summary
This PR improves the Go CLI in two areas:
dimensionargument optional for theembed textcommand.These changes keep the existing single-model and explicit-dimension behaviors compatible while making the CLI more convenient for common workflows.
What Changed
1. Batch model add/remove support
The CLI now supports operating on multiple model names provided in a single quoted string.
Supported commands include:
For add model, each config segment after with is matched to the corresponding model name by position.
Example mapping:
The existing single-model syntax remains supported.
2. Optional embedding dimension
Previously, the Go CLI required dimension to be explicitly provided for embed text.
Before:
embed text 'what is rag' 'who are you' with 'model@test@provider' dimension 8192;
Now both forms are supported:
embed text 'what is rag' 'who are you' with 'model@test@provider' dimension 8192;
embed text 'what is rag' 'who are you' with 'model@test@provider';
When omitted, the CLI leaves dimension unset and relies on provider/backend behavior.
Tests
Added parser tests covering: