Repository navigation
Fix: model provider orders - #15524
Conversation
📝 WalkthroughWalkthroughProvider 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. ChangesProvider Ranking by Factory Configuration
🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (2 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.
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 winInclude
namein the final sort key.
manual_added_model_record_keysis built from aseton 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 winLog rank fallback cases in the new ordering path.
Missing or invalid
rankvalues 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 inapi/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
📒 Files selected for processing (3)
api/apps/services/models_api_service.pyapi/apps/services/provider_api_service.pyconf/llm_factories.json
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Fix: model provider orders
