Skip to content

Go CLI: fix model related commands - #16368

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
JinHai-CN:fix498
Jun 25, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
JinHai-CN:fix498

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

What problem does this PR solve?

RAGFlow(api/default)> show provider 'zhipu-ai'

RAGFlow(api/default)> show provider 'zhipu-ai' instance 'test';

RAGFlow(api/default)> show provider 'zhipu-ai' instance 'test' balance;

RAGFlow(api/default)> show provider 'zhipu-ai' model 'glm-4.5';

Type of change

  • Refactoring

@JinHai-CN JinHai-CN added the ci Continue Integration label Jun 25, 2026
@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The CLI parser now recognizes API-prefixed SHOW PROVIDER forms for provider, instance, balance, and model lookups, and ExecuteUserCommand routes the new api_show_provider* command types to the matching provider display handlers. Legacy non-API provider show cases were removed.

Changes

API show-provider command flow

Layer / File(s) Summary
API show-provider parsing
internal/cli/user_parser.go
parseAPIShowCommands now routes provider tokens to parseAPIShowProviderCommands, which parses provider, instance, balance, and model forms into api_show_provider* command types and removes the old non-API provider instance/balance helpers.
API show-provider execution routing
internal/cli/cli_http.go
ExecuteUserCommand maps api_show_provider, api_show_provider_instance, api_show_provider_instance_balance, and api_show_provider_model to the matching CommonShowProvider* handlers, and removes the old non-API provider instance/balance cases.

Sequence Diagram(s)

sequenceDiagram
  participant parseAPIShowCommands
  participant parseAPIShowProviderCommands
  participant "api_show_provider commands"
  participant ExecuteUserCommand
  participant "CommonShowProvider handlers"
  parseAPIShowCommands->>parseAPIShowProviderCommands: TokenProvider
  parseAPIShowProviderCommands->>"api_show_provider commands": construct provider / instance / balance / model command
  "api_show_provider commands"-->>ExecuteUserCommand: parsed command type
  ExecuteUserCommand->>"CommonShowProvider handlers": dispatch
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • infiniflow/ragflow#16213: Adjusts internal/cli/cli_http.go provider/model show routing to the shared CommonShowProvider* handlers.
  • infiniflow/ragflow#16252: Rekeys SHOW PROVIDER ... parsing/dispatch onto api_show_provider* command types and related handler paths.
  • infiniflow/ragflow#16311: Updates the same CLI user-mode routing layer in internal/cli/cli_http.go and internal/cli/user_parser.go around new api_* dispatch paths.

Suggested labels

☯️ refactor

Poem

A bunny hopped through parser dust,
to api_show_provider paths with trust.
Instance, balance, model too,
all clicked into a tidy queue,
then thump—old tunnels turned to rust.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: fixing Go CLI model-related provider commands.
Description check ✅ Passed The description covers the problem examples and marks the change type as refactoring, matching the required template mostly well.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JinHai-CN
JinHai-CN marked this pull request as ready for review June 25, 2026 13:02
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 25, 2026
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 25, 2026
@JinHai-CN
JinHai-CN marked this pull request as draft June 25, 2026 13:05
@JinHai-CN
JinHai-CN marked this pull request as ready for review June 25, 2026 13:05

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

🤖 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_parser.go`:
- Around line 677-680: The provider subcommand parsing in user_parser.go is too
permissive: the instance, balance, and model branches accept extra tokens after
the expected argument and still return successfully. Update the relevant parsing
paths in the provider subcommand handler to verify the next token is either an
optional semicolon or end-of-input, and raise a parse error for any unexpected
trailing token before returning from the instance/balance/model branches.
🪄 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: 68ed6dea-9299-43f4-8237-cf780fd4f606

📥 Commits

Reviewing files that changed from the base of the PR and between dbefadd and ae5dca8.

📒 Files selected for processing (2)
  • internal/cli/cli_http.go
  • internal/cli/user_parser.go

Comment on lines +677 to +680
// Semicolon is optional
if p.curToken.Type == TokenSemicolon {
p.nextToken()
}

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reject unexpected trailing tokens before returning provider subcommands.

The instance, balance, and model branches accept any non-semicolon token after the parsed argument, so malformed input like SHOW PROVIDER 'p' INSTANCE 'i' EXTRA still executes.

Suggested fix
 	// Semicolon is optional
 	if p.curToken.Type == TokenSemicolon {
 		p.nextToken()
+	} else if p.curToken.Type != TokenEOF {
+		return nil, fmt.Errorf("unexpected token after instance name: %s", p.curToken.Value)
 	}
 	return cmd, nil
 }
@@
 	// Semicolon is optional
 	if p.curToken.Type == TokenSemicolon {
 		p.nextToken()
+	} else if p.curToken.Type != TokenEOF {
+		return nil, fmt.Errorf("unexpected token after balance: %s", p.curToken.Value)
 	}
 	return cmd, nil
 }
@@
 	// Semicolon is optional
 	if p.curToken.Type == TokenSemicolon {
 		p.nextToken()
+	} else if p.curToken.Type != TokenEOF {
+		return nil, fmt.Errorf("unexpected token after model name: %s", p.curToken.Value)
 	}
 	return cmd, nil
 }

Also applies to: 692-695, 713-716

🤖 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 677 - 680, The provider subcommand
parsing in user_parser.go is too permissive: the instance, balance, and model
branches accept extra tokens after the expected argument and still return
successfully. Update the relevant parsing paths in the provider subcommand
handler to verify the next token is either an optional semicolon or
end-of-input, and raise a parse error for any unexpected trailing token before
returning from the instance/balance/model branches.

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (dbefadd) to head (ae5dca8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16368   +/-   ##
=======================================
  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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit 58da1d6 into infiniflow:main Jun 25, 2026
6 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant