ai-sdk-ollama 0.7.0 → 0.8.1
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 +71 -0
- package/README.md +92 -69
- package/dist/index.browser.cjs +171 -331
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +230 -163
- package/dist/index.browser.d.ts +230 -163
- package/dist/index.browser.js +173 -333
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +173 -335
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +230 -163
- package/dist/index.d.ts +230 -163
- package/dist/index.js +173 -333
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,76 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e57ddf2: ## Enhanced Function Renaming & Documentation Improvements
|
|
8
|
+
|
|
9
|
+
### Function Renaming
|
|
10
|
+
- Renamed `generateTextOllama` to `generateText` (enhanced version from ai-sdk-ollama)
|
|
11
|
+
- Renamed `streamTextOllama` to `streamText` (enhanced version from ai-sdk-ollama)
|
|
12
|
+
- Maintains backward compatibility while providing clearer API
|
|
13
|
+
|
|
14
|
+
### Documentation Improvements
|
|
15
|
+
- **README.md**: Complete restructure with better user flow
|
|
16
|
+
- Added Quick Start section with immediate installation and basic example
|
|
17
|
+
- Moved value proposition ("Why Choose") section earlier
|
|
18
|
+
- Added dedicated "Enhanced Tool Calling" section highlighting main differentiator
|
|
19
|
+
- Reorganized examples under "More Examples" for better progression
|
|
20
|
+
- Removed redundant content and improved clarity
|
|
21
|
+
- **packages/ai-sdk-ollama/README.md**: Applied same improvements
|
|
22
|
+
- Consistent structure with main README
|
|
23
|
+
- Better user journey from basic to advanced features
|
|
24
|
+
- Updated table of contents to match new structure
|
|
25
|
+
|
|
26
|
+
### Key Benefits
|
|
27
|
+
- **Better Developer Experience**: Clearer function names and improved documentation flow
|
|
28
|
+
- **Enhanced Tool Calling**: Highlighted the main selling point with dedicated section
|
|
29
|
+
- **User-Friendly**: Users can now get started in 30 seconds and understand value immediately
|
|
30
|
+
- **Consistent**: Both READMEs now have the same improved structure and flow
|
|
31
|
+
|
|
32
|
+
## 0.8.0
|
|
33
|
+
|
|
34
|
+
### Minor Changes
|
|
35
|
+
|
|
36
|
+
- 7ce6ed0: Enhanced tool calling with reliable wrapper functions
|
|
37
|
+
|
|
38
|
+
## What's New
|
|
39
|
+
- **New Enhanced Wrapper Functions**: Added `generateTextOllama()` and `streamTextOllama()` for guaranteed tool calling reliability
|
|
40
|
+
- **Automatic Response Synthesis**: Enhanced functions automatically complete responses when tools are executed but return empty text
|
|
41
|
+
- **Configurable Reliability Options**: Control synthesis behavior with `enhancedOptions` parameter
|
|
42
|
+
- **Improved Documentation**: Comprehensive examples and comparison tables for standard vs enhanced functions
|
|
43
|
+
|
|
44
|
+
## Key Features
|
|
45
|
+
- **Reliable Tool Calling**: Standard `generateText()` may return empty responses after tool execution. Enhanced wrappers guarantee complete, useful responses every time
|
|
46
|
+
- **Backward Compatible**: All existing code continues to work unchanged
|
|
47
|
+
- **Production Ready**: Designed for critical applications that can't handle unpredictable empty responses
|
|
48
|
+
- **Cross Provider Compatible**: Enhanced functions work with any AI SDK provider
|
|
49
|
+
|
|
50
|
+
## Breaking Changes
|
|
51
|
+
|
|
52
|
+
None - this is a purely additive enhancement.
|
|
53
|
+
|
|
54
|
+
## Migration
|
|
55
|
+
|
|
56
|
+
No migration required. Existing code works unchanged. To get enhanced reliability:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
// Before (may return empty text after tool calls)
|
|
60
|
+
const { text } = await generateText({
|
|
61
|
+
model: ollama('llama3.2'),
|
|
62
|
+
tools,
|
|
63
|
+
prompt,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// After (guaranteed complete responses)
|
|
67
|
+
const { text } = await generateTextOllama({
|
|
68
|
+
model: ollama('llama3.2'),
|
|
69
|
+
tools,
|
|
70
|
+
prompt,
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
3
74
|
## 0.7.0
|
|
4
75
|
|
|
5
76
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -7,29 +7,75 @@
|
|
|
7
7
|
|
|
8
8
|
A Vercel AI SDK v5+ provider for Ollama built on the official `ollama` package. Type safe, future proof, with cross provider compatibility and native Ollama features.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
## Quick Start
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install ai-sdk-ollama ai@^5.0.0
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { ollama } from 'ai-sdk-ollama';
|
|
18
|
+
import { generateText } from 'ai';
|
|
19
|
+
|
|
20
|
+
// Works in both Node.js and browsers
|
|
21
|
+
const { text } = await generateText({
|
|
22
|
+
model: ollama('llama3.2'),
|
|
23
|
+
prompt: 'Write a haiku about coding',
|
|
24
|
+
temperature: 0.8,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
console.log(text);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Why Choose AI SDK Ollama?
|
|
31
|
+
|
|
32
|
+
- ✅ **Solves tool calling problems** - Response synthesis for reliable tool execution
|
|
33
|
+
- ✅ **Enhanced wrapper functions** - `generateText` and `streamText` guarantees complete responses
|
|
34
|
+
- ✅ **Built-in reliability** - Default reliability features enabled automatically
|
|
35
|
+
- ✅ **Cross-provider compatibility** - Drop-in replacement for OpenAI, Anthropic, etc.
|
|
36
|
+
- ✅ **Type-safe** - Full TypeScript support with strict typing
|
|
37
|
+
- ✅ **Cross-environment** - Works in Node.js and browsers automatically
|
|
38
|
+
- ✅ **Native Ollama power** - Access advanced features like `mirostat`, `repeat_penalty`, `num_ctx`
|
|
39
|
+
- ✅ **Production ready** - Handles the core Ollama limitations other providers struggle with
|
|
40
|
+
|
|
41
|
+
## Enhanced Tool Calling
|
|
42
|
+
|
|
43
|
+
> **🚀 The Problem We Solve**: Standard Ollama providers often execute tools but return empty responses. Our enhanced functions guarantee complete, useful responses every time.
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { generateText, streamText } from 'ai-sdk-ollama';
|
|
47
|
+
|
|
48
|
+
// ✅ Enhanced generateText - guaranteed complete responses
|
|
49
|
+
const { text } = await generateText({
|
|
50
|
+
model: ollama('llama3.2'),
|
|
51
|
+
tools: { /* your tools */ },
|
|
52
|
+
prompt: 'Use the tools and explain the results'
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// ✅ Enhanced streaming - tool-aware streaming
|
|
56
|
+
const { textStream } = await streamText({
|
|
57
|
+
model: ollama('llama3.2'),
|
|
58
|
+
tools: { /* your tools */ },
|
|
59
|
+
prompt: 'Stream with tools'
|
|
60
|
+
});
|
|
61
|
+
```
|
|
16
62
|
|
|
17
63
|
## Contents
|
|
18
64
|
|
|
19
65
|
- [AI SDK Ollama Provider](#ai-sdk-ollama-provider)
|
|
66
|
+
- [Quick Start](#quick-start)
|
|
67
|
+
- [Why Choose AI SDK Ollama?](#why-choose-ai-sdk-ollama)
|
|
68
|
+
- [Enhanced Tool Calling](#enhanced-tool-calling)
|
|
20
69
|
- [Contents](#contents)
|
|
21
70
|
- [Prerequisites](#prerequisites)
|
|
22
|
-
- [Quick Start](#quick-start)
|
|
23
|
-
- [Installation](#installation)
|
|
24
|
-
- [Basic Usage](#basic-usage)
|
|
25
71
|
- [Browser Support](#browser-support)
|
|
26
72
|
- [Browser Usage](#browser-usage)
|
|
27
73
|
- [Explicit Browser Import](#explicit-browser-import)
|
|
28
74
|
- [CORS Configuration](#cors-configuration)
|
|
29
|
-
- [
|
|
75
|
+
- [More Examples](#more-examples)
|
|
30
76
|
- [Cross Provider Compatibility](#cross-provider-compatibility)
|
|
31
77
|
- [Native Ollama Power](#native-ollama-power)
|
|
32
|
-
- [Tool Calling
|
|
78
|
+
- [Enhanced Tool Calling Wrappers](#enhanced-tool-calling-wrappers)
|
|
33
79
|
- [Simple and Predictable](#simple-and-predictable)
|
|
34
80
|
- [Advanced Features](#advanced-features)
|
|
35
81
|
- [Custom Ollama Instance](#custom-ollama-instance)
|
|
@@ -76,16 +122,6 @@ const { text: advancedText } = await generateText({
|
|
|
76
122
|
- AI SDK v5+ (`ai` package)
|
|
77
123
|
- TypeScript 5.9+ (for TypeScript users)
|
|
78
124
|
|
|
79
|
-
## Quick Start
|
|
80
|
-
|
|
81
|
-
### Installation
|
|
82
|
-
|
|
83
|
-
```bash
|
|
84
|
-
npm install ai-sdk-ollama ai@^5.0.0
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
Ensure you have Ollama running locally:
|
|
88
|
-
|
|
89
125
|
```bash
|
|
90
126
|
# Install Ollama from ollama.com
|
|
91
127
|
ollama serve
|
|
@@ -94,39 +130,6 @@ ollama serve
|
|
|
94
130
|
ollama pull llama3.2
|
|
95
131
|
```
|
|
96
132
|
|
|
97
|
-
### Basic Usage
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
import { ollama } from 'ai-sdk-ollama';
|
|
101
|
-
import { generateText, streamText, embed } from 'ai';
|
|
102
|
-
|
|
103
|
-
// Simple text generation
|
|
104
|
-
const { text } = await generateText({
|
|
105
|
-
model: ollama('llama3.2'),
|
|
106
|
-
prompt: 'What is the capital of France?',
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
console.log(text); // "The capital of France is Paris."
|
|
110
|
-
|
|
111
|
-
// Streaming responses
|
|
112
|
-
const { textStream } = await streamText({
|
|
113
|
-
model: ollama('llama3.2'),
|
|
114
|
-
prompt: 'Tell me a story about a robot',
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
for await (const chunk of textStream) {
|
|
118
|
-
process.stdout.write(chunk);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Embeddings
|
|
122
|
-
const { embedding } = await embed({
|
|
123
|
-
model: ollama.embedding('nomic-embed-text'),
|
|
124
|
-
value: 'Hello world',
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
console.log(embedding.length); // 768 dimensions
|
|
128
|
-
```
|
|
129
|
-
|
|
130
133
|
## Browser Support
|
|
131
134
|
|
|
132
135
|
See the [browser example](../../examples/browser/).
|
|
@@ -173,7 +176,7 @@ OLLAMA_ORIGINS="http://localhost:3000,https://myapp.com" ollama serve
|
|
|
173
176
|
|
|
174
177
|
**Recommended**: Use a development proxy (like Vite proxy) to avoid CORS issues entirely. See the browser example for a complete working setup.
|
|
175
178
|
|
|
176
|
-
##
|
|
179
|
+
## More Examples
|
|
177
180
|
|
|
178
181
|
### Cross Provider Compatibility
|
|
179
182
|
|
|
@@ -210,35 +213,55 @@ const { text } = await generateText({
|
|
|
210
213
|
|
|
211
214
|
> **Parameter Precedence**: When both AI SDK parameters and Ollama options are specified, **Ollama options take precedence**. For example, if you set `temperature: 0.5` in Ollama options and `temperature: 0.8` in the `generateText` call, the final value will be `0.5`. This allows you to use standard AI SDK parameters for portability while having fine-grained control with Ollama-specific options when needed.
|
|
212
215
|
|
|
213
|
-
### Tool Calling
|
|
216
|
+
### Enhanced Tool Calling Wrappers
|
|
214
217
|
|
|
215
|
-
|
|
218
|
+
For maximum tool calling reliability, use our enhanced wrapper functions that guarantee complete responses:
|
|
216
219
|
|
|
217
220
|
```typescript
|
|
221
|
+
import { ollama, generateText, streamText } from 'ai-sdk-ollama';
|
|
222
|
+
import { tool } from 'ai';
|
|
218
223
|
import { z } from 'zod';
|
|
219
|
-
import { generateText, tool } from 'ai';
|
|
220
|
-
import { ollama } from 'ai-sdk-ollama';
|
|
221
224
|
|
|
222
|
-
|
|
225
|
+
// Enhanced generateText with automatic response synthesis
|
|
226
|
+
const result = await generateText({
|
|
223
227
|
model: ollama('llama3.2'),
|
|
224
|
-
prompt: 'What is the
|
|
228
|
+
prompt: 'What is 15 + 27? Use the math tool to calculate it.',
|
|
225
229
|
tools: {
|
|
226
|
-
|
|
227
|
-
description: '
|
|
230
|
+
math: tool({
|
|
231
|
+
description: 'Perform math calculations',
|
|
228
232
|
inputSchema: z.object({
|
|
229
|
-
|
|
230
|
-
unit: z.enum(['celsius', 'fahrenheit']).optional(),
|
|
233
|
+
operation: z.string().describe('Math operation like "15 + 27"'),
|
|
231
234
|
}),
|
|
232
|
-
execute: async ({
|
|
233
|
-
|
|
234
|
-
return { temp: 18, unit, condition: 'sunny' };
|
|
235
|
+
execute: async ({ operation }) => {
|
|
236
|
+
return { result: eval(operation), operation };
|
|
235
237
|
},
|
|
236
238
|
}),
|
|
237
239
|
},
|
|
240
|
+
// Optional: Configure reliability behavior
|
|
241
|
+
enhancedOptions: {
|
|
242
|
+
enableSynthesis: true, // Default: true
|
|
243
|
+
maxSynthesisAttempts: 2, // Default: 2
|
|
244
|
+
minResponseLength: 10, // Default: 10
|
|
245
|
+
},
|
|
238
246
|
});
|
|
247
|
+
|
|
248
|
+
console.log(result.text); // "15 + 27 equals 42. Using the math tool, I calculated..."
|
|
239
249
|
```
|
|
240
250
|
|
|
241
|
-
|
|
251
|
+
**When to Use Enhanced Wrappers:**
|
|
252
|
+
|
|
253
|
+
- **Critical tool calling scenarios** where you need guaranteed text responses
|
|
254
|
+
- **Production applications** that can't handle empty responses after tool execution
|
|
255
|
+
- **Complex multi-step tool interactions** requiring reliable synthesis
|
|
256
|
+
|
|
257
|
+
**Standard vs Enhanced Comparison:**
|
|
258
|
+
|
|
259
|
+
| Function | Standard `generateText` | Enhanced `generateText` |
|
|
260
|
+
| -------------------------- | ------------------------- | ------------------------------------ |
|
|
261
|
+
| **Simple prompts** | ✅ Perfect | ✅ Works (slight overhead) |
|
|
262
|
+
| **Tool calling** | ⚠️ May return empty text | ✅ **Guarantees complete responses** |
|
|
263
|
+
| **Complete responses** | ❌ Manual handling needed | ✅ **Automatic completion** |
|
|
264
|
+
| **Production reliability** | ⚠️ Unpredictable | ✅ **Reliable** |
|
|
242
265
|
|
|
243
266
|
### Simple and Predictable
|
|
244
267
|
|