Skip to content

feat: add xAI (Grok) provider support#1576

Open
Balance8 wants to merge 2 commits intoFalkorDB:stagingfrom
Balance8:feature/add-xai-provider-support
Open

feat: add xAI (Grok) provider support#1576
Balance8 wants to merge 2 commits intoFalkorDB:stagingfrom
Balance8:feature/add-xai-provider-support

Conversation

@Balance8
Copy link
Copy Markdown

@Balance8 Balance8 commented Mar 31, 2026

  • 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.

Summary by CodeRabbit

  • New Features
    • Added support for xAI as an AI provider in the application
    • xAI models are now automatically recognized and properly categorized
    • API key detection now supports xAI credentials

- 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.
Copilot AI review requested due to automatic review settings March 31, 2026 22:26
@overcut-ai
Copy link
Copy Markdown

overcut-ai bot commented Mar 31, 2026

❌ Workflow Failed: "Code Review"

The workflow encountered an error and could not complete successfully.

Error: Step git-clone failed


👉 View complete log

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 31, 2026

@Balance8 is attempting to deploy a commit to the FalkorDB Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

Walkthrough

This 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

Cohort / File(s) Summary
Provider Detection & Utilities
lib/ai-provider-utils.ts
Extended AIProvider union type to include "xai". Added detection logic for xAI API keys (xai- prefix), model names (grok substring heuristic), and display name mapping. Included xAI console URL/documentation in provider info.
UI Display & Categorization
app/settings/ModelSelector.tsx
Added "xAI" display name to provider mappings and introduced Rocket icon for xAI category. Extended model categorization fallback heuristics to recognize "grok" in model names and assign to xAI category.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🚀 A new provider takes flight,
xAI and grok join the light,
Detection and UI both aligned,
Models perfectly categorized and refined! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding xAI (Grok) provider support, which aligns with all modifications across ModelSelector.tsx and ai-provider-utils.ts.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/ai-provider-utils.ts (1)

155-156: Consolidate provider prefix lists into a shared constant to prevent drift.

knownProviders/knownPrefixes are 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

📥 Commits

Reviewing files that changed from the base of the PR and between 708b28a and 2f3ee7d.

📒 Files selected for processing (2)
  • app/settings/ModelSelector.tsx
  • lib/ai-provider-utils.ts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ModelSelector to 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.

Comment on lines 152 to 166
@@ -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;
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 76 to 92
// 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 {
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 87 to 92
categoryName = "Groq";
} else if (model.includes("command") || model.includes("cohere")) {
categoryName = "Cohere";
} else if (model.includes("grok")) {
categoryName = "xAI";
} else {
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@Balance8
Copy link
Copy Markdown
Author

Hey team, just a fellow coder looking to help out. Let me know what I need to improve on to meet your standards.

@gkorland gkorland requested a review from Anchel123 April 3, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants