-
-
Notifications
You must be signed in to change notification settings - Fork 95
feat/improve model selection dropdown #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat/improve model selection dropdown #17
Conversation
|
@mihirpenugonda is attempting to deploy a commit to the Harsh's projects Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe Changes
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
frontend/components/ChatInput.tsxOops! Something went wrong! :( ESLint: 9.28.0 ESLint couldn't find the plugin "eslint-plugin-react-hooks". (The package "eslint-plugin-react-hooks" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following: The plugin "eslint-plugin-react-hooks" was referenced from the config file in " » eslint-config-next/core-web-vitals » /node_modules/.pnpm/eslint-config-next@15.3.2_eslint@9.28.0_jiti@2.4.2__typescript@5.8.3/node_modules/eslint-config-next/index.js". If you still can't figure out the problem, please see https://eslint.org/docs/latest/use/troubleshooting. ✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
frontend/components/ChatInput.tsx (1)
251-295: Excellent grouped dropdown implementation with minor accessibility improvement needed.The grouped dropdown implementation is well-structured with proper conditional navigation and visual indicators. The logic correctly handles API key status and model enablement.
Consider adding keyboard navigation support for the provider labels:
<DropdownMenuLabel className={cn( "flex items-center justify-between px-2 py-1.5", !group.hasApiKey && "cursor-pointer hover:bg-accent/50 transition-colors" )} onClick={!group.hasApiKey ? () => navigate('/settings') : undefined} + onKeyDown={!group.hasApiKey ? (e) => { + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault(); + navigate('/settings'); + } + } : undefined} + tabIndex={!group.hasApiKey ? 0 : -1} + role={!group.hasApiKey ? "button" : "presentation"} + aria-label={!group.hasApiKey ? `Configure API key for ${providerDisplayNames[provider as keyof typeof providerDisplayNames]}` : undefined} >
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
frontend/components/ChatInput.tsx(4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
frontend/components/ChatInput.tsx (3)
lib/models.ts (3)
AIModel(12-12)AI_MODELS(3-10)getModelConfig(53-55)lib/utils.ts (1)
cn(4-6)frontend/components/ui/dropdown-menu.tsx (4)
DropdownMenuGroup(246-246)DropdownMenuLabel(247-247)DropdownMenuItem(248-248)DropdownMenuSeparator(252-252)
🔇 Additional comments (4)
frontend/components/ChatInput.tsx (4)
11-13: LGTM! Correct imports for new dropdown structure.The imports for
DropdownMenuLabel,DropdownMenuSeparator, andDropdownMenuGroupare appropriately added to support the new grouped dropdown functionality.
193-193: LGTM! Navigate hook correctly added for settings navigation.The
useNavigatehook is properly imported and used to enable navigation to the settings page when users click on provider labels without configured API keys.
249-249: LGTM! Appropriate width increase for grouped content.The dropdown width increase from
10remto14remaccommodates the new grouped layout with provider labels and API key status indicators.
204-225:Details
❌ Incorrect review comment
Verify type safety for provider key access.
The grouping logic is well-structured and properly memoized. However, there's a potential type safety issue with the provider key access.
The
config.providervalues should be validated to ensure they match the expected provider keys. Consider adding type checking:AI_MODELS.forEach((model) => { const config = getModelConfig(model); const provider = config.provider; + if (!provider || typeof provider !== 'string') { + console.warn(`Invalid provider for model ${model}:`, provider); + return; + } const apiKey = getKey(provider);Let me verify the provider types and values used in the model configurations:
🏁 Script executed:
#!/bin/bash # Description: Check model configurations and provider values to ensure type safety # Search for model configurations and provider definitions ast-grep --pattern 'provider: $_' # Search for provider type definitions rg -A 3 -B 3 "provider.*:" --type ts # Look for MODEL_CONFIGS usage rg -A 5 "MODEL_CONFIGS" --type tsLength of output: 2328
No runtime provider validation required
TypeScript’s
ModelConfigdefinesprovideras theProviderunion andMODEL_CONFIGSis declaredas const satisfies Record<AIModel, ModelConfig>. This guarantees at compile time thatconfig.provideris always a validProviderstring, so an extra runtime check isn’t needed.Likely an incorrect or invalid review comment.
| const providerDisplayNames = { | ||
| google: 'Google AI', | ||
| openai: 'OpenAI', | ||
| openrouter: 'OpenRouter' | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add type safety for provider display name mapping.
The provider display names mapping should include type checking to handle unknown providers gracefully.
- const providerDisplayNames = {
+ const providerDisplayNames: Record<string, string> = {
google: 'Google AI',
openai: 'OpenAI',
- openrouter: 'OpenRouter'
+ openrouter: 'OpenRouter',
+ // Add fallback for unknown providers
+ };
+
+ const getProviderDisplayName = (provider: string): string => {
+ return providerDisplayNames[provider] || provider;
};Then update the usage in line 261:
- {providerDisplayNames[provider as keyof typeof providerDisplayNames]}
+ {getProviderDisplayName(provider)}📝 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.
| const providerDisplayNames = { | |
| google: 'Google AI', | |
| openai: 'OpenAI', | |
| openrouter: 'OpenRouter' | |
| }; | |
| // original context… | |
| const providerDisplayNames: Record<string, string> = { | |
| google: 'Google AI', | |
| openai: 'OpenAI', | |
| openrouter: 'OpenRouter', | |
| // Add fallback for unknown providers | |
| }; | |
| const getProviderDisplayName = (provider: string): string => { | |
| return providerDisplayNames[provider] || provider; | |
| }; | |
| // …later in your JSX (around line 261) | |
| - {providerDisplayNames[provider as keyof typeof providerDisplayNames]} | |
| + {getProviderDisplayName(provider)} |
🤖 Prompt for AI Agents
In frontend/components/ChatInput.tsx around lines 227 to 231, the
providerDisplayNames object lacks type safety, which can cause issues with
unknown providers. Define a TypeScript type or interface for the provider keys
and use it to type the providerDisplayNames object. Then, update the usage at
line 261 to safely access the display name, providing a fallback value for
unknown providers to handle them gracefully.
Summary
Summary by CodeRabbit