@jerome-benoit/sap-ai-provider 3.0.0-rc.5 → 3.0.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.
Files changed (2) hide show
  1. package/README.md +87 -34
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@mymediset/sap-ai-provider/latest?label=npm&color=blue)](https://www.npmjs.com/package/@mymediset/sap-ai-provider)
4
4
  [![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
6
5
  [![Vercel AI SDK](https://img.shields.io/badge/Vercel%20AI%20SDK-6.0+-black.svg)](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.
@@ -11,6 +10,7 @@ A community provider for SAP AI Core that integrates seamlessly with the Vercel
11
10
 
12
11
  - [Features](#features)
13
12
  - [Quick Start](#quick-start)
13
+ - [Quick Reference](#quick-reference)
14
14
  - [Installation](#installation)
15
15
  - [Authentication](#authentication)
16
16
  - [Basic Usage](#basic-usage)
@@ -45,21 +45,43 @@ npm install @mymediset/sap-ai-provider ai
45
45
  import "dotenv/config"; // Load environment variables
46
46
  import { createSAPAIProvider } from "@mymediset/sap-ai-provider";
47
47
  import { generateText } from "ai";
48
+ import { APICallError } from "@ai-sdk/provider";
48
49
 
49
50
  // Create provider (authentication via AICORE_SERVICE_KEY env var)
50
51
  const provider = createSAPAIProvider();
51
52
 
52
- // Generate text with gpt-4o
53
- const result = await generateText({
54
- model: provider("gpt-4o"),
55
- prompt: "Explain quantum computing in simple terms.",
56
- });
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
+ });
57
59
 
58
- 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
+ }
59
69
  ```
60
70
 
61
- > **Setup:** Create a `.env` file with your `AICORE_SERVICE_KEY`. You can copy from `.env.example`: `cp .env.example .env`
62
- > **Full Setup Guide:** See [ENVIRONMENT_SETUP.md](./ENVIRONMENT_SETUP.md) for detailed authentication configuration.
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) |
63
85
 
64
86
  ## Installation
65
87
 
@@ -86,6 +108,7 @@ You can create an SAP AI provider in two ways:
86
108
  ### Option 1: Factory Function (Recommended for Custom Configuration)
87
109
 
88
110
  ```typescript
111
+ import "dotenv/config"; // Load environment variables
89
112
  import { createSAPAIProvider } from "@mymediset/sap-ai-provider";
90
113
 
91
114
  const provider = createSAPAIProvider({
@@ -97,6 +120,7 @@ const provider = createSAPAIProvider({
97
120
  ### Option 2: Default Instance (Quick Start)
98
121
 
99
122
  ```typescript
123
+ import "dotenv/config"; // Load environment variables
100
124
  import { sapai } from "@mymediset/sap-ai-provider";
101
125
  import { generateText } from "ai";
102
126
 
@@ -129,15 +153,23 @@ Authentication is handled automatically by the SAP AI SDK using the `AICORE_SERV
129
153
  import "dotenv/config"; // Load environment variables
130
154
  import { createSAPAIProvider } from "@mymediset/sap-ai-provider";
131
155
  import { generateText } from "ai";
156
+ import { APICallError } from "@ai-sdk/provider";
132
157
 
133
158
  const provider = createSAPAIProvider();
134
159
 
135
- const result = await generateText({
136
- model: provider("gpt-4o"),
137
- prompt: "Write a short story about a robot learning to paint.",
138
- });
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
+ });
139
165
 
140
- 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
+ }
141
173
  ```
142
174
 
143
175
  ### Chat Conversations
@@ -148,19 +180,27 @@ Note: assistant `reasoning` parts are dropped by default. Set `includeReasoning:
148
180
  import "dotenv/config"; // Load environment variables
149
181
  import { createSAPAIProvider } from "@mymediset/sap-ai-provider";
150
182
  import { generateText } from "ai";
183
+ import { APICallError } from "@ai-sdk/provider";
151
184
 
152
185
  const provider = createSAPAIProvider();
153
186
 
154
- const result = await generateText({
155
- model: provider("anthropic--claude-3.5-sonnet"),
156
- messages: [
157
- { role: "system", content: "You are a helpful coding assistant." },
158
- {
159
- role: "user",
160
- content: "How do I implement binary search in TypeScript?",
161
- },
162
- ],
163
- });
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
+ }
164
204
  ```
165
205
 
166
206
  ### Streaming Responses
@@ -169,16 +209,24 @@ const result = await generateText({
169
209
  import "dotenv/config"; // Load environment variables
170
210
  import { createSAPAIProvider } from "@mymediset/sap-ai-provider";
171
211
  import { streamText } from "ai";
212
+ import { APICallError } from "@ai-sdk/provider";
172
213
 
173
214
  const provider = createSAPAIProvider();
174
215
 
175
- const result = streamText({
176
- model: provider("gpt-4o"),
177
- prompt: "Explain machine learning concepts.",
178
- });
216
+ try {
217
+ const result = streamText({
218
+ model: provider("gpt-4o"),
219
+ prompt: "Explain machine learning concepts.",
220
+ });
179
221
 
180
- for await (const delta of result.textStream) {
181
- process.stdout.write(delta);
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;
182
230
  }
183
231
  ```
184
232
 
@@ -216,11 +264,14 @@ This provider supports all models available through SAP AI Core Orchestration se
216
264
 
217
265
  - **OpenAI**: gpt-4o, gpt-4o-mini, gpt-4.1, o1, o3 (recommended for multi-tool apps)
218
266
  - **Anthropic Claude**: claude-3.5-sonnet, claude-4-opus
219
- - **Google Gemini**: gemini-2.5-pro, gemini-2.0-flash (⚠️ 1 tool limit)
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
+
220
271
  - **Amazon Nova**: nova-pro, nova-lite
221
272
  - **Open Source**: mistralai-mistral-large, llama3.1-70b
222
273
 
223
- **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.
224
275
 
225
276
  **To discover available models in your environment:**
226
277
 
@@ -238,6 +289,8 @@ The following helper functions are exported by this package for convenient confi
238
289
 
239
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.
240
291
 
292
+ 📖 **Complete guide:** [API Reference - Tool Calling](./API_REFERENCE.md#tool-calling-function-calling)
293
+
241
294
  ```typescript
242
295
  import "dotenv/config"; // Load environment variables
243
296
  import { createSAPAIProvider } from "@mymediset/sap-ai-provider";
@@ -269,7 +322,7 @@ const result = await generateText({
269
322
  console.log(result.text);
270
323
  ```
271
324
 
272
- > Known limitations: Gemini models currently support only one function tool per request. For multiple tools, use OpenAI models (e.g., `gpt-4o`) or consolidate tools.
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.
273
326
 
274
327
  ### Multi-modal Input (Images)
275
328
 
@@ -439,7 +492,7 @@ The `examples/` directory contains complete, runnable examples demonstrating key
439
492
  npx tsx examples/example-generate-text.ts
440
493
  ```
441
494
 
442
- **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.
443
496
 
444
497
  ## Migration Guides
445
498
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jerome-benoit/sap-ai-provider",
3
- "version": "3.0.0-rc.5",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
5
  "description": "SAP AI Core provider for AI SDK (powered by @sap-ai-sdk/orchestration)",
6
6
  "keywords": [