ai-sdk-ollama 0.8.0 → 0.9.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 CHANGED
@@ -1,5 +1,45 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 35f19de: Add web search and web fetch tools for Ollama integration
8
+ - Add `webSearch` tool for performing web searches using Ollama's web search capabilities
9
+ - Add `webFetch` tool for fetching web content and URLs
10
+ - Support for both browser and Node.js environments
11
+ - Comprehensive integration tests and examples
12
+ - Updated documentation with usage examples and prerequisites
13
+
14
+ ## 0.8.1
15
+
16
+ ### Patch Changes
17
+
18
+ - e57ddf2: ## Enhanced Function Renaming & Documentation Improvements
19
+
20
+ ### Function Renaming
21
+ - Renamed `generateTextOllama` to `generateText` (enhanced version from ai-sdk-ollama)
22
+ - Renamed `streamTextOllama` to `streamText` (enhanced version from ai-sdk-ollama)
23
+ - Maintains backward compatibility while providing clearer API
24
+
25
+ ### Documentation Improvements
26
+ - **README.md**: Complete restructure with better user flow
27
+ - Added Quick Start section with immediate installation and basic example
28
+ - Moved value proposition ("Why Choose") section earlier
29
+ - Added dedicated "Enhanced Tool Calling" section highlighting main differentiator
30
+ - Reorganized examples under "More Examples" for better progression
31
+ - Removed redundant content and improved clarity
32
+ - **packages/ai-sdk-ollama/README.md**: Applied same improvements
33
+ - Consistent structure with main README
34
+ - Better user journey from basic to advanced features
35
+ - Updated table of contents to match new structure
36
+
37
+ ### Key Benefits
38
+ - **Better Developer Experience**: Clearer function names and improved documentation flow
39
+ - **Enhanced Tool Calling**: Highlighted the main selling point with dedicated section
40
+ - **User-Friendly**: Users can now get started in 30 seconds and understand value immediately
41
+ - **Consistent**: Both READMEs now have the same improved structure and flow
42
+
3
43
  ## 0.8.0
4
44
 
5
45
  ### Minor Changes
package/README.md CHANGED
@@ -7,30 +7,131 @@
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.
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
+ - ✅ **Web search and fetch tools** - Built-in web search and fetch tools powered by [Ollama's web search API](https://ollama.com/blog/web-search). Perfect for getting current information and reducing hallucinations.
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: {
52
+ /* your tools */
53
+ },
54
+ prompt: 'Use the tools and explain the results',
55
+ });
56
+
57
+ // ✅ Enhanced streaming - tool-aware streaming
58
+ const { textStream } = await streamText({
59
+ model: ollama('llama3.2'),
60
+ tools: {
61
+ /* your tools */
62
+ },
63
+ prompt: 'Stream with tools',
64
+ });
65
+ ```
66
+
67
+ ## Web Search Tools
68
+
69
+ > **🌐 New in v0.9.0**: Built-in web search and fetch tools powered by [Ollama's web search API](https://ollama.com/blog/web-search). Perfect for getting current information and reducing hallucinations.
70
+
71
+ ```typescript
72
+ import { generateText } from 'ai';
73
+ import { ollama } from 'ai-sdk-ollama';
74
+
75
+ // 🔍 Web search for current information
76
+ const { text } = await generateText({
77
+ model: ollama('qwen3-coder:480b-cloud'), // Cloud models recommended for web search
78
+ prompt: 'What are the latest developments in AI this week?',
79
+ tools: {
80
+ webSearch: ollama.tools.webSearch({ maxResults: 5 }),
81
+ },
82
+ });
83
+
84
+ // 📄 Fetch specific web content
85
+ const { text: summary } = await generateText({
86
+ model: ollama('gpt-oss:120b-cloud'),
87
+ prompt: 'Summarize this article: https://example.com/article',
88
+ tools: {
89
+ webFetch: ollama.tools.webFetch({ maxContentLength: 5000 }),
90
+ },
91
+ });
92
+
93
+ // 🔄 Combine search and fetch for comprehensive research
94
+ const { text: research } = await generateText({
95
+ model: ollama('gpt-oss:120b-cloud'),
96
+ prompt: 'Research recent TypeScript updates and provide a detailed analysis',
97
+ tools: {
98
+ webSearch: ollama.tools.webSearch({ maxResults: 3 }),
99
+ webFetch: ollama.tools.webFetch(),
100
+ },
101
+ });
102
+ ```
103
+
104
+ ### Web Search Prerequisites
105
+
106
+ 1. **Ollama API Key**: Set `OLLAMA_API_KEY` environment variable
107
+ 2. **Cloud Models**: Use cloud models for optimal web search performance:
108
+ - `qwen3-coder:480b-cloud` - Best for general web search
109
+ - `gpt-oss:120b-cloud` - Best for complex reasoning with web data
110
+
111
+ ```bash
112
+ # Set your API key
113
+ export OLLAMA_API_KEY="your_api_key_here"
114
+
115
+ # Get your API key from: https://ollama.com/account
116
+ ```
17
117
 
18
118
  ## Contents
19
119
 
20
120
  - [AI SDK Ollama Provider](#ai-sdk-ollama-provider)
121
+ - [Quick Start](#quick-start)
122
+ - [Why Choose AI SDK Ollama?](#why-choose-ai-sdk-ollama)
123
+ - [Enhanced Tool Calling](#enhanced-tool-calling)
124
+ - [Web Search Tools](#web-search-tools)
125
+ - [Web Search Prerequisites](#web-search-prerequisites)
21
126
  - [Contents](#contents)
22
127
  - [Prerequisites](#prerequisites)
23
- - [Quick Start](#quick-start)
24
- - [Installation](#installation)
25
- - [Basic Usage](#basic-usage)
26
128
  - [Browser Support](#browser-support)
27
129
  - [Browser Usage](#browser-usage)
28
130
  - [Explicit Browser Import](#explicit-browser-import)
29
131
  - [CORS Configuration](#cors-configuration)
30
- - [Key Features](#key-features)
132
+ - [More Examples](#more-examples)
31
133
  - [Cross Provider Compatibility](#cross-provider-compatibility)
32
134
  - [Native Ollama Power](#native-ollama-power)
33
- - [Tool Calling Support](#tool-calling-support)
34
135
  - [Enhanced Tool Calling Wrappers](#enhanced-tool-calling-wrappers)
35
136
  - [Simple and Predictable](#simple-and-predictable)
36
137
  - [Advanced Features](#advanced-features)
@@ -78,16 +179,6 @@ const { text: advancedText } = await generateText({
78
179
  - AI SDK v5+ (`ai` package)
79
180
  - TypeScript 5.9+ (for TypeScript users)
80
181
 
81
- ## Quick Start
82
-
83
- ### Installation
84
-
85
- ```bash
86
- npm install ai-sdk-ollama ai@^5.0.0
87
- ```
88
-
89
- Ensure you have Ollama running locally:
90
-
91
182
  ```bash
92
183
  # Install Ollama from ollama.com
93
184
  ollama serve
@@ -96,39 +187,6 @@ ollama serve
96
187
  ollama pull llama3.2
97
188
  ```
98
189
 
99
- ### Basic Usage
100
-
101
- ```typescript
102
- import { ollama } from 'ai-sdk-ollama';
103
- import { generateText, streamText, embed } from 'ai';
104
-
105
- // Simple text generation
106
- const { text } = await generateText({
107
- model: ollama('llama3.2'),
108
- prompt: 'What is the capital of France?',
109
- });
110
-
111
- console.log(text); // "The capital of France is Paris."
112
-
113
- // Streaming responses
114
- const { textStream } = await streamText({
115
- model: ollama('llama3.2'),
116
- prompt: 'Tell me a story about a robot',
117
- });
118
-
119
- for await (const chunk of textStream) {
120
- process.stdout.write(chunk);
121
- }
122
-
123
- // Embeddings
124
- const { embedding } = await embed({
125
- model: ollama.embedding('nomic-embed-text'),
126
- value: 'Hello world',
127
- });
128
-
129
- console.log(embedding.length); // 768 dimensions
130
- ```
131
-
132
190
  ## Browser Support
133
191
 
134
192
  See the [browser example](../../examples/browser/).
@@ -175,7 +233,7 @@ OLLAMA_ORIGINS="http://localhost:3000,https://myapp.com" ollama serve
175
233
 
176
234
  **Recommended**: Use a development proxy (like Vite proxy) to avoid CORS issues entirely. See the browser example for a complete working setup.
177
235
 
178
- ## Key Features
236
+ ## More Examples
179
237
 
180
238
  ### Cross Provider Compatibility
181
239
 
@@ -212,47 +270,17 @@ const { text } = await generateText({
212
270
 
213
271
  > **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.
214
272
 
215
- ### Tool Calling Support
216
-
217
- Ollama supports tool calling with compatible models.
218
-
219
- ```typescript
220
- import { z } from 'zod';
221
- import { generateText, tool } from 'ai';
222
- import { ollama } from 'ai-sdk-ollama';
223
-
224
- const { text, toolCalls } = await generateText({
225
- model: ollama('llama3.2'),
226
- prompt: 'What is the weather in San Francisco?',
227
- tools: {
228
- getWeather: tool({
229
- description: 'Get current weather for a location',
230
- inputSchema: z.object({
231
- location: z.string().describe('City name'),
232
- unit: z.enum(['celsius', 'fahrenheit']).optional(),
233
- }),
234
- execute: async ({ location, unit = 'celsius' }) => {
235
- // Your actual weather API call here
236
- return { temp: 18, unit, condition: 'sunny' };
237
- },
238
- }),
239
- },
240
- });
241
- ```
242
-
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`).
244
-
245
273
  ### Enhanced Tool Calling Wrappers
