Skip to content

Commit ee36187

Browse files
dhamivibezAlemTuzlakautofix-ci[bot]
authored
feat(ai-groq): Add Groq adapter package (TanStack#332)
* feat(ai-groq): Add Groq adapter package Adds a new `@tanstack/ai-groq` package for Groq AI model integration. This package provides a tree-shakeable text adapter, supporting streaming chat completions, structured output, and tool usage. * chore: fix issues with PR * ci: apply automated fixes --------- Co-authored-by: Alem Tuzlak <t.zlak@hotmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 484daa1 commit ee36187

23 files changed

Lines changed: 2754 additions & 18 deletions

.changeset/free-impalas-doubt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/ai-groq': minor
3+
---
4+
5+
Adds a new @tanstack/ai-groq package(minor release), a Groq AI adapter for TanStack AI.

examples/ts-react-chat/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@tanstack/ai-client": "workspace:*",
1616
"@tanstack/ai-gemini": "workspace:*",
1717
"@tanstack/ai-grok": "workspace:*",
18+
"@tanstack/ai-groq": "workspace:*",
1819
"@tanstack/ai-ollama": "workspace:*",
1920
"@tanstack/ai-openai": "workspace:*",
2021
"@tanstack/ai-openrouter": "workspace:*",

examples/ts-react-chat/src/lib/model-selection.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type Provider =
44
| 'gemini'
55
| 'ollama'
66
| 'grok'
7+
| 'groq'
78
| 'openrouter'
89

910
export interface ModelOption {
@@ -91,6 +92,23 @@ export const MODEL_OPTIONS: Array<ModelOption> = [
9192
label: 'Ollama - SmolLM',
9293
},
9394

95+
// Groq
96+
{
97+
provider: 'groq',
98+
model: 'llama-3.3-70b-versatile',
99+
label: 'Groq - Llama 3.3 70B',
100+
},
101+
{
102+
provider: 'groq',
103+
model: 'meta-llama/llama-4-maverick-17b-128e-instruct',
104+
label: 'Groq - Llama 4 Maverick',
105+
},
106+
{
107+
provider: 'groq',
108+
model: 'meta-llama/llama-4-scout-17b-16e-instruct',
109+
label: 'Groq - Llama 4 Scout',
110+
},
111+
94112
// Grok
95113
{
96114
provider: 'grok',

examples/ts-react-chat/src/routes/api.tanchat.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { anthropicText } from '@tanstack/ai-anthropic'
1111
import { geminiText } from '@tanstack/ai-gemini'
1212
import { openRouterText } from '@tanstack/ai-openrouter'
1313
import { grokText } from '@tanstack/ai-grok'
14+
import { groqText } from '@tanstack/ai-groq'
1415
import type { AnyTextAdapter } from '@tanstack/ai'
1516
import {
1617
addToCartToolDef,
@@ -26,6 +27,7 @@ type Provider =
2627
| 'gemini'
2728
| 'ollama'
2829
| 'grok'
30+
| 'groq'
2931
| 'openrouter'
3032

3133
const SYSTEM_PROMPT = `You are a helpful assistant for a guitar store.
@@ -131,6 +133,13 @@ export const Route = createFileRoute('/api/tanchat')({
131133
adapter: grokText((model || 'grok-3') as 'grok-3'),
132134
modelOptions: {},
133135
}),
136+
groq: () =>
137+
createChatOptions({
138+
adapter: groqText(
139+
(model ||
140+
'llama-3.3-70b-versatile') as 'llama-3.3-70b-versatile',
141+
),
142+
}),
134143
ollama: () =>
135144
createChatOptions({
136145
adapter: ollamaText((model || 'gpt-oss:120b') as 'gpt-oss:120b'),

examples/ts-react-chat/src/routes/index.tsx

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,19 +264,25 @@ function ChatPage() {
264264
[selectedModel.provider, selectedModel.model],
265265
)
266266

267-
const { messages, sendMessage, isLoading, addToolApprovalResponse, stop } =
268-
useChat({
269-
connection: fetchServerSentEvents('/api/tanchat'),
270-
tools,
271-
body,
272-
onCustomEvent: (eventType, data, context) => {
273-
console.log(
274-
`[CustomEvent] ${eventType}`,
275-
data,
276-
context.toolCallId ? `(tool call: ${context.toolCallId})` : '',
277-
)
278-
},
279-
})
267+
const {
268+
messages,
269+
sendMessage,
270+
isLoading,
271+
error,
272+
addToolApprovalResponse,
273+
stop,
274+
} = useChat({
275+
connection: fetchServerSentEvents('/api/tanchat'),
276+
tools,
277+
body,
278+
onCustomEvent: (eventType, data, context) => {
279+
console.log(
280+
`[CustomEvent] ${eventType}`,
281+
data,
282+
context.toolCallId ? `(tool call: ${context.toolCallId})` : '',
283+
)
284+
},
285+
})
280286
const [input, setInput] = useState('')
281287

282288
/**
@@ -415,6 +421,12 @@ function ChatPage() {
415421
addToolApprovalResponse={addToolApprovalResponse}
416422
/>
417423

424+
{error && (
425+
<div className="mx-4 mt-2 p-3 bg-red-500/10 border border-red-500/30 rounded-lg text-red-400 text-sm">
426+
{error.message}
427+
</div>
428+
)}
429+
418430
<ChatInputArea>
419431
<div className="space-y-3">
420432
{isLoading && (
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# @tanstack/ai-groq
2+
3+
Groq adapter for TanStack AI
4+
5+
## Installation
6+
7+
```bash
8+
npm install @tanstack/ai-groq
9+
# or
10+
pnpm add @tanstack/ai-groq
11+
# or
12+
yarn add @tanstack/ai-groq
13+
```
14+
15+
## Setup
16+
17+
Get your API key from [Groq Console](https://console.groq.com) and set it as an environment variable:
18+
19+
```bash
20+
export GROQ_API_KEY="gsk_..."
21+
```
22+
23+
## Usage
24+
25+
### Text/Chat Adapter
26+
27+
```typescript
28+
import { groqText } from '@tanstack/ai-groq'
29+
import { generate } from '@tanstack/ai'
30+
31+
const adapter = groqText('llama-3.3-70b-versatile')
32+
33+
const result = await generate({
34+
adapter,
35+
model: 'llama-3.3-70b-versatile',
36+
messages: [
37+
{ role: 'user', content: 'Explain quantum computing in simple terms' },
38+
],
39+
})
40+
41+
console.log(result.text)
42+
```
43+
44+
### With Explicit API Key
45+
46+
```typescript
47+
import { createGroqText } from '@tanstack/ai-groq'
48+
49+
const adapter = createGroqText('llama-3.3-70b-versatile', 'gsk_api_key')
50+
```
51+
52+
## Supported Models
53+
54+
### Chat Models
55+
56+
- `llama-3.3-70b-versatile` - Meta Llama 3.3 70B (131k context)
57+
- `llama-3.1-8b-instant` - Meta Llama 3.1 8B (131k context)
58+
- `meta-llama/llama-4-maverick-17b-128e-instruct` - Meta Llama 4 Maverick (vision)
59+
- `meta-llama/llama-4-scout-17b-16e-instruct` - Meta Llama 4 Scout
60+
- `meta-llama/llama-guard-4-12b` - Meta Llama Guard 4 (content moderation, vision)
61+
- `meta-llama/llama-prompt-guard-2-86m` - Meta Llama Prompt Guard (content moderation)
62+
- `meta-llama/llama-prompt-guard-2-22m` - Meta Llama Prompt Guard (content moderation)
63+
- `openai/gpt-oss-120b` - GPT OSS 120B (reasoning, tools, search)
64+
- `openai/gpt-oss-20b` - GPT OSS 20B (reasoning, search)
65+
- `openai/gpt-oss-safeguard-20b` - GPT OSS Safeguard 20B (content moderation, reasoning)
66+
- `moonshotai/kimi-k2-instruct-0905` - Kimi K2 Instruct (262k context)
67+
- `qwen/qwen3-32b` - Qwen3 32B (reasoning, tools)
68+
69+
## Features
70+
71+
- ✅ Streaming chat completions
72+
- ✅ Structured output (JSON Schema)
73+
- ✅ Function/tool calling
74+
- ✅ Multimodal input (text + images for vision models)
75+
- ❌ Embeddings (not supported by Groq)
76+
- ❌ Image generation (not supported by Groq)
77+
78+
## Tree-Shakeable Adapters
79+
80+
This package uses tree-shakeable adapters, so you only import what you need:
81+
82+
```typescript
83+
// Only imports text adapter
84+
import { groqText } from '@tanstack/ai-groq'
85+
```
86+
87+
This keeps your bundle size small!
88+
89+
## License
90+
91+
MIT
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "@tanstack/ai-groq",
3+
"version": "0.0.0",
4+
"type": "module",
5+
"description": "Groq adapter for TanStack AI",
6+
"author": "",
7+
"license": "MIT",
8+
"repository": {
9+
"type": "git",
10+
"url": "git+https://github.com/TanStack/ai.git",
11+
"directory": "packages/typescript/ai-groq"
12+
},
13+
"module": "./dist/esm/index.js",
14+
"types": "./dist/esm/index.d.ts",
15+
"exports": {
16+
".": {
17+
"types": "./dist/esm/index.d.ts",
18+
"import": "./dist/esm/index.js"
19+
}
20+
},
21+
"files": [
22+
"dist",
23+
"src"
24+
],
25+
"scripts": {
26+
"build": "vite build",
27+
"clean": "premove ./build ./dist",
28+
"lint:fix": "eslint ./src --fix",
29+
"test:build": "publint --strict",
30+
"test:eslint": "eslint ./src",
31+
"test:lib": "vitest run",
32+
"test:lib:dev": "pnpm test:lib --watch",
33+
"test:types": "tsc"
34+
},
35+
"keywords": [
36+
"ai",
37+
"groq",
38+
"tanstack",
39+
"adapter"
40+
],
41+
"devDependencies": {
42+
"@vitest/coverage-v8": "4.0.14",
43+
"vite": "^7.2.7"
44+
},
45+
"peerDependencies": {
46+
"@tanstack/ai": "workspace:^",
47+
"zod": "^4.0.0"
48+
},
49+
"dependencies": {
50+
"groq-sdk": "^0.37.0"
51+
}
52+
}

0 commit comments

Comments
 (0)