ai-sdk-ollama 3.8.8 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +44 -32
- package/dist/index.browser.cjs +312 -234
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +441 -22
- package/dist/index.browser.d.ts +441 -22
- package/dist/index.browser.js +312 -234
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +312 -234
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +452 -33
- package/dist/index.d.ts +452 -33
- package/dist/index.js +312 -234
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- cbf2dd6: Add support for Vercel AI SDK v7 (beta).
|
|
8
|
+
|
|
9
|
+
- Bump peer dependency to `ai@^7`, and dependencies to `@ai-sdk/provider@4` and `@ai-sdk/provider-utils@5`.
|
|
10
|
+
- Migrate all models (chat, embedding, image, reranking) to the `LanguageModelV4` / `EmbeddingModelV4` / `ImageModelV4` / `RerankingModelV4` provider specs, declaring `specificationVersion: 'v4'`.
|
|
11
|
+
- Read the new `SharedV4FileData` tagged file-data union for image inputs, and the consolidated `file` tool-result output type (was `image-data` / `image-url` / `file-data`). Fixes multimodal image inputs under v7.
|
|
12
|
+
- Update the `tool()` helper usages (web search / web fetch) for the v7 `ToolExecutionOptions` and 3-generic `Tool<INPUT, OUTPUT, CONTEXT>` signature.
|
|
13
|
+
- Support the new per-call `reasoning` effort option (`LanguageModelV4CallOptions.reasoning`). The provider maps `'none'`/`'minimal'`/`'low'`/`'medium'`/`'high'`/`'xhigh'`/`'provider-default'` onto Ollama's `think` parameter, overriding the model-level `think` setting, so you can set reasoning effort per request.
|
|
14
|
+
|
|
15
|
+
BREAKING: This release requires `ai@^7`. AI SDK v7 renamed the re-exported agent callback types `ToolLoopAgentOnFinishCallback` and `ToolLoopAgentOnStepFinishCallback` to `GenerateTextOnFinishCallback` and `GenerateTextOnStepFinishCallback`.
|
|
16
|
+
|
|
17
|
+
## 4.0.0-beta.0
|
|
18
|
+
|
|
19
|
+
### Major Changes
|
|
20
|
+
|
|
21
|
+
- cbf2dd6: Add support for Vercel AI SDK v7 (beta).
|
|
22
|
+
|
|
23
|
+
- Bump peer dependency to `ai@^7`, and dependencies to `@ai-sdk/provider@4` and `@ai-sdk/provider-utils@5`.
|
|
24
|
+
- Migrate all models (chat, embedding, image, reranking) to the `LanguageModelV4` / `EmbeddingModelV4` / `ImageModelV4` / `RerankingModelV4` provider specs, declaring `specificationVersion: 'v4'`.
|
|
25
|
+
- Read the new `SharedV4FileData` tagged file-data union for image inputs, and the consolidated `file` tool-result output type (was `image-data` / `image-url` / `file-data`). Fixes multimodal image inputs under v7.
|
|
26
|
+
- Update the `tool()` helper usages (web search / web fetch) for the v7 `ToolExecutionOptions` and 3-generic `Tool<INPUT, OUTPUT, CONTEXT>` signature.
|
|
27
|
+
- Support the new per-call `reasoning` effort option (`LanguageModelV4CallOptions.reasoning`). The provider maps `'none'`/`'minimal'`/`'low'`/`'medium'`/`'high'`/`'xhigh'`/`'provider-default'` onto Ollama's `think` parameter, overriding the model-level `think` setting, so you can set reasoning effort per request.
|
|
28
|
+
|
|
29
|
+
BREAKING: This release requires `ai@^7`. AI SDK v7 renamed the re-exported agent callback types `ToolLoopAgentOnFinishCallback` and `ToolLoopAgentOnStepFinishCallback` to `GenerateTextOnFinishCallback` and `GenerateTextOnStepFinishCallback`.
|
|
30
|
+
|
|
3
31
|
## 3.8.8
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -5,14 +5,28 @@
|
|
|
5
5
|
[](https://nodejs.org/)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
|
-
A Vercel AI SDK
|
|
9
|
-
|
|
10
|
-
>
|
|
8
|
+
A Vercel AI SDK provider for Ollama, built on the official `ollama` package. Type-safe, cross-provider compatible, with access to native Ollama features.
|
|
9
|
+
|
|
10
|
+
> **Version compatibility**
|
|
11
|
+
>
|
|
12
|
+
> Each `ai-sdk-ollama` major targets one AI SDK major. Every line stays published on npm, so pick the one that matches your `ai` version:
|
|
13
|
+
>
|
|
14
|
+
> | `ai-sdk-ollama` | `ai` (peer) | Status |
|
|
15
|
+
> | ----------------- | ----------- | --------------------------------- |
|
|
16
|
+
> | `4.x` (`@latest`) | `ai@^7` | Active. New features land here. |
|
|
17
|
+
> | `3.x` | `ai@^6` | Maintenance. Critical fixes only. |
|
|
18
|
+
> | `2.x` | `ai@^5` | Unmaintained. |
|
|
19
|
+
>
|
|
20
|
+
> AI SDK v7 is stable, so v4 installs from `latest`. The v3 line still works for AI SDK v6.
|
|
11
21
|
|
|
12
22
|
## Quick Start
|
|
13
23
|
|
|
14
24
|
```bash
|
|
15
|
-
|
|
25
|
+
# AI SDK v7 (stable)
|
|
26
|
+
npm install ai-sdk-ollama ai
|
|
27
|
+
|
|
28
|
+
# AI SDK v6
|
|
29
|
+
npm install ai-sdk-ollama@^3 ai@^6
|
|
16
30
|
```
|
|
17
31
|
|
|
18
32
|
```typescript
|
|
@@ -31,24 +45,24 @@ console.log(text);
|
|
|
31
45
|
|
|
32
46
|
## Why Choose AI SDK Ollama?
|
|
33
47
|
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
48
|
+
- **Reliable tool calling** - Response synthesis adds text after tool execution, so you don't get empty replies
|
|
49
|
+
- **Wrapper functions** - `generateText` and `streamText` return complete responses
|
|
50
|
+
- **Built-in reliability** - Reliability features run by default
|
|
51
|
+
- **Automatic JSON repair** - Cascade repair runs [jsonrepair](https://github.com/josdejong/jsonrepair) first, then an Ollama-specific fallback for trailing commas, comments, URLs, and Python constants
|
|
52
|
+
- **Web search and fetch** - Built-in tools powered by [Ollama's web search API](https://ollama.com/blog/web-search) for current information
|
|
53
|
+
- **Type-safe** - Full TypeScript support with strict typing
|
|
54
|
+
- **Cross-environment** - Runs in Node.js and browsers automatically
|
|
55
|
+
- **Native Ollama options** - Use `mirostat`, `repeat_penalty`, `num_ctx`, and more
|
|
56
|
+
- **Production-ready** - Handles the tool-call and JSON edge cases that otherwise need manual workarounds
|
|
43
57
|
|
|
44
58
|
## Enhanced Tool Calling
|
|
45
59
|
|
|
46
|
-
>
|
|
60
|
+
> **The problem this solves**: Standard Ollama providers can execute a tool and then return empty text. These wrapper functions synthesize a response so you get complete output.
|
|
47
61
|
|
|
48
62
|
```typescript
|
|
49
63
|
import { ollama, generateText, streamText } from 'ai-sdk-ollama';
|
|
50
64
|
|
|
51
|
-
//
|
|
65
|
+
// Enhanced generateText - returns complete responses after tool calls
|
|
52
66
|
const { text } = await generateText({
|
|
53
67
|
model: ollama('llama3.2'),
|
|
54
68
|
tools: {
|
|
@@ -57,7 +71,7 @@ const { text } = await generateText({
|
|
|
57
71
|
prompt: 'Use the tools and explain the results',
|
|
58
72
|
});
|
|
59
73
|
|
|
60
|
-
//
|
|
74
|
+
// Enhanced streaming - tool-aware streaming
|
|
61
75
|
const { textStream } = await streamText({
|
|
62
76
|
model: ollama('llama3.2'),
|
|
63
77
|
tools: {
|
|
@@ -69,7 +83,7 @@ const { textStream } = await streamText({
|
|
|
69
83
|
|
|
70
84
|
## Web Search Tools
|
|
71
85
|
|
|
72
|
-
>
|
|
86
|
+
> **Web search and fetch**: Built-in tools powered by [Ollama's web search API](https://ollama.com/blog/web-search) for current information.
|
|
73
87
|
|
|
74
88
|
```typescript
|
|
75
89
|
import { generateText } from 'ai';
|
|
@@ -191,7 +205,7 @@ const { text: advancedText } = await generateText({
|
|
|
191
205
|
|
|
192
206
|
- Node.js 22+
|
|
193
207
|
- [Ollama](https://ollama.com) installed locally or running on a remote server
|
|
194
|
-
- AI SDK
|
|
208
|
+
- AI SDK v7 (`ai` package)
|
|
195
209
|
- TypeScript 5.9+ (for TypeScript users)
|
|
196
210
|
|
|
197
211
|
```bash
|
|
@@ -319,7 +333,7 @@ const { text } = await generateText({
|
|
|
319
333
|
|
|
320
334
|
### Enhanced Tool Calling Wrappers
|
|
321
335
|
|
|
322
|
-
For
|
|
336
|
+
For reliable tool calling, use the enhanced wrapper functions that return complete responses:
|
|
323
337
|
|
|
324
338
|
```typescript
|
|
325
339
|
import { ollama, generateText, streamText } from 'ai-sdk-ollama';
|
|
@@ -374,9 +388,7 @@ const weatherTool = tool({
|
|
|
374
388
|
}),
|
|
375
389
|
});
|
|
376
390
|
|
|
377
|
-
// AI SDK
|
|
378
|
-
import { ollama } from 'ai-sdk-ollama';
|
|
379
|
-
|
|
391
|
+
// AI SDK v7: tools and structured output work together by default
|
|
380
392
|
const result = await generateText({
|
|
381
393
|
model: ollama('llama3.2'),
|
|
382
394
|
prompt: 'Get weather for San Francisco and provide a structured summary',
|
|
@@ -395,18 +407,18 @@ const result = await generateText({
|
|
|
395
407
|
|
|
396
408
|
**When to Use Enhanced Wrappers:**
|
|
397
409
|
|
|
398
|
-
- **Critical tool calling scenarios** where you need
|
|
410
|
+
- **Critical tool calling scenarios** where you need a text response after the tool runs
|
|
399
411
|
- **Production applications** that can't handle empty responses after tool execution
|
|
400
412
|
- **Complex multi-step tool interactions** requiring reliable synthesis
|
|
401
413
|
|
|
402
414
|
**Standard vs Enhanced Comparison:**
|
|
403
415
|
|
|
404
|
-
| Function | Standard `generateText` | Enhanced `generateText`
|
|
405
|
-
| -------------------------- | ------------------------- |
|
|
406
|
-
| **Simple prompts** | ✅ Perfect | ✅ Works (slight overhead)
|
|
407
|
-
| **Tool calling** | ⚠️ May return empty text | ✅ **
|
|
408
|
-
| **Complete responses** | ❌ Manual handling needed | ✅ **Automatic completion**
|
|
409
|
-
| **Production reliability** | ⚠️ Unpredictable | ✅ **Reliable**
|
|
416
|
+
| Function | Standard `generateText` | Enhanced `generateText` |
|
|
417
|
+
| -------------------------- | ------------------------- | --------------------------------- |
|
|
418
|
+
| **Simple prompts** | ✅ Perfect | ✅ Works (slight overhead) |
|
|
419
|
+
| **Tool calling** | ⚠️ May return empty text | ✅ **Returns complete responses** |
|
|
420
|
+
| **Complete responses** | ❌ Manual handling needed | ✅ **Automatic completion** |
|
|
421
|
+
| **Production reliability** | ⚠️ Unpredictable | ✅ **Reliable** |
|
|
410
422
|
|
|
411
423
|
### Simple and Predictable
|
|
412
424
|
|
|
@@ -430,7 +442,7 @@ const { text } = await generateText({
|
|
|
430
442
|
|
|
431
443
|
## Reranking
|
|
432
444
|
|
|
433
|
-
> **
|
|
445
|
+
> **Reranking**: Rank documents by semantic relevance for search results and RAG pipelines.
|
|
434
446
|
|
|
435
447
|
Since Ollama doesn't have native reranking yet, we provide embedding-based reranking using cosine similarity:
|
|
436
448
|
|
|
@@ -818,7 +830,7 @@ const { text } = await generateText({
|
|
|
818
830
|
|
|
819
831
|
### Automatic JSON Repair
|
|
820
832
|
|
|
821
|
-
>
|
|
833
|
+
> **Cascade JSON repair**: Built-in repair fixes malformed model output during object generation.
|
|
822
834
|
|
|
823
835
|
Repair uses a **cascade**: the [jsonrepair](https://github.com/josdejong/jsonrepair) library runs first (standard JSON issues), then the built-in Ollama-specific repair runs if needed (e.g. Python `True`/`None`, URLs with `//`, smart quotes). You can use the default, disable repair with `enableTextRepair: false`, or pass a custom `repairText` function. Exported helpers: `cascadeRepairText`, `enhancedRepairText` (see [test-cascade-repair example](../../examples/node/src/test-cascade-repair.ts)).
|
|
824
836
|
|
|
@@ -956,7 +968,7 @@ Install with: `ollama pull deepseek-r1:7b`
|
|
|
956
968
|
- **Model compatibility errors** - The provider will throw errors if you try to use unsupported features (e.g., tools with non-compatible models)
|
|
957
969
|
- **Network issues** - Verify Ollama is accessible at the configured URL
|
|
958
970
|
- **TypeScript support** - Full type safety with TypeScript 5.9+
|
|
959
|
-
- **AI SDK
|
|
971
|
+
- **AI SDK v7 compatibility** - Built for the AI SDK v7 specification
|
|
960
972
|
|
|
961
973
|
## Supported Models
|
|
962
974
|
|