Repository navigation
fix(model-selector): improve model selection logic for regional models - #2412
Conversation
WalkthroughModelSelector selection parsing adds region-aware fallback logic to resolve the selected model more robustly from regional model URLs. When direct model ID matching fails, it searches by provider ID and raw model name, and applies region-aware preference for the selected mapping based on whether the input contains a region suffix. ChangesRegion-aware Model Selection
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 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. ✨ Finishing Touches🧪 Generate unit tests (beta)
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: 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 `@apps/playground/src/components/model-selector.tsx`:
- Around line 868-870: selectedModelId currently uses
selectedModelIdRaw.split(":")[0], which removes everything after the first colon
and can mis-parse IDs that contain additional colons; change the logic to locate
the last colon (use lastIndexOf(":")) and strip only the trailing region suffix
so you preserve any internal colons in the ID when computing selectedModelId,
and apply the same trailing-suffix parsing fix to the other similar spots that
handle selectedModelIdRaw/selectedModel resolution in the same block (the code
around selectedModelId, selectedModelIdRaw and selectedModel resolution).
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: b04f9e7e-c2b9-4fdb-9088-8fdc4c1fcb30
📒 Files selected for processing (1)
apps/playground/src/components/model-selector.tsx
| const selectedModelId = selectedModelIdRaw.includes(":") | ||
| ? selectedModelIdRaw.split(":")[0] | ||
| : selectedModelIdRaw; |
There was a problem hiding this comment.
Use trailing-suffix parsing instead of first-colon split
Line 868 currently uses split(":")[0], which strips at the first colon. This can mis-parse model IDs containing additional colons and break selectedModel resolution. Use lastIndexOf(":") (same pattern as downstream parsing) to only remove the trailing region suffix.
Suggested fix
- const selectedModelId = selectedModelIdRaw.includes(":")
- ? selectedModelIdRaw.split(":")[0]
- : selectedModelIdRaw;
+ const colonIndex = selectedModelIdRaw.lastIndexOf(":");
+ const selectedModelId =
+ colonIndex === -1
+ ? selectedModelIdRaw
+ : selectedModelIdRaw.slice(0, colonIndex);Also applies to: 871-884
🤖 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 `@apps/playground/src/components/model-selector.tsx` around lines 868 - 870,
selectedModelId currently uses selectedModelIdRaw.split(":")[0], which removes
everything after the first colon and can mis-parse IDs that contain additional
colons; change the logic to locate the last colon (use lastIndexOf(":")) and
strip only the trailing region suffix so you preserve any internal colons in the
ID when computing selectedModelId, and apply the same trailing-suffix parsing
fix to the other similar spots that handle selectedModelIdRaw/selectedModel
resolution in the same block (the code around selectedModelId,
selectedModelIdRaw and selectedModel resolution).
Summary by CodeRabbit