Skip to content

Commit

Permalink
Merge pull request #444 from miurla/feat/add-xai-provider
Browse files Browse the repository at this point in the history
feat: add xAI (Grok) provider and models
  • Loading branch information
miurla authored Feb 17, 2025
2 parents 004c5d9 + 934b3af commit dd231d0
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ TAVILY_API_KEY=[YOUR_TAVILY_API_KEY] # Get your API key at: https://app.tavily.
# Fireworks
# FIREWORKS_API_KEY=[YOUR_FIREWORKS_API_KEY]

# xAI (Grok)
# XAI_API_KEY=[YOUR_XAI_API_KEY]

# OpenAI Compatible Model
# NEXT_PUBLIC_OPENAI_COMPATIBLE_MODEL=
# OPENAI_COMPATIBLE_API_KEY=
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ This will allow you to use Morphic as your default search engine in the browser.
- DeepSeek
- DeepSeek V3
- DeepSeek R1
- xAI
- grok-2
- grok-2-vision

## ⚡ AI SDK Implementation

Expand Down
Binary file modified bun.lockb
Binary file not shown.
6 changes: 6 additions & 0 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ NEXT_PUBLIC_AZURE_DEPLOYMENT_NAME=[YOUR_DEPLOYMENT_NAME]
# FIREWORKS_API_KEY=[YOUR_API_KEY]
```
### xAI
```bash
XAI_API_KEY=[YOUR_XAI_API_KEY]
```

## Other Features

### Share Feature
Expand Down
12 changes: 12 additions & 0 deletions lib/types/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,17 @@ export const models: Model[] = [
name: process.env.NEXT_PUBLIC_OPENAI_COMPATIBLE_MODEL || 'Undefined',
provider: 'OpenAI Compatible',
providerId: 'openai-compatible'
},
{
id: 'grok-2-1212',
name: 'Grok 2',
provider: 'xAI',
providerId: 'xai'
},
{
id: 'grok-2-vision-1212',
name: 'Grok 2 Vision',
provider: 'xAI',
providerId: 'xai'
}
]
6 changes: 5 additions & 1 deletion lib/utils/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createFireworks, fireworks } from '@ai-sdk/fireworks'
import { google } from '@ai-sdk/google'
import { groq } from '@ai-sdk/groq'
import { createOpenAI, openai } from '@ai-sdk/openai'
import { xai } from '@ai-sdk/xai'
import {
experimental_createProviderRegistry as createProviderRegistry,
extractReasoningMiddleware,
Expand Down Expand Up @@ -34,7 +35,8 @@ export const registry = createProviderRegistry({
'openai-compatible': createOpenAI({
apiKey: process.env.OPENAI_COMPATIBLE_API_KEY,
baseURL: process.env.OPENAI_COMPATIBLE_API_BASE_URL
})
}),
xai
})

export function getModel(model: string) {
Expand Down Expand Up @@ -102,6 +104,8 @@ export function isProviderEnabled(providerId: string): boolean {
return !!process.env.DEEPSEEK_API_KEY
case 'fireworks':
return !!process.env.FIREWORKS_API_KEY
case 'xai':
return !!process.env.XAI_API_KEY
case 'openai-compatible':
return (
!!process.env.OPENAI_COMPATIBLE_API_KEY &&
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@ai-sdk/google": "^1.1.5",
"@ai-sdk/groq": "^1.1.6",
"@ai-sdk/openai": "^1.1.5",
"@ai-sdk/xai": "^1.1.10",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
Expand Down
7 changes: 7 additions & 0 deletions public/providers/logos/xai.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dd231d0

Please sign in to comment.