@jerome-benoit/sap-ai-provider 4.2.2 → 4.2.3
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/dist/index.cjs +41 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -56
- package/dist/index.d.ts +87 -56
- package/dist/index.js +40 -44
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -14141,7 +14141,7 @@ var require_cloud_sdk_logger = __commonJS({
|
|
|
14141
14141
|
exports2.createLogger = createLogger;
|
|
14142
14142
|
exports2.getLogger = getLogger;
|
|
14143
14143
|
exports2.setLogLevel = setLogLevel;
|
|
14144
|
-
exports2.setGlobalLogLevel =
|
|
14144
|
+
exports2.setGlobalLogLevel = setGlobalLogLevel2;
|
|
14145
14145
|
exports2.getGlobalLogLevel = getGlobalLogLevel;
|
|
14146
14146
|
exports2.setGlobalTransports = setGlobalTransports;
|
|
14147
14147
|
exports2.setLogFormat = setLogFormat;
|
|
@@ -14228,7 +14228,7 @@ var require_cloud_sdk_logger = __commonJS({
|
|
|
14228
14228
|
messageContextOrLogger.level = level;
|
|
14229
14229
|
}
|
|
14230
14230
|
}
|
|
14231
|
-
function
|
|
14231
|
+
function setGlobalLogLevel2(level) {
|
|
14232
14232
|
container.options.level = level;
|
|
14233
14233
|
container.loggers.forEach((logger) => {
|
|
14234
14234
|
logger.level = level;
|
|
@@ -29743,6 +29743,7 @@ __export(index_exports, {
|
|
|
29743
29743
|
OrchestrationStreamChunkResponse: () => import_orchestration4.OrchestrationStreamChunkResponse,
|
|
29744
29744
|
OrchestrationStreamResponse: () => import_orchestration4.OrchestrationStreamResponse,
|
|
29745
29745
|
SAPAIEmbeddingModel: () => SAPAIEmbeddingModel,
|
|
29746
|
+
SAPAILanguageModel: () => SAPAILanguageModel,
|
|
29746
29747
|
SAP_AI_PROVIDER_NAME: () => SAP_AI_PROVIDER_NAME,
|
|
29747
29748
|
buildAzureContentSafetyFilter: () => import_orchestration3.buildAzureContentSafetyFilter,
|
|
29748
29749
|
buildDocumentGroundingConfig: () => import_orchestration3.buildDocumentGroundingConfig,
|
|
@@ -30299,6 +30300,14 @@ var SAPAIEmbeddingModel = class {
|
|
|
30299
30300
|
supportsParallelCalls = true;
|
|
30300
30301
|
config;
|
|
30301
30302
|
settings;
|
|
30303
|
+
/**
|
|
30304
|
+
* Creates a new SAP AI Embedding Model instance.
|
|
30305
|
+
*
|
|
30306
|
+
* This is the main implementation that handles all SAP AI Core embedding logic.
|
|
30307
|
+
* @param modelId - The model identifier (e.g., 'text-embedding-ada-002', 'text-embedding-3-small').
|
|
30308
|
+
* @param settings - Model configuration settings (embedding type, model parameters, etc.). Defaults to {}.
|
|
30309
|
+
* @param config - SAP AI Core deployment and destination configuration.
|
|
30310
|
+
*/
|
|
30302
30311
|
constructor(modelId, settings = {}, config) {
|
|
30303
30312
|
if (settings.modelParams) {
|
|
30304
30313
|
validateEmbeddingModelParamsSettings(settings.modelParams);
|
|
@@ -30311,8 +30320,10 @@ var SAPAIEmbeddingModel = class {
|
|
|
30311
30320
|
}
|
|
30312
30321
|
/**
|
|
30313
30322
|
* Generates embeddings for the given input values.
|
|
30314
|
-
*
|
|
30315
|
-
*
|
|
30323
|
+
*
|
|
30324
|
+
* Validates input count, merges settings, calls SAP AI SDK, and normalizes embeddings.
|
|
30325
|
+
* @param options - The Vercel AI SDK V3 embedding call options.
|
|
30326
|
+
* @returns The embedding result with vectors, usage data, and warnings.
|
|
30316
30327
|
*/
|
|
30317
30328
|
async doEmbed(options) {
|
|
30318
30329
|
const { abortSignal, providerOptions, values } = options;
|
|
@@ -30403,9 +30414,6 @@ var SAPAIEmbeddingModel = class {
|
|
|
30403
30414
|
}
|
|
30404
30415
|
};
|
|
30405
30416
|
|
|
30406
|
-
// src/sap-ai-provider.ts
|
|
30407
|
-
var import_provider4 = require("@ai-sdk/provider");
|
|
30408
|
-
|
|
30409
30417
|
// src/sap-ai-language-model.ts
|
|
30410
30418
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
30411
30419
|
var import_orchestration2 = require("@sap-ai-sdk/orchestration");
|
|
@@ -30623,8 +30631,10 @@ var SAPAILanguageModel = class {
|
|
|
30623
30631
|
settings;
|
|
30624
30632
|
/**
|
|
30625
30633
|
* Creates a new SAP AI Language Model instance.
|
|
30626
|
-
*
|
|
30627
|
-
*
|
|
30634
|
+
*
|
|
30635
|
+
* This is the main implementation that handles all SAP AI Core orchestration logic.
|
|
30636
|
+
* @param modelId - The model identifier (e.g., 'gpt-4o', 'claude-3-5-sonnet', 'gemini-2.0-flash').
|
|
30637
|
+
* @param settings - Model configuration settings (temperature, max tokens, filtering, etc.).
|
|
30628
30638
|
* @param config - SAP AI Core deployment and destination configuration.
|
|
30629
30639
|
* @internal
|
|
30630
30640
|
*/
|
|
@@ -30638,9 +30648,12 @@ var SAPAILanguageModel = class {
|
|
|
30638
30648
|
}
|
|
30639
30649
|
/**
|
|
30640
30650
|
* Generates a single completion (non-streaming).
|
|
30641
|
-
*
|
|
30642
|
-
*
|
|
30643
|
-
*
|
|
30651
|
+
*
|
|
30652
|
+
* Builds orchestration configuration, converts messages, validates parameters,
|
|
30653
|
+
* calls SAP AI SDK, and processes the response.
|
|
30654
|
+
* Supports request cancellation via AbortSignal at the HTTP transport layer.
|
|
30655
|
+
* @param options - The Vercel AI SDK V3 generation call options.
|
|
30656
|
+
* @returns The generation result with content, usage, warnings, and provider metadata.
|
|
30644
30657
|
*/
|
|
30645
30658
|
async doGenerate(options) {
|
|
30646
30659
|
try {
|
|
@@ -30671,36 +30684,10 @@ var SAPAILanguageModel = class {
|
|
|
30671
30684
|
return translation && Object.keys(translation).length > 0 ? { translation } : {};
|
|
30672
30685
|
})()
|
|
30673
30686
|
};
|
|
30674
|
-
const response = await (
|
|
30675
|
-
|
|
30676
|
-
|
|
30677
|
-
|
|
30678
|
-
completionPromise,
|
|
30679
|
-
new Promise((_, reject) => {
|
|
30680
|
-
if (options.abortSignal?.aborted) {
|
|
30681
|
-
reject(
|
|
30682
|
-
new Error(
|
|
30683
|
-
`Request aborted: ${String(options.abortSignal.reason ?? "unknown reason")}`
|
|
30684
|
-
)
|
|
30685
|
-
);
|
|
30686
|
-
return;
|
|
30687
|
-
}
|
|
30688
|
-
options.abortSignal?.addEventListener(
|
|
30689
|
-
"abort",
|
|
30690
|
-
() => {
|
|
30691
|
-
reject(
|
|
30692
|
-
new Error(
|
|
30693
|
-
`Request aborted: ${String(options.abortSignal?.reason ?? "unknown reason")}`
|
|
30694
|
-
)
|
|
30695
|
-
);
|
|
30696
|
-
},
|
|
30697
|
-
{ once: true }
|
|
30698
|
-
);
|
|
30699
|
-
})
|
|
30700
|
-
]);
|
|
30701
|
-
}
|
|
30702
|
-
return completionPromise;
|
|
30703
|
-
})();
|
|
30687
|
+
const response = await client.chatCompletion(
|
|
30688
|
+
requestBody,
|
|
30689
|
+
options.abortSignal ? { signal: options.abortSignal } : void 0
|
|
30690
|
+
);
|
|
30704
30691
|
const responseHeadersRaw = response.rawResponse.headers;
|
|
30705
30692
|
const responseHeaders = responseHeadersRaw ? Object.fromEntries(
|
|
30706
30693
|
Object.entries(responseHeadersRaw).flatMap(([key, value]) => {
|
|
@@ -30788,8 +30775,11 @@ var SAPAILanguageModel = class {
|
|
|
30788
30775
|
}
|
|
30789
30776
|
/**
|
|
30790
30777
|
* Generates a streaming completion.
|
|
30791
|
-
*
|
|
30792
|
-
*
|
|
30778
|
+
*
|
|
30779
|
+
* Builds orchestration configuration, creates streaming client, and transforms
|
|
30780
|
+
* the stream with proper event handling (text blocks, tool calls, finish reason).
|
|
30781
|
+
* Supports request cancellation via AbortSignal at the HTTP transport layer.
|
|
30782
|
+
* @param options - The Vercel AI SDK V3 generation call options.
|
|
30793
30783
|
* @returns A stream result with async iterable stream parts.
|
|
30794
30784
|
*/
|
|
30795
30785
|
async doStream(options) {
|
|
@@ -31356,6 +31346,8 @@ function mapFinishReason(reason) {
|
|
|
31356
31346
|
}
|
|
31357
31347
|
|
|
31358
31348
|
// src/sap-ai-provider.ts
|
|
31349
|
+
var import_provider4 = require("@ai-sdk/provider");
|
|
31350
|
+
var import_util2 = __toESM(require_dist(), 1);
|
|
31359
31351
|
function createSAPAIProvider(options = {}) {
|
|
31360
31352
|
if (options.defaultSettings?.modelParams) {
|
|
31361
31353
|
validateModelParamsSettings(options.defaultSettings.modelParams);
|
|
@@ -31368,6 +31360,10 @@ function createSAPAIProvider(options = {}) {
|
|
|
31368
31360
|
"createSAPAIProvider: both 'deploymentId' and 'resourceGroup' were provided; using 'deploymentId' and ignoring 'resourceGroup'."
|
|
31369
31361
|
);
|
|
31370
31362
|
}
|
|
31363
|
+
if (!process.env.SAP_CLOUD_SDK_LOG_LEVEL) {
|
|
31364
|
+
const logLevel = options.logLevel ?? "warn";
|
|
31365
|
+
(0, import_util2.setGlobalLogLevel)(logLevel);
|
|
31366
|
+
}
|
|
31371
31367
|
const deploymentConfig = options.deploymentId ? { deploymentId: options.deploymentId } : { resourceGroup };
|
|
31372
31368
|
const createModel = (modelId, settings = {}) => {
|
|
31373
31369
|
const mergedSettings = {
|
|
@@ -31431,6 +31427,7 @@ var import_orchestration5 = require("@sap-ai-sdk/orchestration");
|
|
|
31431
31427
|
OrchestrationStreamChunkResponse,
|
|
31432
31428
|
OrchestrationStreamResponse,
|
|
31433
31429
|
SAPAIEmbeddingModel,
|
|
31430
|
+
SAPAILanguageModel,
|
|
31434
31431
|
SAP_AI_PROVIDER_NAME,
|
|
31435
31432
|
buildAzureContentSafetyFilter,
|
|
31436
31433
|
buildDocumentGroundingConfig,
|