ai-sdk-ollama 0.6.2 → 0.8.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 +97 -0
- package/README.md +59 -0
- package/dist/index.browser.cjs +1486 -12
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +395 -74
- package/dist/index.browser.d.ts +395 -74
- package/dist/index.browser.js +1486 -12
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +1489 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +395 -74
- package/dist/index.d.ts +395 -74
- package/dist/index.js +1486 -12
- package/dist/index.js.map +1 -1
- package/package.json +10 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,102 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7ce6ed0: Enhanced tool calling with reliable wrapper functions
|
|
8
|
+
|
|
9
|
+
## What's New
|
|
10
|
+
- **New Enhanced Wrapper Functions**: Added `generateTextOllama()` and `streamTextOllama()` for guaranteed tool calling reliability
|
|
11
|
+
- **Automatic Response Synthesis**: Enhanced functions automatically complete responses when tools are executed but return empty text
|
|
12
|
+
- **Configurable Reliability Options**: Control synthesis behavior with `enhancedOptions` parameter
|
|
13
|
+
- **Improved Documentation**: Comprehensive examples and comparison tables for standard vs enhanced functions
|
|
14
|
+
|
|
15
|
+
## Key Features
|
|
16
|
+
- **Reliable Tool Calling**: Standard `generateText()` may return empty responses after tool execution. Enhanced wrappers guarantee complete, useful responses every time
|
|
17
|
+
- **Backward Compatible**: All existing code continues to work unchanged
|
|
18
|
+
- **Production Ready**: Designed for critical applications that can't handle unpredictable empty responses
|
|
19
|
+
- **Cross Provider Compatible**: Enhanced functions work with any AI SDK provider
|
|
20
|
+
|
|
21
|
+
## Breaking Changes
|
|
22
|
+
|
|
23
|
+
None - this is a purely additive enhancement.
|
|
24
|
+
|
|
25
|
+
## Migration
|
|
26
|
+
|
|
27
|
+
No migration required. Existing code works unchanged. To get enhanced reliability:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
// Before (may return empty text after tool calls)
|
|
31
|
+
const { text } = await generateText({
|
|
32
|
+
model: ollama('llama3.2'),
|
|
33
|
+
tools,
|
|
34
|
+
prompt,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// After (guaranteed complete responses)
|
|
38
|
+
const { text } = await generateTextOllama({
|
|
39
|
+
model: ollama('llama3.2'),
|
|
40
|
+
tools,
|
|
41
|
+
prompt,
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 0.7.0
|
|
46
|
+
|
|
47
|
+
### Minor Changes
|
|
48
|
+
|
|
49
|
+
- 8f0a292: Comprehensive reliability improvements and new Ollama-specific functions
|
|
50
|
+
|
|
51
|
+
## New Features
|
|
52
|
+
|
|
53
|
+
### Ollama-Specific AI Functions
|
|
54
|
+
- **generateTextOllama**: Enhanced text generation with reliability features
|
|
55
|
+
- **generateObjectOllama**: Structured object generation with schema validation
|
|
56
|
+
- **streamTextOllama**: Real-time text streaming with tool calling support
|
|
57
|
+
- **streamObjectOllama**: Progressive object streaming with reliability features
|
|
58
|
+
|
|
59
|
+
### Reliability Features
|
|
60
|
+
- **Tool Calling Reliability**: Enhanced tool calling with retry logic and parameter normalization
|
|
61
|
+
- **Object Generation Reliability**: Schema validation, type mismatch fixing, and fallback generation
|
|
62
|
+
- **Streaming Reliability**: Better stop conditions and response synthesis
|
|
63
|
+
- **Error Recovery**: Automatic retry mechanisms and graceful error handling
|
|
64
|
+
|
|
65
|
+
## Examples and Documentation
|
|
66
|
+
|
|
67
|
+
### New Example Files
|
|
68
|
+
- **Comprehensive Demo**: `generate-all-ollama-demo.ts` - showcases all Ollama-specific functions
|
|
69
|
+
- **Streaming Demos**: `stream-text-ollama-demo.ts` and `stream-object-ollama-demo.ts`
|
|
70
|
+
- **Debug Tools**: `debug-streaming-issue.ts` and `debug-gpt-oss-tools.ts`
|
|
71
|
+
- **Testing Examples**: Various test files for different use cases
|
|
72
|
+
|
|
73
|
+
### Enhanced Examples
|
|
74
|
+
- **Browser Example**: Fixed to use `createOllama()` for proper provider configuration
|
|
75
|
+
- **Node Examples**: Updated with better error handling and TypeScript compliance
|
|
76
|
+
- **Tool Calling**: Comprehensive examples with weather and search tools
|
|
77
|
+
|
|
78
|
+
## Technical Improvements
|
|
79
|
+
|
|
80
|
+
### TypeScript Fixes
|
|
81
|
+
- Fixed variable naming conflicts in all example files
|
|
82
|
+
- Resolved async/await issues with tool calls
|
|
83
|
+
- Fixed Zod schema definitions for record types
|
|
84
|
+
- Improved type safety across all examples
|
|
85
|
+
|
|
86
|
+
### API Enhancements
|
|
87
|
+
- Better error messages and debugging information
|
|
88
|
+
- Enhanced configuration options for reliability features
|
|
89
|
+
- Improved streaming performance and reliability
|
|
90
|
+
- Better integration with Ollama's native capabilities
|
|
91
|
+
|
|
92
|
+
## Breaking Changes
|
|
93
|
+
|
|
94
|
+
None - all changes are backward compatible
|
|
95
|
+
|
|
96
|
+
## Migration Guide
|
|
97
|
+
|
|
98
|
+
Existing code continues to work unchanged. New Ollama-specific functions are available as additional options for enhanced reliability.
|
|
99
|
+
|
|
3
100
|
## 0.6.2
|
|
4
101
|
|
|
5
102
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -7,6 +7,14 @@
|
|
|
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
|
+
> **🚀 Reliable Tool Calling**: This provider includes built-in reliability features enabled by default, plus enhanced wrapper functions for guaranteed tool calling success:
|
|
11
|
+
>
|
|
12
|
+
> - **Standard**: `generateText({ model: ollama('llama3.2'), tools, prompt })` - works with built-in reliability
|
|
13
|
+
> - **Enhanced**: `generateTextOllama({ model: ollama('llama3.2'), tools, prompt })` - reliable tool calling
|
|
14
|
+
> - **Streaming**: `streamTextOllama()` - enhanced streaming with tool awareness
|
|
15
|
+
>
|
|
16
|
+
> **The Problem We Solve**: Standard Ollama providers often execute tools but return empty responses. Our enhanced functions guarantee complete, useful responses every time.
|
|
17
|
+
|
|
10
18
|
## Contents
|
|
11
19
|
|
|
12
20
|
- [AI SDK Ollama Provider](#ai-sdk-ollama-provider)
|
|
@@ -23,6 +31,7 @@ A Vercel AI SDK v5+ provider for Ollama built on the official `ollama` package.
|
|
|
23
31
|
- [Cross Provider Compatibility](#cross-provider-compatibility)
|
|
24
32
|
- [Native Ollama Power](#native-ollama-power)
|
|
25
33
|
- [Tool Calling Support](#tool-calling-support)
|
|
34
|
+
- [Enhanced Tool Calling Wrappers](#enhanced-tool-calling-wrappers)
|
|
26
35
|
- [Simple and Predictable](#simple-and-predictable)
|
|
27
36
|
- [Advanced Features](#advanced-features)
|
|
28
37
|
- [Custom Ollama Instance](#custom-ollama-instance)
|
|
@@ -233,6 +242,56 @@ const { text, toolCalls } = await generateText({
|
|
|
233
242
|
|
|
234
243
|
> **Note on Tool Parameters**: Due to Zod version compatibility issues, tool schemas may not always convert properly. When this happens, Ollama may use different parameter names than defined in your schema. It's recommended to handle parameter variations in your tool's execute function (e.g., checking for both `location` and `city`).
|
|
235
244
|
|
|
245
|
+
### Enhanced Tool Calling Wrappers
|
|
246
|
+
|
|
247
|
+
For maximum tool calling reliability, use our enhanced wrapper functions that guarantee complete responses:
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import { ollama, generateTextOllama, streamTextOllama } from 'ai-sdk-ollama';
|
|
251
|
+
import { tool } from 'ai';
|
|
252
|
+
import { z } from 'zod';
|
|
253
|
+
|
|
254
|
+
// Enhanced generateText with automatic response synthesis
|
|
255
|
+
const result = await generateTextOllama({
|
|
256
|
+
model: ollama('llama3.2'),
|
|
257
|
+
prompt: 'What is 15 + 27? Use the math tool to calculate it.',
|
|
258
|
+
tools: {
|
|
259
|
+
math: tool({
|
|
260
|
+
description: 'Perform math calculations',
|
|
261
|
+
inputSchema: z.object({
|
|
262
|
+
operation: z.string().describe('Math operation like "15 + 27"'),
|
|
263
|
+
}),
|
|
264
|
+
execute: async ({ operation }) => {
|
|
265
|
+
return { result: eval(operation), operation };
|
|
266
|
+
},
|
|
267
|
+
}),
|
|
268
|
+
},
|
|
269
|
+
// Optional: Configure reliability behavior
|
|
270
|
+
enhancedOptions: {
|
|
271
|
+
enableSynthesis: true, // Default: true
|
|
272
|
+
maxSynthesisAttempts: 2, // Default: 2
|
|
273
|
+
minResponseLength: 10, // Default: 10
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
console.log(result.text); // "15 + 27 equals 42. Using the math tool, I calculated..."
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**When to Use Enhanced Wrappers:**
|
|
281
|
+
|
|
282
|
+
- **Critical tool calling scenarios** where you need guaranteed text responses
|
|
283
|
+
- **Production applications** that can't handle empty responses after tool execution
|
|
284
|
+
- **Complex multi-step tool interactions** requiring reliable synthesis
|
|
285
|
+
|
|
286
|
+
**Standard vs Enhanced Comparison:**
|
|
287
|
+
|
|
288
|
+
| Function | Standard `generateText` | Enhanced `generateTextOllama` |
|
|
289
|
+
| -------------------------- | ------------------------- | ------------------------------------ |
|
|
290
|
+
| **Simple prompts** | ✅ Perfect | ✅ Works (slight overhead) |
|
|
291
|
+
| **Tool calling** | ⚠️ May return empty text | ✅ **Guarantees complete responses** |
|
|
292
|
+
| **Complete responses** | ❌ Manual handling needed | ✅ **Automatic completion** |
|
|
293
|
+
| **Production reliability** | ⚠️ Unpredictable | ✅ **Reliable** |
|
|
294
|
+
|
|
236
295
|
### Simple and Predictable
|
|
237
296
|
|
|
238
297
|
The provider works the same way with any model - just try the features you need:
|