Skip to content

Fix Go: list providers order issue. - #16616

Merged
JinHai-CN merged 4 commits into
infiniflow:mainfrom
JinHai-CN:fix517
Jul 3, 2026
Merged

JinHai-CN merged 4 commits into
infiniflow:mainfrom
JinHai-CN:fix517

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

Summary

As title.

@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a numeric rank field to eighteen provider JSON configuration files under conf/models/. Correspondingly, internal/entity/models/model.go gains a Rank field on the Provider struct, includes rank in the ListProviders() map output, and sorts returned providers by descending rank.

Changes

Provider rank support

Layer / File(s) Summary
Provider struct and sorting logic
internal/entity/models/model.go
Adds sort import, adds public Rank int field (JSON key rank) to Provider struct, includes rank in ListProviders() output map, and sorts returned providers slice by descending rank.
Provider config rank values
conf/models/aliyun.json, conf/models/anthropic.json, conf/models/cohere.json, conf/models/deepseek.json, conf/models/google.json, conf/models/huggingface.json, conf/models/minimax.json, conf/models/moonshot.json, conf/models/ollama.json, conf/models/openai.json, conf/models/openrouter.json, conf/models/replicate.json, conf/models/siliconflow.json, conf/models/vllm.json, conf/models/volcengine.json, conf/models/xai.json, conf/models/zhipu-ai.json
Each provider config gains a top-level numeric rank field ranging from 975 to 999.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ProviderManager
  participant ProviderConfig

  Client->>ProviderManager: ListProviders()
  ProviderManager->>ProviderConfig: read Rank field per provider
  ProviderManager->>ProviderManager: build response map with rank
  ProviderManager->>ProviderManager: sort providers by rank descending
  ProviderManager-->>Client: sorted providers list
Loading

Poem

A rabbit hops through configs bright,
Adding ranks from left to right. 🐇
Aliyun, OpenAI, all in line,
Sorted now by rank so fine.
Hop, hop, hooray — the list looks right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description is too vague and does not provide the required summary or background context from the template. Expand the Summary section with a brief explanation of the ordering bug, the rank-based fix, and any relevant context.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly reflects the main change: fixing provider listing order in Go.
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.

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 changed the title Fix Go: fix list provider order issue. Fix Go: list providers order issue. Jul 3, 2026
@JinHai-CN
JinHai-CN marked this pull request as ready for review July 3, 2026 10:12
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 3, 2026
@JinHai-CN JinHai-CN added the ci Continue Integration label Jul 3, 2026

@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.

🧹 Nitpick comments (1)
internal/entity/models/model.go (1)

375-389: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Sort on the typed Provider slice instead of interface{} maps.

Sorting via providers[i]["rank"].(int) type assertion works today because every entry always sets "rank" as an int, but it's fragile against future changes to providerData construction. Sorting pm.Providers (or a copy) by provider.Rank before building the output maps avoids the assertion entirely and is more idiomatic.

Also note sort.Slice doesn't guarantee stable ordering for equal ranks; if two providers ever share a rank value, their relative order becomes nondeterministic across runs. sort.SliceStable would preserve deterministic ordering for ties.

♻️ Suggested refactor
 func (pm *ProviderManager) ListProviders() ([]map[string]interface{}, error) {
 
 	var providers []map[string]interface{}
 
-	for _, provider := range pm.Providers {
+	sortedProviders := make([]Provider, len(pm.Providers))
+	copy(sortedProviders, pm.Providers)
+	sort.SliceStable(sortedProviders, func(i, j int) bool {
+		return sortedProviders[i].Rank > sortedProviders[j].Rank
+	})
+
+	for _, provider := range sortedProviders {
 
 		modelTypeSet := make(map[string]struct{})
 		for _, model := range provider.Models {
 			for _, modelType := range model.ModelTypes {
 				modelTypeSet[modelType] = struct{}{}
 			}
 		}
 
 		modelTypes := make([]string, 0, len(modelTypeSet))
 		for modelType := range modelTypeSet {
 			modelTypes = append(modelTypes, modelType)
 		}
 
 		providerData := map[string]interface{}{
 			"name":        provider.Name,
 			"rank":        provider.Rank,
 			"url":         provider.URL,
 			"model_types": modelTypes,
 			"url_suffix":  provider.URLSuffix,
 		}
 		providers = append(providers, providerData)
 	}
-
-	// Sort providers by rank
-	sort.Slice(providers, func(i, j int) bool {
-		return providers[i]["rank"].(int) > providers[j]["rank"].(int)
-	})
 
 	if len(providers) == 0 {
 		return nil, fmt.Errorf("no providers found")
 	}
🤖 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/model.go` around lines 375 - 389, The provider sorting
in the model-building flow relies on `providerData["rank"].(int)` inside
`sort.Slice`, which is fragile and nondeterministic for equal ranks. Update the
sorting in the `providers` construction path to sort the typed `pm.Providers`
slice (or a copy) by `Provider.Rank` before converting each entry into the
`providerData` map, and use stable sorting so ties keep deterministic order.
Keep the output map creation unchanged, but remove the `interface{}` rank
assertion from the sort logic.
🤖 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.

Nitpick comments:
In `@internal/entity/models/model.go`:
- Around line 375-389: The provider sorting in the model-building flow relies on
`providerData["rank"].(int)` inside `sort.Slice`, which is fragile and
nondeterministic for equal ranks. Update the sorting in the `providers`
construction path to sort the typed `pm.Providers` slice (or a copy) by
`Provider.Rank` before converting each entry into the `providerData` map, and
use stable sorting so ties keep deterministic order. Keep the output map
creation unchanged, but remove the `interface{}` rank assertion from the sort
logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 49ee4833-6fe5-4d3c-8fe7-297cbff80e41

📥 Commits

Reviewing files that changed from the base of the PR and between ffc4d29 and fb335c3.

📒 Files selected for processing (18)
  • conf/models/aliyun.json
  • conf/models/anthropic.json
  • conf/models/cohere.json
  • conf/models/deepseek.json
  • conf/models/google.json
  • conf/models/huggingface.json
  • conf/models/minimax.json
  • conf/models/moonshot.json
  • conf/models/ollama.json
  • conf/models/openai.json
  • conf/models/openrouter.json
  • conf/models/replicate.json
  • conf/models/siliconflow.json
  • conf/models/vllm.json
  • conf/models/volcengine.json
  • conf/models/xai.json
  • conf/models/zhipu-ai.json
  • internal/entity/models/model.go

@JinHai-CN
JinHai-CN merged commit 83d09b1 into infiniflow:main Jul 3, 2026
6 checks passed
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 3, 2026
### Summary

As title.

---------

Signed-off-by: Jin Hai <[email protected]>
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 6, 2026
### Summary

As title.

---------

Signed-off-by: Jin Hai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant