Skip to content

Commit a87d242

Browse files
committed
feat: add Mistral provider adapter for TanStack AI
- Implemented MistralTextAdapter and related functions for chat completions. - Defined Mistral-specific message types and metadata structures. - Created model metadata for various Mistral models with pricing and capabilities. - Added text provider options and validation for Mistral text models. - Developed utility functions for Mistral client configuration and schema conversion. - Implemented function tool conversion for Mistral-specific formats. - Added tests for Mistral adapters, including event emissions and error handling. - Configured TypeScript and Vite for the new package.
1 parent cb07e01 commit a87d242

19 files changed

Lines changed: 2308 additions & 30 deletions

.changeset/add-ai-mistral.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/ai-mistral': minor
3+
---
4+
5+
Add new `@tanstack/ai-mistral` adapter package for Mistral models using the `@mistralai/mistralai` SDK. Supports streaming chat, tool calling, vision input (Pixtral / Mistral Medium / Small), and structured output via JSON Schema. Includes model metadata for Mistral Large, Medium, Small, Ministral 3B/8B, Codestral, Pixtral, Magistral, and Open Mistral Nemo.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# @tanstack/ai-mistral
2+
3+
Mistral adapter for TanStack AI.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @tanstack/ai-mistral
9+
# or
10+
pnpm add @tanstack/ai-mistral
11+
# or
12+
yarn add @tanstack/ai-mistral
13+
```
14+
15+
## Setup
16+
17+
Get your API key from [Mistral Console](https://console.mistral.ai/) and set it as an environment variable:
18+
19+
```bash
20+
export MISTRAL_API_KEY="..."
21+
```
22+
23+
## Usage
24+
25+
### Text/Chat Adapter
26+
27+
```typescript
28+
import { mistralText } from '@tanstack/ai-mistral'
29+
import { generate } from '@tanstack/ai'
30+
31+
const adapter = mistralText('mistral-large-latest')
32+
33+
const result = await generate({
34+
adapter,
35+
model: 'mistral-large-latest',
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 { createMistralText } from '@tanstack/ai-mistral'
48+
49+
const adapter = createMistralText('mistral-large-latest', 'api_key')
50+
```
51+
52+
## Supported Models
53+
54+
### Chat Models
55+
56+
- `mistral-large-latest` - Frontier flagship model (128k context)
57+
- `mistral-medium-latest` - Balanced multimodal model (vision)
58+
- `mistral-small-latest` - Fast, affordable multimodal model (vision)
59+
- `ministral-8b-latest` - 8B edge model
60+
- `ministral-3b-latest` - 3B edge model
61+
- `codestral-latest` - Code-specialized model (256k context)
62+
- `pixtral-large-latest` - Large vision model
63+
- `pixtral-12b-2409` - 12B vision model
64+
- `magistral-medium-latest` - Reasoning model
65+
- `magistral-small-latest` - Small reasoning model
66+
- `open-mistral-nemo` - Open 12B model
67+
68+
See [Mistral model comparison](https://docs.mistral.ai/getting-started/models/compare) for full details.
69+
70+
## Features
71+
72+
- ✅ Streaming chat completions
73+
- ✅ Structured output (JSON Schema)
74+
- ✅ Function/tool calling
75+
- ✅ Multimodal input (text + images for vision models)
76+
- ❌ Embeddings (use the Mistral SDK directly)
77+
- ❌ Image generation
78+
79+
## Tree-Shakeable Adapters
80+
81+
This package uses tree-shakeable adapters, so you only import what you need:
82+
83+
```typescript
84+
import { mistralText } from '@tanstack/ai-mistral'
85+
```
86+
87+
## License
88+
89+
MIT
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "@tanstack/ai-mistral",
3+
"version": "0.1.0",
4+
"type": "module",
5+
"description": "Mistral 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-mistral"
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+
"mistral",
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+
"@mistralai/mistralai": "^2.2.0"
51+
}
52+
}

0 commit comments

Comments
 (0)