feat: add xAI (Grok) provider support#1576
feat: add xAI (Grok) provider support#1576Balance8 wants to merge 2 commits intoFalkorDB:stagingfrom
Conversation
- Add xAI to AIProvider type definition - Implement API key detection for xai- prefix format - Add xAI provider display name and console URL - Add Grok model detection and categorization - Add Rocket icon for xAI category in ModelSelector - Support all xAI Grok models (grok-4.20 and grok-4-1-fast variants) This enables users to select and use xAI's Grok models for text-to-cypher functionality with proper API key validation and UI integration.
❌ Workflow Failed: "Code Review"The workflow encountered an error and could not complete successfully. Error: Step git-clone failed |
|
@Balance8 is attempting to deploy a commit to the FalkorDB Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThis pull request adds support for xAI as a new AI provider, including its "grok" models. The changes extend the provider detection utilities and UI display layer to recognize, categorize, and display xAI models alongside existing providers like OpenAI, Anthropic, and others. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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.
🧹 Nitpick comments (1)
lib/ai-provider-utils.ts (1)
155-156: Consolidate provider prefix lists into a shared constant to prevent drift.
knownProviders/knownPrefixesare duplicated in multiple places. Centralizing this will reduce maintenance risk when adding providers again.♻️ Proposed refactor
export type AIProvider = "openai" | "anthropic" | "gemini" | "ollama" | "groq" | "cohere" | "xai" | "unknown"; + +const KNOWN_PROVIDER_PREFIXES: ReadonlyArray<Exclude<AIProvider, "unknown">> = [ + "openai", + "anthropic", + "gemini", + "ollama", + "groq", + "cohere", + "xai", +]; ... - const knownProviders: AIProvider[] = ["openai", "anthropic", "gemini", "ollama", "groq", "cohere", "xai"]; - const matched = knownProviders.find(p => p === prefix); + const matched = KNOWN_PROVIDER_PREFIXES.find(p => p === prefix); ... - const knownProviders: AIProvider[] = ["openai", "anthropic", "gemini", "ollama", "groq", "cohere", "xai"]; - const matched = knownProviders.find(p => p === prefix); + const matched = KNOWN_PROVIDER_PREFIXES.find(p => p === prefix); ... - const knownPrefixes = ["openai", "anthropic", "gemini", "ollama", "groq", "cohere", "xai"]; + const knownPrefixes = KNOWN_PROVIDER_PREFIXES;Also applies to: 164-165, 201-201
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/ai-provider-utils.ts` around lines 155 - 156, Replace the locally duplicated knownProviders array with a single shared exported constant (e.g., AI_PROVIDER_PREFIXES or KNOWN_AI_PROVIDERS) and use that constant everywhere the code currently defines or references knownProviders/knownPrefixes (the occurrences around the variables named knownProviders and matched, and the other duplicated checks at the other locations referenced in the comment). Move the constant into a common module or the top of lib/ai-provider-utils.ts, export it, and update all usages to import/reference that constant so the provider prefix list is maintained in one place.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@lib/ai-provider-utils.ts`:
- Around line 155-156: Replace the locally duplicated knownProviders array with
a single shared exported constant (e.g., AI_PROVIDER_PREFIXES or
KNOWN_AI_PROVIDERS) and use that constant everywhere the code currently defines
or references knownProviders/knownPrefixes (the occurrences around the variables
named knownProviders and matched, and the other duplicated checks at the other
locations referenced in the comment). Move the constant into a common module or
the top of lib/ai-provider-utils.ts, export it, and update all usages to
import/reference that constant so the provider prefix list is maintained in one
place.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4a828a46-dfc7-41f0-9787-06c9819d9241
📒 Files selected for processing (2)
app/settings/ModelSelector.tsxlib/ai-provider-utils.ts
There was a problem hiding this comment.
Pull request overview
Adds first-class xAI (Grok) provider support to the app’s provider detection utilities and model selection UI, enabling Grok models to be selected and validated (including API-key/provider mismatch messaging) alongside existing providers.
Changes:
- Extend
AIProvider+ API key/model heuristics to recognize xAI (xai-keys,grok*models) and provide xAI display name + console URL. - Update model display formatting to strip
xai:/xai::prefixes. - Update
ModelSelectorto categorize Grok models under an “xAI” section and show a Rocket icon for that category.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
lib/ai-provider-utils.ts |
Adds xAI to provider typing, API key detection, model/provider heuristics, and API-key help metadata. |
app/settings/ModelSelector.tsx |
Adds “xAI” category mapping + icon and categorizes grok* models into that category. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -149,7 +161,7 @@ export function detectProviderFromModel(model: string): AIProvider { | |||
| const singleSeparatorIndex = model.indexOf(":"); | |||
| if (singleSeparatorIndex !== -1) { | |||
| const prefix = model.substring(0, singleSeparatorIndex); | |||
| const knownProviders: AIProvider[] = ["openai", "anthropic", "gemini", "ollama", "groq", "cohere"]; | |||
| const knownProviders: AIProvider[] = ["openai", "anthropic", "gemini", "ollama", "groq", "cohere", "xai"]; | |||
| const matched = knownProviders.find(p => p === prefix); | |||
| if (matched) return matched; | |||
There was a problem hiding this comment.
detectProviderFromModel duplicates the knownProviders list in two branches ("::" and ":"), and a similar provider list exists again in formatModelDisplayName. Now that more providers (e.g., xai) are being added, this repetition increases the chance of future misses. Consider extracting a single shared constant (e.g., KNOWN_PROVIDERS) and reusing it in both functions/branches to keep provider support in sync.
| // Fallback: substring heuristics for unprefixed model names | ||
| if (!categoryName) { | ||
| if (model.startsWith("gpt") || model.startsWith("o1") || model.startsWith("o3")) { | ||
| categoryName = "OpenAI"; | ||
| } else if (model.includes("claude")) { | ||
| categoryName = "Anthropic"; | ||
| } else if (model.includes("gemini")) { | ||
| categoryName = "Google"; | ||
| } else if (model.includes("llama") || model.includes("mixtral") || model.includes("phi") || model.includes("deepseek")) { | ||
| categoryName = "Ollama"; | ||
| } else if (model.includes("groq")) { | ||
| categoryName = "Groq"; | ||
| } else if (model.includes("command") || model.includes("cohere")) { | ||
| categoryName = "Cohere"; | ||
| } else if (model.includes("grok")) { | ||
| categoryName = "xAI"; | ||
| } else { |
There was a problem hiding this comment.
categorizeModels re-implements provider detection heuristics that largely overlap with detectProviderFromModel in lib/ai-provider-utils.ts. This duplication means future provider additions/heuristic tweaks can easily get out of sync between backend validation (model/API key mismatch) and UI grouping. Consider importing and using detectProviderFromModel (plus getProviderDisplayName / the existing mapping) to derive categories instead of maintaining a separate heuristic set here.
| categoryName = "Groq"; | ||
| } else if (model.includes("command") || model.includes("cohere")) { | ||
| categoryName = "Cohere"; | ||
| } else if (model.includes("grok")) { | ||
| categoryName = "xAI"; | ||
| } else { |
There was a problem hiding this comment.
There are existing Playwright E2E tests for model categories and model/API-key mismatch, but none appear to cover the new xAI/Grok category or xai- API key mismatch behavior. Please add/extend E2E coverage (ideally conditional like the Ollama check) to validate that Grok models are grouped under an "xAI" category and that xai-prefixed keys are accepted/mismatch-detected correctly.
|
Hey team, just a fellow coder looking to help out. Let me know what I need to improve on to meet your standards. |
This enables users to select and use xAI's Grok models for text-to-cypher functionality with proper API key validation and UI integration.
Summary by CodeRabbit