@jerome-benoit/sap-ai-provider 3.0.0-rc.4 → 3.0.0-rc.6
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/README.md +113 -58
- package/dist/index.cjs +11 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,37 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@mymediset/sap-ai-provider)
|
|
4
4
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
5
|
-
[](https://www.typescriptlang.org/)
|
|
6
5
|
[](https://sdk.vercel.ai/docs)
|
|
7
6
|
|
|
8
7
|
A community provider for SAP AI Core that integrates seamlessly with the Vercel AI SDK. Built on top of the official **@sap-ai-sdk/orchestration** package, this provider enables you to use SAP's enterprise-grade AI models through the familiar Vercel AI SDK interface.
|
|
9
8
|
|
|
10
|
-
> **Note on Terminology:** This documentation uses "tool calling" (Vercel AI SDK convention), equivalent to "function calling" in OpenAI documentation. Both terms refer to the same capability of models invoking external functions.
|
|
11
|
-
|
|
12
|
-
## ⚠️ Breaking Changes in v3.0.0-rc.1
|
|
13
|
-
|
|
14
|
-
Version 3.0 standardizes error handling to use Vercel AI SDK native error types. **See the [Migration Guide](./MIGRATION_GUIDE.md#v2x--v30) for complete upgrade instructions.**
|
|
15
|
-
|
|
16
|
-
**Key changes:**
|
|
17
|
-
|
|
18
|
-
- `SAPAIError` removed → Use `APICallError` from `@ai-sdk/provider`
|
|
19
|
-
- Error properties: `error.code` → `error.statusCode`
|
|
20
|
-
- Automatic retries for rate limits (429) and server errors (5xx)
|
|
21
|
-
|
|
22
|
-
## ⚠️ Breaking Changes in v2.0
|
|
23
|
-
|
|
24
|
-
Version 2.0 uses the official SAP AI SDK. **See the [Migration Guide](./MIGRATION_GUIDE.md#v1x--v20) for complete upgrade instructions.**
|
|
25
|
-
|
|
26
|
-
**Key changes:**
|
|
27
|
-
|
|
28
|
-
- Authentication via `AICORE_SERVICE_KEY` environment variable
|
|
29
|
-
- Synchronous provider creation: `createSAPAIProvider()` (no await)
|
|
30
|
-
- Helper functions from SAP AI SDK
|
|
31
|
-
|
|
32
9
|
## Table of Contents
|
|
33
10
|
|
|
34
11
|
- [Features](#features)
|
|
35
12
|
- [Quick Start](#quick-start)
|
|
13
|
+
- [Quick Reference](#quick-reference)
|
|
36
14
|
- [Installation](#installation)
|
|
37
15
|
- [Authentication](#authentication)
|
|
38
16
|
- [Basic Usage](#basic-usage)
|
|
@@ -41,7 +19,7 @@ Version 2.0 uses the official SAP AI SDK. **See the [Migration Guide](./MIGRATIO
|
|
|
41
19
|
- [Configuration Options](#configuration-options)
|
|
42
20
|
- [Error Handling](#error-handling)
|
|
43
21
|
- [Examples](#examples)
|
|
44
|
-
- [Migration Guides
|
|
22
|
+
- [Migration Guides](#migration-guides)
|
|
45
23
|
- [Contributing](#contributing)
|
|
46
24
|
- [License](#license)
|
|
47
25
|
|
|
@@ -67,21 +45,43 @@ npm install @mymediset/sap-ai-provider ai
|
|
|
67
45
|
import "dotenv/config"; // Load environment variables
|
|
68
46
|
import { createSAPAIProvider } from "@mymediset/sap-ai-provider";
|
|
69
47
|
import { generateText } from "ai";
|
|
48
|
+
import { APICallError } from "@ai-sdk/provider";
|
|
70
49
|
|
|
71
50
|
// Create provider (authentication via AICORE_SERVICE_KEY env var)
|
|
72
51
|
const provider = createSAPAIProvider();
|
|
73
52
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
53
|
+
try {
|
|
54
|
+
// Generate text with gpt-4o
|
|
55
|
+
const result = await generateText({
|
|
56
|
+
model: provider("gpt-4o"),
|
|
57
|
+
prompt: "Explain quantum computing in simple terms.",
|
|
58
|
+
});
|
|
79
59
|
|
|
80
|
-
console.log(result.text);
|
|
60
|
+
console.log(result.text);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (error instanceof APICallError) {
|
|
63
|
+
console.error("SAP AI Core API error:", error.message);
|
|
64
|
+
console.error("Status:", error.statusCode);
|
|
65
|
+
} else {
|
|
66
|
+
console.error("Unexpected error:", error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
81
69
|
```
|
|
82
70
|
|
|
83
|
-
> **
|
|
84
|
-
|
|
71
|
+
> **Note:** Requires `AICORE_SERVICE_KEY` environment variable. See [Environment Setup](./ENVIRONMENT_SETUP.md) for configuration.
|
|
72
|
+
|
|
73
|
+
## Quick Reference
|
|
74
|
+
|
|
75
|
+
| Task | Code Pattern | Documentation |
|
|
76
|
+
| ------------------- | ----------------------------------------------------- | ------------------------------------------------------------- |
|
|
77
|
+
| **Install** | `npm install @mymediset/sap-ai-provider ai` | [Installation](#installation) |
|
|
78
|
+
| **Auth Setup** | Add `AICORE_SERVICE_KEY` to `.env` | [Environment Setup](./ENVIRONMENT_SETUP.md) |
|
|
79
|
+
| **Create Provider** | `createSAPAIProvider()` or use `sapai` | [Provider Creation](#provider-creation) |
|
|
80
|
+
| **Text Generation** | `generateText({ model: provider("gpt-4o"), prompt })` | [Basic Usage](#text-generation) |
|
|
81
|
+
| **Streaming** | `streamText({ model: provider("gpt-4o"), prompt })` | [Streaming](#streaming-responses) |
|
|
82
|
+
| **Tool Calling** | `generateText({ tools: { myTool: tool({...}) } })` | [Tool Calling](#tool-calling) |
|
|
83
|
+
| **Error Handling** | `catch (error instanceof APICallError)` | [API Reference](./API_REFERENCE.md#error-handling--reference) |
|
|
84
|
+
| **Choose Model** | See 80+ models (GPT, Claude, Gemini, Llama) | [Models](./API_REFERENCE.md#models) |
|
|
85
85
|
|
|
86
86
|
## Installation
|
|
87
87
|
|
|
@@ -108,6 +108,7 @@ You can create an SAP AI provider in two ways:
|
|
|
108
108
|
### Option 1: Factory Function (Recommended for Custom Configuration)
|
|
109
109
|
|
|
110
110
|
```typescript
|
|
111
|
+
import "dotenv/config"; // Load environment variables
|
|
111
112
|
import { createSAPAIProvider } from "@mymediset/sap-ai-provider";
|
|
112
113
|
|
|
113
114
|
const provider = createSAPAIProvider({
|
|
@@ -119,6 +120,7 @@ const provider = createSAPAIProvider({
|
|
|
119
120
|
### Option 2: Default Instance (Quick Start)
|
|
120
121
|
|
|
121
122
|
```typescript
|
|
123
|
+
import "dotenv/config"; // Load environment variables
|
|
122
124
|
import { sapai } from "@mymediset/sap-ai-provider";
|
|
123
125
|
import { generateText } from "ai";
|
|
124
126
|
|
|
@@ -151,15 +153,23 @@ Authentication is handled automatically by the SAP AI SDK using the `AICORE_SERV
|
|
|
151
153
|
import "dotenv/config"; // Load environment variables
|
|
152
154
|
import { createSAPAIProvider } from "@mymediset/sap-ai-provider";
|
|
153
155
|
import { generateText } from "ai";
|
|
156
|
+
import { APICallError } from "@ai-sdk/provider";
|
|
154
157
|
|
|
155
158
|
const provider = createSAPAIProvider();
|
|
156
159
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
try {
|
|
161
|
+
const result = await generateText({
|
|
162
|
+
model: provider("gpt-4o"),
|
|
163
|
+
prompt: "Write a short story about a robot learning to paint.",
|
|
164
|
+
});
|
|
161
165
|
|
|
162
|
-
console.log(result.text);
|
|
166
|
+
console.log(result.text);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
if (error instanceof APICallError) {
|
|
169
|
+
console.error("API error:", error.message, "- Status:", error.statusCode);
|
|
170
|
+
}
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
163
173
|
```
|
|
164
174
|
|
|
165
175
|
### Chat Conversations
|
|
@@ -170,19 +180,27 @@ Note: assistant `reasoning` parts are dropped by default. Set `includeReasoning:
|
|
|
170
180
|
import "dotenv/config"; // Load environment variables
|
|
171
181
|
import { createSAPAIProvider } from "@mymediset/sap-ai-provider";
|
|
172
182
|
import { generateText } from "ai";
|
|
183
|
+
import { APICallError } from "@ai-sdk/provider";
|
|
173
184
|
|
|
174
185
|
const provider = createSAPAIProvider();
|
|
175
186
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
187
|
+
try {
|
|
188
|
+
const result = await generateText({
|
|
189
|
+
model: provider("anthropic--claude-3.5-sonnet"),
|
|
190
|
+
messages: [
|
|
191
|
+
{ role: "system", content: "You are a helpful coding assistant." },
|
|
192
|
+
{
|
|
193
|
+
role: "user",
|
|
194
|
+
content: "How do I implement binary search in TypeScript?",
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
});
|
|
198
|
+
} catch (error) {
|
|
199
|
+
if (error instanceof APICallError) {
|
|
200
|
+
console.error("API error:", error.message, "- Status:", error.statusCode);
|
|
201
|
+
}
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
186
204
|
```
|
|
187
205
|
|
|
188
206
|
### Streaming Responses
|
|
@@ -191,16 +209,24 @@ const result = await generateText({
|
|
|
191
209
|
import "dotenv/config"; // Load environment variables
|
|
192
210
|
import { createSAPAIProvider } from "@mymediset/sap-ai-provider";
|
|
193
211
|
import { streamText } from "ai";
|
|
212
|
+
import { APICallError } from "@ai-sdk/provider";
|
|
194
213
|
|
|
195
214
|
const provider = createSAPAIProvider();
|
|
196
215
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
216
|
+
try {
|
|
217
|
+
const result = streamText({
|
|
218
|
+
model: provider("gpt-4o"),
|
|
219
|
+
prompt: "Explain machine learning concepts.",
|
|
220
|
+
});
|
|
201
221
|
|
|
202
|
-
for await (const delta of result.textStream) {
|
|
203
|
-
|
|
222
|
+
for await (const delta of result.textStream) {
|
|
223
|
+
process.stdout.write(delta);
|
|
224
|
+
}
|
|
225
|
+
} catch (error) {
|
|
226
|
+
if (error instanceof APICallError) {
|
|
227
|
+
console.error("API error:", error.message, "- Status:", error.statusCode);
|
|
228
|
+
}
|
|
229
|
+
throw error;
|
|
204
230
|
}
|
|
205
231
|
```
|
|
206
232
|
|
|
@@ -238,11 +264,14 @@ This provider supports all models available through SAP AI Core Orchestration se
|
|
|
238
264
|
|
|
239
265
|
- **OpenAI**: gpt-4o, gpt-4o-mini, gpt-4.1, o1, o3 (recommended for multi-tool apps)
|
|
240
266
|
- **Anthropic Claude**: claude-3.5-sonnet, claude-4-opus
|
|
241
|
-
- **Google Gemini**: gemini-2.5-pro, gemini-2.0-flash
|
|
267
|
+
- **Google Gemini**: gemini-2.5-pro, gemini-2.0-flash
|
|
268
|
+
|
|
269
|
+
⚠️ **Important:** Google Gemini models have a 1 tool limit per request.
|
|
270
|
+
|
|
242
271
|
- **Amazon Nova**: nova-pro, nova-lite
|
|
243
272
|
- **Open Source**: mistralai-mistral-large, llama3.1-70b
|
|
244
273
|
|
|
245
|
-
**Note:** Model availability depends on your SAP AI Core tenant configuration, region, and subscription.
|
|
274
|
+
> **Note:** Model availability depends on your SAP AI Core tenant configuration, region, and subscription.
|
|
246
275
|
|
|
247
276
|
**To discover available models in your environment:**
|
|
248
277
|
|
|
@@ -258,6 +287,10 @@ The following helper functions are exported by this package for convenient confi
|
|
|
258
287
|
|
|
259
288
|
### Tool Calling
|
|
260
289
|
|
|
290
|
+
> **Note on Terminology:** This documentation uses "tool calling" (Vercel AI SDK convention), equivalent to "function calling" in OpenAI documentation. Both terms refer to the same capability of models invoking external functions.
|
|
291
|
+
|
|
292
|
+
📖 **Complete guide:** [API Reference - Tool Calling](./API_REFERENCE.md#tool-calling-function-calling)
|
|
293
|
+
|
|
261
294
|
```typescript
|
|
262
295
|
import "dotenv/config"; // Load environment variables
|
|
263
296
|
import { createSAPAIProvider } from "@mymediset/sap-ai-provider";
|
|
@@ -289,7 +322,7 @@ const result = await generateText({
|
|
|
289
322
|
console.log(result.text);
|
|
290
323
|
```
|
|
291
324
|
|
|
292
|
-
|
|
325
|
+
⚠️ **Important:** Gemini models support only 1 tool per request. For multi-tool applications, use GPT-4o, Claude, or Amazon Nova models. See [API Reference - Tool Calling](./API_REFERENCE.md#tool-calling-function-calling) for complete model comparison.
|
|
293
326
|
|
|
294
327
|
### Multi-modal Input (Images)
|
|
295
328
|
|
|
@@ -459,9 +492,31 @@ The `examples/` directory contains complete, runnable examples demonstrating key
|
|
|
459
492
|
npx tsx examples/example-generate-text.ts
|
|
460
493
|
```
|
|
461
494
|
|
|
462
|
-
**Note:** Examples require `AICORE_SERVICE_KEY` environment variable. See [Environment Setup](./ENVIRONMENT_SETUP.md) for configuration.
|
|
495
|
+
> **Note:** Examples require `AICORE_SERVICE_KEY` environment variable. See [Environment Setup](./ENVIRONMENT_SETUP.md) for configuration.
|
|
496
|
+
|
|
497
|
+
## Migration Guides
|
|
498
|
+
|
|
499
|
+
### Upgrading from v2.x to v3.x
|
|
500
|
+
|
|
501
|
+
Version 3.0 standardizes error handling to use Vercel AI SDK native error types. **See the [Migration Guide](./MIGRATION_GUIDE.md#v2x--v30) for complete upgrade instructions.**
|
|
502
|
+
|
|
503
|
+
**Key changes:**
|
|
504
|
+
|
|
505
|
+
- `SAPAIError` removed → Use `APICallError` from `@ai-sdk/provider`
|
|
506
|
+
- Error properties: `error.code` → `error.statusCode`
|
|
507
|
+
- Automatic retries for rate limits (429) and server errors (5xx)
|
|
508
|
+
|
|
509
|
+
### Upgrading from v1.x to v2.x
|
|
510
|
+
|
|
511
|
+
Version 2.0 uses the official SAP AI SDK. **See the [Migration Guide](./MIGRATION_GUIDE.md#v1x--v20) for complete upgrade instructions.**
|
|
512
|
+
|
|
513
|
+
**Key changes:**
|
|
514
|
+
|
|
515
|
+
- Authentication via `AICORE_SERVICE_KEY` environment variable
|
|
516
|
+
- Synchronous provider creation: `createSAPAIProvider()` (no await)
|
|
517
|
+
- Helper functions from SAP AI SDK
|
|
463
518
|
|
|
464
|
-
**
|
|
519
|
+
**For detailed migration instructions with code examples, see the [complete Migration Guide](./MIGRATION_GUIDE.md).**
|
|
465
520
|
|
|
466
521
|
## Important Note
|
|
467
522
|
|
package/dist/index.cjs
CHANGED
|
@@ -29737,16 +29737,17 @@ var require_dist = __commonJS({
|
|
|
29737
29737
|
// src/index.ts
|
|
29738
29738
|
var index_exports = {};
|
|
29739
29739
|
__export(index_exports, {
|
|
29740
|
-
OrchestrationClient: () =>
|
|
29741
|
-
OrchestrationResponse: () =>
|
|
29742
|
-
OrchestrationStreamChunkResponse: () =>
|
|
29743
|
-
OrchestrationStreamResponse: () =>
|
|
29740
|
+
OrchestrationClient: () => import_orchestration5.OrchestrationClient,
|
|
29741
|
+
OrchestrationResponse: () => import_orchestration4.OrchestrationResponse,
|
|
29742
|
+
OrchestrationStreamChunkResponse: () => import_orchestration4.OrchestrationStreamChunkResponse,
|
|
29743
|
+
OrchestrationStreamResponse: () => import_orchestration4.OrchestrationStreamResponse,
|
|
29744
29744
|
buildAzureContentSafetyFilter: () => import_orchestration2.buildAzureContentSafetyFilter,
|
|
29745
29745
|
buildDocumentGroundingConfig: () => import_orchestration2.buildDocumentGroundingConfig,
|
|
29746
29746
|
buildDpiMaskingProvider: () => import_orchestration2.buildDpiMaskingProvider,
|
|
29747
29747
|
buildLlamaGuard38BFilter: () => import_orchestration2.buildLlamaGuard38BFilter,
|
|
29748
29748
|
buildTranslationConfig: () => import_orchestration2.buildTranslationConfig,
|
|
29749
29749
|
createSAPAIProvider: () => createSAPAIProvider,
|
|
29750
|
+
isConfigReference: () => import_orchestration3.isConfigReference,
|
|
29750
29751
|
sapai: () => sapai
|
|
29751
29752
|
});
|
|
29752
29753
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -30909,11 +30910,14 @@ var sapai = createSAPAIProvider();
|
|
|
30909
30910
|
// src/sap-ai-chat-settings.ts
|
|
30910
30911
|
var import_orchestration2 = require("@sap-ai-sdk/orchestration");
|
|
30911
30912
|
|
|
30912
|
-
// src/types/completion-
|
|
30913
|
+
// src/types/completion-request.ts
|
|
30913
30914
|
var import_orchestration3 = require("@sap-ai-sdk/orchestration");
|
|
30914
30915
|
|
|
30915
|
-
// src/
|
|
30916
|
+
// src/types/completion-response.ts
|
|
30916
30917
|
var import_orchestration4 = require("@sap-ai-sdk/orchestration");
|
|
30918
|
+
|
|
30919
|
+
// src/index.ts
|
|
30920
|
+
var import_orchestration5 = require("@sap-ai-sdk/orchestration");
|
|
30917
30921
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30918
30922
|
0 && (module.exports = {
|
|
30919
30923
|
OrchestrationClient,
|
|
@@ -30926,6 +30930,7 @@ var import_orchestration4 = require("@sap-ai-sdk/orchestration");
|
|
|
30926
30930
|
buildLlamaGuard38BFilter,
|
|
30927
30931
|
buildTranslationConfig,
|
|
30928
30932
|
createSAPAIProvider,
|
|
30933
|
+
isConfigReference,
|
|
30929
30934
|
sapai
|
|
30930
30935
|
});
|
|
30931
30936
|
/*! Bundled license information:
|