Skip to content

Fix: model provider orders - #15524

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
wangq8:feature/model-provider-order
Jun 3, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
wangq8:feature/model-provider-order

Conversation

@wangq8

@wangq8 wangq8 commented Jun 2, 2026 •

Copy link
Copy Markdown
Collaborator

Fix: model provider orders
image

@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Provider and models APIs now build a factory rank mapping (using a safe _to_int helper) from FACTORY_LLM_INFOS and sort provider/model lists by factory rank (ascending) then name; the factory configuration file updates many provider rank values and removes rank fields from others.

Changes

Provider Ranking by Factory Configuration

Layer / File(s) Summary
Provider API provider ranking
api/apps/services/provider_api_service.py
Add _to_int helper, build factory_rank_mapping from FACTORY_LLM_INFOS, and sort provider lists by (rank, name) in both all-available and tenant-configured branches.
Models API provider ranking
api/apps/services/models_api_service.py
Add _to_int helper, build factory_rank_mapping from FACTORY_LLM_INFOS, and sort added_models by factory rank, then provider name, then instance name.
LLM factory rank configuration
conf/llm_factories.json
Update numeric rank values for multiple active providers and remove rank fields from a set of other provider entries across the configuration file.

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

size:M

🐰 Providers now hop in ranked order,
Each factory a steady supporter,
Safe integers guard the way,
As configs lead the sorting day!

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description is minimal and does not follow the required template structure with 'What problem does this PR solve?' and 'Type of change' sections. Add a detailed description explaining the problem being solved and select the appropriate type of change. The changes appear to involve reordering LLM providers by rank, so clarify this intent and rationale.
Title check ❓ Inconclusive The PR title 'Fix: model provider orders' describes the primary change (reordering model providers based on rank), but is partially misaligned with the PR label which indicates 'feature' rather than 'fix'. Clarify whether this is a bugfix or feature by aligning the title prefix ('Fix:' vs 'Feature:') with the actual nature of the change and PR labels.
✅ Passed checks (2 passed)
Check name Status Explanation
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 and usage tips.

@wangq8 wangq8 added the ci Continue Integration label Jun 2, 2026
@wangq8
wangq8 marked this pull request as ready for review June 2, 2026 12:46
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. labels Jun 2, 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
api/apps/services/models_api_service.py (1)

348-369: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Include name in the final sort key.

manual_added_model_record_keys is built from a set on Line 348, so models that share the same provider and instance can now come back in arbitrary order. Adding the model name here keeps the output deterministic inside each rank bucket.

Suggested fix
-    added_models.sort(key=lambda x: (factory_rank_mapping.get(x["provider_name"]), x["provider_name"], x["instance_name"]))
+    added_models.sort(
+        key=lambda x: (
+            factory_rank_mapping.get(x["provider_name"]),
+            x["provider_name"],
+            x["instance_name"],
+            x["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 `@api/apps/services/models_api_service.py` around lines 348 - 369, The final
sort for added_models currently uses key=lambda x:
(factory_rank_mapping.get(x["provider_name"]), x["provider_name"],
x["instance_name"]) which can yield non-deterministic order for models with the
same provider and instance; update the sort key used in added_models.sort to
include the model "name" (x["name"]) as a tie-breaker (e.g., append x["name"] to
the tuple) so that entries from manual_added_model_record_keys are ordered
deterministically by provider rank, provider_name, instance_name, then model
name.
🧹 Nitpick comments (1)
api/apps/services/provider_api_service.py (1)

31-35: ⚡ Quick win

Log rank fallback cases in the new ordering path.

Missing or invalid rank values are silently coerced into the default bucket here, so config-driven ordering regressions will be hard to trace once this ships. A small debug/warning log when fallback ranking is applied would make this path observable in both this service and the identical helper flow in api/apps/services/models_api_service.py.

As per coding guidelines, "Add logging for new flows".

Also applies to: 52-53, 69-69, 92-92

🤖 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 `@api/apps/services/provider_api_service.py` around lines 31 - 35, The _to_int
helper currently swallows invalid/missing rank values and returns the default
silently; update _to_int to log when it applies the fallback (include the
incoming value and the default used) using the module logger (e.g., logger.debug
or logger.warning) so these cases are observable; apply the same change to the
identical helper in api/apps/services/models_api_service.py and ensure log
messages are clear and consistent across both functions (_to_int) to aid tracing
config-driven ordering regressions.
🤖 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 `@api/apps/services/models_api_service.py`:
- Around line 348-369: The final sort for added_models currently uses key=lambda
x: (factory_rank_mapping.get(x["provider_name"]), x["provider_name"],
x["instance_name"]) which can yield non-deterministic order for models with the
same provider and instance; update the sort key used in added_models.sort to
include the model "name" (x["name"]) as a tie-breaker (e.g., append x["name"] to
the tuple) so that entries from manual_added_model_record_keys are ordered
deterministically by provider rank, provider_name, instance_name, then model
name.

---

Nitpick comments:
In `@api/apps/services/provider_api_service.py`:
- Around line 31-35: The _to_int helper currently swallows invalid/missing rank
values and returns the default silently; update _to_int to log when it applies
the fallback (include the incoming value and the default used) using the module
logger (e.g., logger.debug or logger.warning) so these cases are observable;
apply the same change to the identical helper in
api/apps/services/models_api_service.py and ensure log messages are clear and
consistent across both functions (_to_int) to aid tracing config-driven ordering
regressions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4fc66912-6c2a-46b3-8c05-6c37aca2407f

📥 Commits

Reviewing files that changed from the base of the PR and between 9799f33 and cb8a1b4.

📒 Files selected for processing (3)
  • api/apps/services/models_api_service.py
  • api/apps/services/provider_api_service.py
  • conf/llm_factories.json

@wangq8 wangq8 changed the title Feature: model provider orders Fix: model provider orders Jun 3, 2026
@wangq8
wangq8 requested a review from Lynn-Inf June 3, 2026 01:40

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

LGTM

@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (d41373c) to head (1278555).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15524   +/-   ##
=======================================
  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.
📢 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.

@wangq8
wangq8 merged commit 583daf4 into infiniflow:main Jun 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants