ai-sdk-ollama 0.1.0 → 0.2.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 +13 -0
- package/README.md +13 -15
- package/dist/compatibility.test.d.ts +2 -0
- package/dist/compatibility.test.d.ts.map +1 -0
- package/dist/compatibility.test.js +123 -0
- package/dist/index.cjs +94 -512
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -86
- package/dist/index.d.ts +36 -86
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -491
- package/dist/index.js.map +1 -1
- package/dist/integration.test.d.ts +2 -0
- package/dist/integration.test.d.ts.map +1 -0
- package/dist/integration.test.js +221 -0
- package/dist/internal/index.cjs +135 -0
- package/dist/internal/index.cjs.map +1 -0
- package/dist/internal/index.d.cts +18 -0
- package/dist/internal/index.d.ts +18 -0
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +107 -0
- package/dist/internal/index.js.map +1 -0
- package/dist/models/chat-language-model.d.ts +49 -0
- package/dist/models/chat-language-model.d.ts.map +1 -0
- package/dist/models/chat-language-model.js +278 -0
- package/dist/models/chat-language-model.test.d.ts +2 -0
- package/dist/models/chat-language-model.test.d.ts.map +1 -0
- package/dist/models/chat-language-model.test.js +486 -0
- package/dist/models/embedding-model.d.ts +24 -0
- package/dist/models/embedding-model.d.ts.map +1 -0
- package/dist/models/embedding-model.js +77 -0
- package/dist/models/embedding-model.test.d.ts +2 -0
- package/dist/models/embedding-model.test.d.ts.map +1 -0
- package/dist/models/embedding-model.test.js +281 -0
- package/dist/provider-dual-parameters.test.d.ts +2 -0
- package/dist/provider-dual-parameters.test.d.ts.map +1 -0
- package/dist/provider-dual-parameters.test.js +223 -0
- package/dist/provider.d.ts +123 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +52 -0
- package/dist/provider.test.d.ts +2 -0
- package/dist/provider.test.d.ts.map +1 -0
- package/dist/provider.test.js +192 -0
- package/dist/test-setup.d.ts +4 -0
- package/dist/test-setup.d.ts.map +1 -0
- package/dist/test-setup.js +31 -0
- package/dist/utils/convert-to-ollama-messages.d.ts +4 -0
- package/dist/utils/convert-to-ollama-messages.d.ts.map +1 -0
- package/dist/utils/convert-to-ollama-messages.js +105 -0
- package/dist/utils/convert-to-ollama-messages.test.d.ts +2 -0
- package/dist/utils/convert-to-ollama-messages.test.d.ts.map +1 -0
- package/dist/utils/convert-to-ollama-messages.test.js +433 -0
- package/dist/utils/map-ollama-finish-reason.d.ts +3 -0
- package/dist/utils/map-ollama-finish-reason.d.ts.map +1 -0
- package/dist/utils/map-ollama-finish-reason.js +15 -0
- package/dist/utils/map-ollama-finish-reason.test.d.ts +2 -0
- package/dist/utils/map-ollama-finish-reason.test.d.ts.map +1 -0
- package/dist/utils/map-ollama-finish-reason.test.js +47 -0
- package/dist/utils/model-capabilities.d.ts +28 -0
- package/dist/utils/model-capabilities.d.ts.map +1 -0
- package/dist/utils/model-capabilities.js +327 -0
- package/dist/utils/model-suggestions.d.ts +38 -0
- package/dist/utils/model-suggestions.d.ts.map +1 -0
- package/dist/utils/model-suggestions.js +158 -0
- package/dist/utils/normalize-tool-parameters.d.ts +17 -0
- package/dist/utils/normalize-tool-parameters.d.ts.map +1 -0
- package/dist/utils/normalize-tool-parameters.js +63 -0
- package/dist/utils/normalize-tool-parameters.test.d.ts +2 -0
- package/dist/utils/normalize-tool-parameters.test.d.ts.map +1 -0
- package/dist/utils/normalize-tool-parameters.test.js +100 -0
- package/dist/utils/ollama-error.d.ts +16 -0
- package/dist/utils/ollama-error.d.ts.map +1 -0
- package/dist/utils/ollama-error.js +13 -0
- package/dist/utils/ollama-error.test.d.ts +2 -0
- package/dist/utils/ollama-error.test.d.ts.map +1 -0
- package/dist/utils/ollama-error.test.js +94 -0
- package/dist/utils/validate-model.d.ts +32 -0
- package/dist/utils/validate-model.d.ts.map +1 -0
- package/dist/utils/validate-model.js +32 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- bf0905a: Fix streaming examples and improve TypeScript type checking
|
|
8
|
+
- Fix "Stream error: text part not found" by using textStream instead of fullStream for basic streaming
|
|
9
|
+
- Fix TypeScript errors in all examples (error handling, index access, undefined checks)
|
|
10
|
+
- Remove rootDir restriction in tsconfig.json to enable type checking for examples
|
|
11
|
+
- Fix tool call parameter handling and error messages
|
|
12
|
+
- Remove deprecated model capabilities and suggestions utilities
|
|
13
|
+
- Improve error handling with proper type checking throughout examples
|
|
14
|
+
- Update streaming examples to work with AI SDK v5 API changes
|
|
15
|
+
|
|
3
16
|
All notable changes to this project will be documented in this file.
|
|
4
17
|
|
|
5
18
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
package/README.md
CHANGED
|
@@ -151,7 +151,7 @@ const { text } = await generateText({
|
|
|
151
151
|
|
|
152
152
|
### Tool Calling Support
|
|
153
153
|
|
|
154
|
-
Ollama supports tool calling with compatible models
|
|
154
|
+
Ollama supports tool calling with compatible models.
|
|
155
155
|
|
|
156
156
|
```typescript
|
|
157
157
|
import { z } from 'zod';
|
|
@@ -162,7 +162,7 @@ const { text, toolCalls } = await generateText({
|
|
|
162
162
|
tools: {
|
|
163
163
|
getWeather: {
|
|
164
164
|
description: 'Get current weather for a location',
|
|
165
|
-
|
|
165
|
+
inputSchema: z.object({
|
|
166
166
|
location: z.string().describe('City name'),
|
|
167
167
|
unit: z.enum(['celsius', 'fahrenheit']).optional(),
|
|
168
168
|
}),
|
|
@@ -175,28 +175,26 @@ const { text, toolCalls } = await generateText({
|
|
|
175
175
|
});
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
> **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`).
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
### Simple and Predictable
|
|
181
|
+
|
|
182
|
+
The provider works the same way with any model - just try the features you need:
|
|
181
183
|
|
|
182
184
|
```typescript
|
|
183
|
-
//
|
|
185
|
+
// No capability checking required - just use any model
|
|
184
186
|
const { text } = await generateText({
|
|
185
|
-
model: ollama('
|
|
187
|
+
model: ollama('any-model'),
|
|
186
188
|
prompt: 'What is the weather?',
|
|
187
189
|
tools: {
|
|
188
190
|
/* ... */
|
|
189
|
-
}, //
|
|
191
|
+
}, // If the model doesn't support tools, you'll get a clear error
|
|
190
192
|
});
|
|
191
193
|
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
toolCalling: true,
|
|
197
|
-
performance: 'fast',
|
|
198
|
-
});
|
|
199
|
-
// Returns: [{ modelId: 'llama3.2', reason: 'Excellent tool calling...' }]
|
|
194
|
+
// The provider is simple and predictable
|
|
195
|
+
// - Try any feature with any model
|
|
196
|
+
// - Get clear error messages if something doesn't work
|
|
197
|
+
// - No hidden complexity or capability detection
|
|
200
198
|
```
|
|
201
199
|
|
|
202
200
|
## Advanced Features
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compatibility.test.d.ts","sourceRoot":"","sources":["../src/compatibility.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { ollama } from './index';
|
|
3
|
+
describe('OpenAI API Compatibility', () => {
|
|
4
|
+
describe('Provider Interface Compatibility', () => {
|
|
5
|
+
it('should implement standard provider pattern like OpenAI provider', () => {
|
|
6
|
+
// Test that our provider follows the same pattern as Vercel's OpenAI provider
|
|
7
|
+
expect(typeof ollama).toBe('function');
|
|
8
|
+
expect(typeof ollama.chat).toBe('function');
|
|
9
|
+
expect(typeof ollama.languageModel).toBe('function');
|
|
10
|
+
expect(typeof ollama.embedding).toBe('function');
|
|
11
|
+
expect(typeof ollama.textEmbedding).toBe('function');
|
|
12
|
+
expect(typeof ollama.textEmbeddingModel).toBe('function');
|
|
13
|
+
});
|
|
14
|
+
it('should create LanguageModelV2 compatible models', () => {
|
|
15
|
+
const model = ollama('llama3.2');
|
|
16
|
+
// Test LanguageModelV2 interface compliance
|
|
17
|
+
expect(model.specificationVersion).toBe('v2');
|
|
18
|
+
expect(typeof model.modelId).toBe('string');
|
|
19
|
+
expect(typeof model.provider).toBe('string');
|
|
20
|
+
expect(typeof model.doGenerate).toBe('function');
|
|
21
|
+
expect(typeof model.doStream).toBe('function');
|
|
22
|
+
// Test that model has expected properties (interface may have changed)
|
|
23
|
+
expect(typeof model.supportedUrls).toBe('object');
|
|
24
|
+
});
|
|
25
|
+
it('should create EmbeddingModelV2 compatible models', () => {
|
|
26
|
+
const model = ollama.embedding('nomic-embed-text');
|
|
27
|
+
// Test EmbeddingModelV2 interface compliance
|
|
28
|
+
expect(model.specificationVersion).toBe('v2');
|
|
29
|
+
expect(typeof model.modelId).toBe('string');
|
|
30
|
+
expect(typeof model.provider).toBe('string');
|
|
31
|
+
expect(typeof model.doEmbed).toBe('function');
|
|
32
|
+
// Test standard properties
|
|
33
|
+
expect(typeof model.maxEmbeddingsPerCall).toBe('number');
|
|
34
|
+
expect(typeof model.supportsParallelCalls).toBe('boolean');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('AI SDK Integration Compatibility', () => {
|
|
38
|
+
it('should work with generateText like OpenAI provider', () => {
|
|
39
|
+
const model = ollama('llama3.2');
|
|
40
|
+
// Test that model can be used with AI SDK functions
|
|
41
|
+
expect(typeof model.doGenerate).toBe('function');
|
|
42
|
+
expect(model.doGenerate.length).toBe(1); // Takes one parameter (options)
|
|
43
|
+
});
|
|
44
|
+
it('should work with streamText like OpenAI provider', () => {
|
|
45
|
+
const model = ollama('llama3.2');
|
|
46
|
+
expect(typeof model.doStream).toBe('function');
|
|
47
|
+
expect(model.doStream.length).toBe(1); // Takes one parameter (options)
|
|
48
|
+
});
|
|
49
|
+
it('should work with embed like OpenAI provider', () => {
|
|
50
|
+
const model = ollama.embedding('nomic-embed-text');
|
|
51
|
+
expect(() => {
|
|
52
|
+
// Test embedding interface compatibility
|
|
53
|
+
expect(typeof model.doEmbed).toBe('function');
|
|
54
|
+
expect(model.doEmbed.length).toBe(1); // Takes one parameter (options)
|
|
55
|
+
}).not.toThrow();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe('Response Format Compatibility', () => {
|
|
59
|
+
it('should support JSON response format like OpenAI', () => {
|
|
60
|
+
const model = ollama('llama3.2');
|
|
61
|
+
// Test that our model exists and can be configured
|
|
62
|
+
expect(model.provider).toBe('ollama');
|
|
63
|
+
expect(model.modelId).toBe('llama3.2');
|
|
64
|
+
});
|
|
65
|
+
it('should support standard parameters like OpenAI', () => {
|
|
66
|
+
const model = ollama('llama3.2');
|
|
67
|
+
// Test basic model properties
|
|
68
|
+
expect(typeof model.doGenerate).toBe('function');
|
|
69
|
+
expect(typeof model.doStream).toBe('function');
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
describe('Error Handling Compatibility', () => {
|
|
73
|
+
it('should handle errors consistently with OpenAI provider', () => {
|
|
74
|
+
const model = ollama('llama3.2');
|
|
75
|
+
// Test that our error handling follows standard patterns
|
|
76
|
+
expect(model.provider).toBe('ollama');
|
|
77
|
+
expect(model.modelId).toBe('llama3.2');
|
|
78
|
+
// Models should have consistent error behavior
|
|
79
|
+
expect(() => {
|
|
80
|
+
// Test model creation with invalid parameters
|
|
81
|
+
ollama(''); // Empty model name
|
|
82
|
+
}).not.toThrow(); // Should create model, errors happen at runtime
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe('Provider Settings Compatibility', () => {
|
|
86
|
+
it('should support provider-specific settings like OpenAI', () => {
|
|
87
|
+
// Test custom settings similar to how OpenAI provider works
|
|
88
|
+
const modelWithSettings = ollama('llama3.2', {
|
|
89
|
+
options: {
|
|
90
|
+
temperature: 0.8,
|
|
91
|
+
num_ctx: 4096,
|
|
92
|
+
top_k: 50,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
expect(modelWithSettings.modelId).toBe('llama3.2');
|
|
96
|
+
expect(modelWithSettings.provider).toBe('ollama');
|
|
97
|
+
});
|
|
98
|
+
it('should support structured outputs setting', () => {
|
|
99
|
+
const modelWithStructuredOutputs = ollama('llama3.2', {
|
|
100
|
+
structuredOutputs: true,
|
|
101
|
+
});
|
|
102
|
+
expect(modelWithStructuredOutputs.provider).toBe('ollama');
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe('Embedding Model Compatibility', () => {
|
|
106
|
+
it('should handle embeddings consistently with OpenAI', () => {
|
|
107
|
+
const embeddingModel = ollama.embedding('nomic-embed-text');
|
|
108
|
+
expect(embeddingModel.modelId).toBe('nomic-embed-text');
|
|
109
|
+
expect(embeddingModel.provider).toBe('ollama');
|
|
110
|
+
expect(embeddingModel.specificationVersion).toBe('v2');
|
|
111
|
+
expect(typeof embeddingModel.maxEmbeddingsPerCall).toBe('number');
|
|
112
|
+
expect(embeddingModel.maxEmbeddingsPerCall).toBeGreaterThan(0);
|
|
113
|
+
});
|
|
114
|
+
it('should support embedding settings', () => {
|
|
115
|
+
const embeddingModel = ollama.embedding('nomic-embed-text', {
|
|
116
|
+
options: {
|
|
117
|
+
num_thread: 8,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
expect(embeddingModel.provider).toBe('ollama');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|