246
274
 
247
275
  For maximum tool calling reliability, use our enhanced wrapper functions that guarantee complete responses:
248
276
 
249
277
  ```typescript
250
- import { ollama, generateTextOllama, streamTextOllama } from 'ai-sdk-ollama';
278
+ import { ollama, generateText, streamText } from 'ai-sdk-ollama';
251
279
  import { tool } from 'ai';
252
280
  import { z } from 'zod';
253
281
 
254
282
  // Enhanced generateText with automatic response synthesis
255
- const result = await generateTextOllama({
283
+ const result = await generateText({
256
284
  model: ollama('llama3.2'),
257
285
  prompt: 'What is 15 + 27? Use the math tool to calculate it.',
258
286
  tools: {
@@ -285,7 +313,7 @@ console.log(result.text); // "15 + 27 equals 42. Using the math tool, I calculat
285
313
 
286
314
  **Standard vs Enhanced Comparison:**
287
315
 
288
- | Function | Standard `generateText` | Enhanced `generateTextOllama` |
316
+ | Function | Standard `generateText` | Enhanced `generateText` |
289
317
  | -------------------------- | ------------------------- | ------------------------------------ |
290
318
  | **Simple prompts** | ✅ Perfect | ✅ Works (slight overhead) |
291
319
  | **Tool calling** | ⚠️ May return empty text | ✅ **Guarantees complete responses** |
@@ -473,6 +501,7 @@ Works with any model in your Ollama installation:
473
501
  - **Vision**: `llava`, `bakllava`, `llama3.2-vision`, `minicpm-v`
474
502
  - **Embeddings**: `nomic-embed-text`, `all-minilm`, `mxbai-embed-large`
475
503
  - **Reasoning**: `deepseek-r1:7b`, `deepseek-r1:1.5b`, `deepseek-r1:8b`
504
+ - **Cloud Models** (for web search): `qwen3-coder:480b-cloud`, `gpt-oss:120b-cloud`
476
505
 
477
506
  ## Testing
478
507
 
@@ -495,17 +524,19 @@ For detailed testing information, see [Integration Tests Documentation](./src/in
495
524
 
496
525
  ## Learn More
497
526
 
498
- 📚 **[Examples Directory](./examples/)** - Comprehensive usage patterns with real working code
527
+ 📚 **[Examples Directory](../../examples/)** - Comprehensive usage patterns with real working code
528
+
529
+ 🚀 **[Quick Start Guide](../../examples/node/src/basic-chat.ts)** - Get running in 2 minutes
499
530
 
500
- 🚀 **[Quick Start Guide](./examples/basic-chat.ts)** - Get running in 2 minutes
531
+ ⚙️ **[Dual Parameters Demo](../../examples/node/src/dual-parameter-example.ts)** - See the key feature in action
501
532
 
502
- ⚙️ **[Dual Parameters Demo](./examples/dual-parameter-example.ts)** - See the key feature in action
533
+ 🔧 **[Tool Calling Guide](../../examples/node/src/simple-tool-test.ts)** - Function calling with Ollama
503
534
 
504
- 🔧 **[Tool Calling Guide](./examples/tool-calling-example.ts)** - Function calling with Ollama
535
+ 🖼️ **[Image Processing Guide](../../examples/node/src/image-handling-example.ts)** - Vision models with LLaVA
505
536
 
506
- 🖼️ **[Image Processing Guide](./examples/image-handling-example.ts)** - Vision models with LLaVA
537
+ 📡 **[Streaming Examples](../../examples/node/src/streaming-simple-test.ts)** - Real-time responses
507
538
 
508
- 📡 **[Streaming Examples](./examples/streaming-simple-test.ts)** - Real-time responses
539
+ 🌐 **[Web Search Tools](../../examples/node/src/web-search-example.ts)** - Web search and fetch capabilities
509
540
 
510
541
  ## License
511
542