Repository navigation
Go: show model and list all models - #16272
Conversation
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughRenames ChangesBase64 Rename, Model Endpoint Split, and Username Decoding Update
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/common/format.go (1)
77-87: 🎯 Functional Correctness | 🟠 MajorSwitch to
base64.URLEncodingfor values embedded in URL path segments.These helpers back username and model-name values embedded in request paths (e.g.,
/admin/users/:username,/admin/users/:username/keys).base64.StdEncodingemits+,/, and=. A/in the encoded output is interpreted as a path separator by Gin and will not be captured by a single-segment:param, so encode→path→decode round-trips fail for any input whose base64 contains/(and+/=add further escaping hazards). Switch both functions tobase64.URLEncoding(alphabet-/_, no/) to keep encoding/decoding symmetric and path-safe.Proposed fix
-func EncodeToBase64(email string) string { - return base64.StdEncoding.EncodeToString([]byte(email)) +func EncodeToBase64(s string) string { + return base64.URLEncoding.EncodeToString([]byte(s)) } func DecodeFromBase64(encoded string) (string, error) { - decoded, err := base64.StdEncoding.DecodeString(encoded) + decoded, err := base64.URLEncoding.DecodeString(encoded) if err != nil { return "", err } return string(decoded), 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/common/format.go` around lines 77 - 87, The EncodeToBase64 and DecodeFromBase64 functions use base64.StdEncoding which produces characters like slash, plus, and equals that cause path parsing issues when embedded in URL segments (e.g., /admin/users/:username). Replace base64.StdEncoding with base64.URLEncoding in both functions to use URL-safe alphabet characters (dash and underscore instead of plus and slash) that remain safe in path parameters and preserve encoding-decoding symmetry.
🤖 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/admin/router.go`:
- Line 187: The DELETE route for DeleteModelInstance handler in the provider
router is currently bound to the collection path `/:provider_name/instances`
without an instance identifier. Change this route to include an instance_name
parameter so it becomes instance-scoped, allowing the handler to target and
delete a specific instance rather than operating at the collection level. This
will enable the DeleteModelInstance handler to properly access the instance_name
from the route parameters.
In `@internal/cli/common_command.go`:
- Around line 1432-1445: The EncodeToBase64 function in
internal/common/format.go is using base64.StdEncoding which produces URL-unsafe
characters like forward slashes and plus signs that break URL path matching when
the encoded values are used in route paths like
/admin/all-models/{encoded_name}. Replace the
base64.StdEncoding.EncodeToString() call with
base64.URLEncoding.EncodeToString() (or base64.RawURLEncoding if padding is not
needed) to ensure the encoded values are safe for use as URL path segments
across all handlers that use this helper function.
---
Outside diff comments:
In `@internal/common/format.go`:
- Around line 77-87: The EncodeToBase64 and DecodeFromBase64 functions use
base64.StdEncoding which produces characters like slash, plus, and equals that
cause path parsing issues when embedded in URL segments (e.g.,
/admin/users/:username). Replace base64.StdEncoding with base64.URLEncoding in
both functions to use URL-safe alphabet characters (dash and underscore instead
of plus and slash) that remain safe in path parameters and preserve
encoding-decoding symmetry.
🪄 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: 318291d3-2c12-4535-a940-d93bfb23beb7
📒 Files selected for processing (6)
internal/admin/enterprise_handler.gointernal/admin/handler.gointernal/admin/router.gointernal/cli/admin_command.gointernal/cli/common_command.gointernal/common/format.go
|
|
||
| provider.POST("/:provider_name/instances", r.handler.AddModelInstance) | ||
| provider.GET("/:provider_name/instances", r.handler.ListModelInstances) | ||
| provider.DELETE("/:provider_name/instances", r.handler.DeleteModelInstance) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Use an instance-scoped delete route for DeleteModelInstance.
Line 187 still binds deletion to /providers/:provider_name/instances (collection path). This prevents targeting a specific instance via route param and can break handlers expecting instance_name.
Proposed fix
- provider.DELETE("/:provider_name/instances", r.handler.DeleteModelInstance)
+ provider.DELETE("/:provider_name/instances/:instance_name", r.handler.DeleteModelInstance)📝 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.
| provider.DELETE("/:provider_name/instances", r.handler.DeleteModelInstance) | |
| provider.DELETE("/:provider_name/instances/:instance_name", r.handler.DeleteModelInstance) |
🤖 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/admin/router.go` at line 187, The DELETE route for
DeleteModelInstance handler in the provider router is currently bound to the
collection path `/:provider_name/instances` without an instance identifier.
Change this route to include an instance_name parameter so it becomes
instance-scoped, allowing the handler to target and delete a specific instance
rather than operating at the collection level. This will enable the
DeleteModelInstance handler to properly access the instance_name from the route
parameters.
| encodedModelName := common.EncodeToBase64(modelName) | ||
|
|
||
| var resp *Response | ||
| var err error | ||
| var httpClient *HTTPClient | ||
| switch c.Config.CLIMode { | ||
| case AdminMode: | ||
| baseURL := fmt.Sprintf("/admin/all-models/%s", encodedModelName) | ||
| httpClient = c.AdminServerClient | ||
| resp, err = httpClient.Request("GET", "/admin/all-models", "web", nil, payload) | ||
| resp, err = httpClient.Request("GET", baseURL, "web", nil, nil) | ||
| case APIMode: | ||
| baseURL := fmt.Sprintf("/all-models/%s", encodedModelName) | ||
| httpClient = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer] | ||
| resp, err = httpClient.Request("GET", "/all-models", "web", nil, payload) | ||
| resp, err = httpClient.Request("GET", baseURL, "web", nil, nil) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Locate base64 helpers =="
fd -p 'format.go' internal/common | while read -r f; do
echo "-- $f --"
rg -n 'func (EncodeToBase64|DecodeFromBase64)|StdEncoding|URLEncoding|RawURLEncoding|RawStdEncoding' "$f" -C2
done
echo
echo "== Locate model-name param decoding in admin handlers =="
fd -p 'enterprise_handler.go' internal/admin | while read -r f; do
echo "-- $f --"
rg -n 'ShowModel|ListAllModels|Param\("model_name"\)|DecodeFromBase64' "$f" -C2
doneRepository: infiniflow/ragflow
Length of output: 6295
Replace base64.StdEncoding with base64.URLEncoding in EncodeToBase64() helper.
The helper at internal/common/format.go:77–79 currently uses base64.StdEncoding.EncodeToString(), which produces characters like / and + that are unsafe in URL path segments. Since encoded model names (and usernames) are placed directly in routes like /admin/all-models/{encoded_name}, any encoded / will be interpreted as a path delimiter and break route matching.
Replace with base64.URLEncoding (or base64.RawURLEncoding if padding is unnecessary) to ensure path-segment safety across all affected handlers.
🤖 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/common_command.go` around lines 1432 - 1445, The EncodeToBase64
function in internal/common/format.go is using base64.StdEncoding which produces
URL-unsafe characters like forward slashes and plus signs that break URL path
matching when the encoded values are used in route paths like
/admin/all-models/{encoded_name}. Replace the
base64.StdEncoding.EncodeToString() call with
base64.URLEncoding.EncodeToString() (or base64.RawURLEncoding if padding is not
needed) to ensure the encoded values are safe for use as URL path segments
across all handlers that use this helper function.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16272 +/- ##
=======================================
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:
|
What problem does this PR solve?
Type of change