@jerome-benoit/sap-ai-provider 4.0.0-rc.2 → 4.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.
- package/README.md +11 -12
- package/dist/index.cjs +19 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +20 -28
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -347,10 +347,7 @@ const dpiConfig = buildDpiMaskingProvider({
|
|
|
347
347
|
|
|
348
348
|
```typescript
|
|
349
349
|
import "dotenv/config"; // Load environment variables
|
|
350
|
-
import {
|
|
351
|
-
createSAPAIProvider,
|
|
352
|
-
buildAzureContentSafetyFilter,
|
|
353
|
-
} from "@mymediset/sap-ai-provider";
|
|
350
|
+
import { createSAPAIProvider, buildAzureContentSafetyFilter } from "@mymediset/sap-ai-provider";
|
|
354
351
|
|
|
355
352
|
const provider = createSAPAIProvider({
|
|
356
353
|
defaultSettings: {
|
|
@@ -521,14 +518,16 @@ Error code reference table: [API Reference - HTTP Status Codes](./API_REFERENCE.
|
|
|
521
518
|
|
|
522
519
|
The `examples/` directory contains complete, runnable examples demonstrating key features:
|
|
523
520
|
|
|
524
|
-
| Example | Description | Key Features
|
|
525
|
-
| ----------------------------------- | --------------------------- |
|
|
526
|
-
| `example-generate-text.ts` | Basic text generation | Simple prompts, synchronous generation
|
|
527
|
-
| `example-simple-chat-completion.ts` | Simple chat conversation | System messages, user prompts
|
|
528
|
-
| `example-chat-completion-tool.ts` | Tool calling with functions | Weather API tool, function execution
|
|
529
|
-
| `example-streaming-chat.ts` | Streaming responses | Real-time text generation, SSE
|
|
530
|
-
| `example-image-recognition.ts` | Multi-modal with images | Vision models, image analysis
|
|
531
|
-
| `example-data-masking.ts` | Data privacy integration | DPI masking, anonymization
|
|
521
|
+
| Example | Description | Key Features |
|
|
522
|
+
| ----------------------------------- | --------------------------- | --------------------------------------- |
|
|
523
|
+
| `example-generate-text.ts` | Basic text generation | Simple prompts, synchronous generation |
|
|
524
|
+
| `example-simple-chat-completion.ts` | Simple chat conversation | System messages, user prompts |
|
|
525
|
+
| `example-chat-completion-tool.ts` | Tool calling with functions | Weather API tool, function execution |
|
|
526
|
+
| `example-streaming-chat.ts` | Streaming responses | Real-time text generation, SSE |
|
|
527
|
+
| `example-image-recognition.ts` | Multi-modal with images | Vision models, image analysis |
|
|
528
|
+
| `example-data-masking.ts` | Data privacy integration | DPI masking, anonymization |
|
|
529
|
+
| `example-document-grounding.ts` | Document grounding (RAG) | Vector store, retrieval-augmented gen |
|
|
530
|
+
| `example-translation.ts` | Input/output translation | Multi-language support, SAP translation |
|
|
532
531
|
|
|
533
532
|
**Running Examples:**
|
|
534
533
|
|
package/dist/index.cjs
CHANGED
|
@@ -29910,9 +29910,7 @@ function convertToSAPMessages(prompt, options = {}) {
|
|
|
29910
29910
|
}
|
|
29911
29911
|
default: {
|
|
29912
29912
|
const _exhaustiveCheck = message;
|
|
29913
|
-
throw new Error(
|
|
29914
|
-
`Unsupported role: ${_exhaustiveCheck.role}`
|
|
29915
|
-
);
|
|
29913
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck.role}`);
|
|
29916
29914
|
}
|
|
29917
29915
|
}
|
|
29918
29916
|
}
|
|
@@ -30194,6 +30192,8 @@ var SAPAILanguageModel = class {
|
|
|
30194
30192
|
* to SAP AI Core - the request continues executing on the server. This is a
|
|
30195
30193
|
* limitation of the SAP AI SDK's chatCompletion API.
|
|
30196
30194
|
*
|
|
30195
|
+
* @see https://github.com/SAP/ai-sdk-js/issues/1429 for tracking true cancellation support
|
|
30196
|
+
*
|
|
30197
30197
|
* @param options - Generation options including prompt, tools, and settings
|
|
30198
30198
|
* @returns Promise resolving to the generation result with content, usage, and metadata
|
|
30199
30199
|
*
|
|
@@ -30377,6 +30377,13 @@ var SAPAILanguageModel = class {
|
|
|
30377
30377
|
* - Usage format: `{ inputTokens: { total, ... }, outputTokens: { total, ... } }`
|
|
30378
30378
|
* - Warnings only in `stream-start` event
|
|
30379
30379
|
*
|
|
30380
|
+
* **Note on Abort Signal:**
|
|
30381
|
+
* The abort signal implementation uses Promise.race to reject the promise when
|
|
30382
|
+
* the signal is aborted. However, this does not cancel the underlying HTTP request
|
|
30383
|
+
* to SAP AI Core - the request continues executing on the server. This is a
|
|
30384
|
+
* limitation of the SAP AI SDK's chatCompletion API.
|
|
30385
|
+
*
|
|
30386
|
+
* @see https://github.com/SAP/ai-sdk-js/issues/1429 for tracking true cancellation support
|
|
30380
30387
|
* @see {@link https://sdk.vercel.ai/docs/ai-sdk-core/streaming Vercel AI SDK Streaming}
|
|
30381
30388
|
*
|
|
30382
30389
|
* @param options - Streaming options including prompt, tools, and settings
|
|
@@ -30423,11 +30430,9 @@ var SAPAILanguageModel = class {
|
|
|
30423
30430
|
return filtering && Object.keys(filtering).length > 0 ? { filtering } : {};
|
|
30424
30431
|
})()
|
|
30425
30432
|
};
|
|
30426
|
-
const streamResponse = await client.stream(
|
|
30427
|
-
|
|
30428
|
-
|
|
30429
|
-
{ promptTemplating: { include_usage: true } }
|
|
30430
|
-
);
|
|
30433
|
+
const streamResponse = await client.stream(requestBody, options.abortSignal, {
|
|
30434
|
+
promptTemplating: { include_usage: true }
|
|
30435
|
+
});
|
|
30431
30436
|
const idGenerator = new StreamIdGenerator();
|
|
30432
30437
|
let textBlockId = null;
|
|
30433
30438
|
const streamState = {
|
|
@@ -30714,12 +30719,9 @@ var SAPAILanguageModel = class {
|
|
|
30714
30719
|
let parameters;
|
|
30715
30720
|
if (toolWithParams.parameters && isZodSchema(toolWithParams.parameters)) {
|
|
30716
30721
|
try {
|
|
30717
|
-
const jsonSchema = (0, import_zod_to_json_schema.zodToJsonSchema)(
|
|
30718
|
-
|
|
30719
|
-
|
|
30720
|
-
$refStrategy: "none"
|
|
30721
|
-
}
|
|
30722
|
-
);
|
|
30722
|
+
const jsonSchema = (0, import_zod_to_json_schema.zodToJsonSchema)(toolWithParams.parameters, {
|
|
30723
|
+
$refStrategy: "none"
|
|
30724
|
+
});
|
|
30723
30725
|
const schemaRecord = jsonSchema;
|
|
30724
30726
|
delete schemaRecord.$schema;
|
|
30725
30727
|
parameters = buildSAPToolParameters(schemaRecord);
|
|
@@ -30865,11 +30867,7 @@ var SAPAILanguageModel = class {
|
|
|
30865
30867
|
* @internal
|
|
30866
30868
|
*/
|
|
30867
30869
|
createClient(config) {
|
|
30868
|
-
return new import_orchestration.OrchestrationClient(
|
|
30869
|
-
config,
|
|
30870
|
-
this.config.deploymentConfig,
|
|
30871
|
-
this.config.destination
|
|
30872
|
-
);
|
|
30870
|
+
return new import_orchestration.OrchestrationClient(config, this.config.deploymentConfig, this.config.destination);
|
|
30873
30871
|
}
|
|
30874
30872
|
};
|
|
30875
30873
|
function buildSAPToolParameters(schema) {
|
|
@@ -30898,9 +30896,7 @@ function buildSAPToolParameters(schema) {
|
|
|
30898
30896
|
function createAISDKRequestBodySummary(options) {
|
|
30899
30897
|
return {
|
|
30900
30898
|
hasImageParts: options.prompt.some(
|
|
30901
|
-
(message) => message.role === "user" && message.content.some(
|
|
30902
|
-
(part) => part.type === "file" && part.mediaType.startsWith("image/")
|
|
30903
|
-
)
|
|
30899
|
+
(message) => message.role === "user" && message.content.some((part) => part.type === "file" && part.mediaType.startsWith("image/"))
|
|
30904
30900
|
),
|
|
30905
30901
|
maxOutputTokens: options.maxOutputTokens,
|
|
30906
30902
|
promptMessages: options.prompt.length,
|
|
@@ -31019,9 +31015,7 @@ function createSAPAIProvider(options = {}) {
|
|
|
31019
31015
|
};
|
|
31020
31016
|
const provider = function(modelId, settings) {
|
|
31021
31017
|
if (new.target) {
|
|
31022
|
-
throw new Error(
|
|
31023
|
-
"The SAP AI provider function cannot be called with the new keyword."
|
|
31024
|
-
);
|
|
31018
|
+
throw new Error("The SAP AI provider function cannot be called with the new keyword.");
|
|
31025
31019
|
}
|
|
31026
31020
|
return createModel(modelId, settings);
|
|
31027
31021
|
};
|