@jerome-benoit/sap-ai-provider-v2 4.1.2 → 4.2.1
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 +2 -1
- package/dist/index.cjs +45 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +123 -45
- package/dist/index.d.ts +123 -45
- package/dist/index.js +44 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmbeddingModelV2, SharedV2ProviderOptions, SharedV2ProviderMetadata, SharedV2Headers, LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2ResponseMetadata, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2StreamPart } from '@ai-sdk/provider';
|
|
1
|
+
import { EmbeddingModelV2, SharedV2ProviderOptions, SharedV2ProviderMetadata, SharedV2Headers, LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2ResponseMetadata, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2StreamPart, ProviderV2, ImageModelV2 } from '@ai-sdk/provider';
|
|
2
2
|
import { DeploymentIdConfig, ResourceGroupConfig } from '@sap-ai-sdk/ai-api/internal.js';
|
|
3
3
|
import { HttpDestinationOrFetchOptions } from '@sap-cloud-sdk/connectivity';
|
|
4
4
|
import { EmbeddingModelParams, FilteringModule, GroundingModule, MaskingModule, ChatCompletionTool, TranslationModule, ChatModel } from '@sap-ai-sdk/orchestration';
|
|
@@ -6,6 +6,15 @@ export { AssistantChatMessage, ChatCompletionRequest, ChatCompletionTool, ChatMe
|
|
|
6
6
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
7
7
|
import { InferSchema } from '@ai-sdk/provider-utils';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* SAP AI Embedding Model implementation.
|
|
11
|
+
*
|
|
12
|
+
* This module provides an EmbeddingModelV3 implementation that bridges
|
|
13
|
+
* the Vercel AI SDK with SAP AI Core's Orchestration API for generating
|
|
14
|
+
* text embeddings using the official SAP AI SDK (@sap-ai-sdk/orchestration).
|
|
15
|
+
* @module sap-ai-embedding-model
|
|
16
|
+
*/
|
|
17
|
+
|
|
9
18
|
/**
|
|
10
19
|
* Model ID type for SAP AI embedding models.
|
|
11
20
|
*
|
|
@@ -23,16 +32,16 @@ interface SAPAIEmbeddingSettings {
|
|
|
23
32
|
* Maximum number of embeddings per API call.
|
|
24
33
|
* @default 2048
|
|
25
34
|
*/
|
|
26
|
-
maxEmbeddingsPerCall?: number;
|
|
35
|
+
readonly maxEmbeddingsPerCall?: number;
|
|
27
36
|
/**
|
|
28
37
|
* Additional model parameters passed to the embedding API.
|
|
29
38
|
*/
|
|
30
|
-
modelParams?: EmbeddingModelParams;
|
|
39
|
+
readonly modelParams?: EmbeddingModelParams;
|
|
31
40
|
/**
|
|
32
41
|
* Embedding task type.
|
|
33
42
|
* @default 'text'
|
|
34
43
|
*/
|
|
35
|
-
type?: "document" | "query" | "text";
|
|
44
|
+
readonly type?: "document" | "query" | "text";
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
/**
|
|
@@ -53,9 +62,9 @@ interface SAPAIEmbeddingSettings {
|
|
|
53
62
|
* @internal
|
|
54
63
|
*/
|
|
55
64
|
interface SAPAIEmbeddingConfig {
|
|
56
|
-
deploymentConfig: DeploymentIdConfig | ResourceGroupConfig;
|
|
57
|
-
destination?: HttpDestinationOrFetchOptions;
|
|
58
|
-
provider: string;
|
|
65
|
+
readonly deploymentConfig: DeploymentIdConfig | ResourceGroupConfig;
|
|
66
|
+
readonly destination?: HttpDestinationOrFetchOptions;
|
|
67
|
+
readonly provider: string;
|
|
59
68
|
}
|
|
60
69
|
/**
|
|
61
70
|
* SAP AI Core Embedding Model implementing the Vercel AI SDK EmbeddingModelV2 interface.
|
|
@@ -128,6 +137,7 @@ declare class SAPAIEmbeddingModelV2 implements EmbeddingModelV2<string> {
|
|
|
128
137
|
* @param options.providerOptions - Optional provider-specific options
|
|
129
138
|
* @param options.headers - Optional HTTP headers
|
|
130
139
|
* @returns Promise resolving to embeddings and metadata in V2 format
|
|
140
|
+
* @since 1.0.0
|
|
131
141
|
*/
|
|
132
142
|
doEmbed(options: {
|
|
133
143
|
abortSignal?: AbortSignal;
|
|
@@ -148,8 +158,9 @@ declare class SAPAIEmbeddingModelV2 implements EmbeddingModelV2<string> {
|
|
|
148
158
|
}
|
|
149
159
|
|
|
150
160
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
161
|
+
* Default provider name.
|
|
162
|
+
*
|
|
163
|
+
* Use this as key in `providerOptions` and `providerMetadata` when using the default provider name.
|
|
153
164
|
* @example
|
|
154
165
|
* ```typescript
|
|
155
166
|
* providerOptions: {
|
|
@@ -158,6 +169,22 @@ declare class SAPAIEmbeddingModelV2 implements EmbeddingModelV2<string> {
|
|
|
158
169
|
* ```
|
|
159
170
|
*/
|
|
160
171
|
declare const SAP_AI_PROVIDER_NAME: "sap-ai";
|
|
172
|
+
/**
|
|
173
|
+
* Extracts the provider name from a provider identifier.
|
|
174
|
+
*
|
|
175
|
+
* Following the AI SDK convention, provider identifiers use the format `{name}.{type}`
|
|
176
|
+
* (e.g., `"openai.chat"`, `"anthropic.messages"`). This function extracts the provider name
|
|
177
|
+
* for use with `providerOptions` and `providerMetadata`, which use the provider name as key.
|
|
178
|
+
* @param providerIdentifier - The provider identifier (e.g., `"sap-ai.chat"`, `"sap-ai.embedding"`)
|
|
179
|
+
* @returns The provider name (e.g., `"sap-ai"`)
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* getProviderName("sap-ai.chat") // => "sap-ai"
|
|
183
|
+
* getProviderName("sap-ai-core.embedding") // => "sap-ai-core"
|
|
184
|
+
* getProviderName("sap-ai") // => "sap-ai" (no type suffix)
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
declare function getProviderName(providerIdentifier: string): string;
|
|
161
188
|
/**
|
|
162
189
|
* Zod schema for SAP AI language model provider options.
|
|
163
190
|
*
|
|
@@ -327,7 +354,7 @@ interface SAPAISettings {
|
|
|
327
354
|
* });
|
|
328
355
|
* ```
|
|
329
356
|
*/
|
|
330
|
-
filtering?: FilteringModule;
|
|
357
|
+
readonly filtering?: FilteringModule;
|
|
331
358
|
/**
|
|
332
359
|
* Grounding module configuration for document-based retrieval (RAG).
|
|
333
360
|
* Enables retrieval-augmented generation using SAP Document Grounding Service.
|
|
@@ -356,7 +383,7 @@ interface SAPAISettings {
|
|
|
356
383
|
* });
|
|
357
384
|
* ```
|
|
358
385
|
*/
|
|
359
|
-
grounding?: GroundingModule;
|
|
386
|
+
readonly grounding?: GroundingModule;
|
|
360
387
|
/**
|
|
361
388
|
* Whether to include assistant reasoning parts in the SAP prompt conversion.
|
|
362
389
|
*
|
|
@@ -370,7 +397,7 @@ interface SAPAISettings {
|
|
|
370
397
|
* const prodModel = provider('gpt-4o'); // includeReasoning defaults to false
|
|
371
398
|
* ```
|
|
372
399
|
*/
|
|
373
|
-
includeReasoning?: boolean;
|
|
400
|
+
readonly includeReasoning?: boolean;
|
|
374
401
|
/**
|
|
375
402
|
* Masking configuration for SAP AI Core orchestration.
|
|
376
403
|
* When provided, sensitive information in prompts can be anonymized or
|
|
@@ -392,22 +419,22 @@ interface SAPAISettings {
|
|
|
392
419
|
* });
|
|
393
420
|
* ```
|
|
394
421
|
*/
|
|
395
|
-
masking?: MaskingModule;
|
|
422
|
+
readonly masking?: MaskingModule;
|
|
396
423
|
/**
|
|
397
424
|
* Model generation parameters that control the output.
|
|
398
425
|
*/
|
|
399
|
-
modelParams?: {
|
|
426
|
+
readonly modelParams?: {
|
|
400
427
|
/**
|
|
401
428
|
* Frequency penalty between -2.0 and 2.0.
|
|
402
429
|
* Positive values penalize tokens based on their frequency.
|
|
403
430
|
* If not specified, the model's default is used (typically 0).
|
|
404
431
|
*/
|
|
405
|
-
frequencyPenalty?: number;
|
|
432
|
+
readonly frequencyPenalty?: number;
|
|
406
433
|
/**
|
|
407
434
|
* Maximum number of tokens to generate.
|
|
408
435
|
* Higher values allow for longer responses but increase latency and cost.
|
|
409
436
|
*/
|
|
410
|
-
maxTokens?: number;
|
|
437
|
+
readonly maxTokens?: number;
|
|
411
438
|
/**
|
|
412
439
|
* Number of completions to generate.
|
|
413
440
|
* Multiple completions provide alternative responses.
|
|
@@ -416,38 +443,38 @@ interface SAPAISettings {
|
|
|
416
443
|
* models, the parameter is silently omitted from the request.
|
|
417
444
|
* If not specified, typically defaults to 1 on the model side.
|
|
418
445
|
*/
|
|
419
|
-
n?: number;
|
|
446
|
+
readonly n?: number;
|
|
420
447
|
/**
|
|
421
448
|
* Whether to enable parallel tool calls.
|
|
422
449
|
* When enabled, the model can call multiple tools in parallel.
|
|
423
450
|
*
|
|
424
451
|
* Note: This uses the SAP/OpenAI-style key `parallel_tool_calls`.
|
|
425
452
|
*/
|
|
426
|
-
parallel_tool_calls?: boolean;
|
|
453
|
+
readonly parallel_tool_calls?: boolean;
|
|
427
454
|
/**
|
|
428
455
|
* Presence penalty between -2.0 and 2.0.
|
|
429
456
|
* Positive values penalize tokens that have appeared in the text.
|
|
430
457
|
* If not specified, the model's default is used (typically 0).
|
|
431
458
|
*/
|
|
432
|
-
presencePenalty?: number;
|
|
459
|
+
readonly presencePenalty?: number;
|
|
433
460
|
/**
|
|
434
461
|
* Sampling temperature between 0 and 2.
|
|
435
462
|
* Higher values make output more random, lower values more deterministic.
|
|
436
463
|
* If not specified, the model's default temperature is used.
|
|
437
464
|
*/
|
|
438
|
-
temperature?: number;
|
|
465
|
+
readonly temperature?: number;
|
|
439
466
|
/**
|
|
440
467
|
* Nucleus sampling parameter between 0 and 1.
|
|
441
468
|
* Controls diversity via cumulative probability cutoff.
|
|
442
469
|
* If not specified, the model's default topP is used (typically 1).
|
|
443
470
|
*/
|
|
444
|
-
topP?: number;
|
|
471
|
+
readonly topP?: number;
|
|
445
472
|
};
|
|
446
473
|
/**
|
|
447
474
|
* Specific version of the model to use.
|
|
448
475
|
* If not provided, the latest version will be used.
|
|
449
476
|
*/
|
|
450
|
-
modelVersion?: string;
|
|
477
|
+
readonly modelVersion?: string;
|
|
451
478
|
/**
|
|
452
479
|
* Response format for templating prompt (OpenAI-compatible)
|
|
453
480
|
* Allows specifying structured output formats
|
|
@@ -464,18 +491,18 @@ interface SAPAISettings {
|
|
|
464
491
|
* });
|
|
465
492
|
* ```
|
|
466
493
|
*/
|
|
467
|
-
responseFormat?: {
|
|
468
|
-
json_schema: {
|
|
469
|
-
description?: string;
|
|
470
|
-
name: string;
|
|
471
|
-
schema?: unknown;
|
|
472
|
-
strict?: boolean | null;
|
|
494
|
+
readonly responseFormat?: {
|
|
495
|
+
readonly json_schema: {
|
|
496
|
+
readonly description?: string;
|
|
497
|
+
readonly name: string;
|
|
498
|
+
readonly schema?: unknown;
|
|
499
|
+
readonly strict?: boolean | null;
|
|
473
500
|
};
|
|
474
|
-
type: "json_schema";
|
|
501
|
+
readonly type: "json_schema";
|
|
475
502
|
} | {
|
|
476
|
-
type: "json_object";
|
|
503
|
+
readonly type: "json_object";
|
|
477
504
|
} | {
|
|
478
|
-
type: "text";
|
|
505
|
+
readonly type: "text";
|
|
479
506
|
};
|
|
480
507
|
/**
|
|
481
508
|
* Tool definitions in SAP AI SDK format
|
|
@@ -508,7 +535,7 @@ interface SAPAISettings {
|
|
|
508
535
|
* });
|
|
509
536
|
* ```
|
|
510
537
|
*/
|
|
511
|
-
tools?: ChatCompletionTool[];
|
|
538
|
+
readonly tools?: ChatCompletionTool[];
|
|
512
539
|
/**
|
|
513
540
|
* Translation module configuration for input/output translation.
|
|
514
541
|
* Enables automatic translation using SAP Document Translation service.
|
|
@@ -532,7 +559,7 @@ interface SAPAISettings {
|
|
|
532
559
|
* });
|
|
533
560
|
* ```
|
|
534
561
|
*/
|
|
535
|
-
translation?: TranslationModule;
|
|
562
|
+
readonly translation?: TranslationModule;
|
|
536
563
|
}
|
|
537
564
|
|
|
538
565
|
/**
|
|
@@ -553,9 +580,9 @@ interface SAPAISettings {
|
|
|
553
580
|
* @internal
|
|
554
581
|
*/
|
|
555
582
|
interface SAPAIConfig {
|
|
556
|
-
deploymentConfig: DeploymentIdConfig | ResourceGroupConfig;
|
|
557
|
-
destination?: HttpDestinationOrFetchOptions;
|
|
558
|
-
provider: string;
|
|
583
|
+
readonly deploymentConfig: DeploymentIdConfig | ResourceGroupConfig;
|
|
584
|
+
readonly destination?: HttpDestinationOrFetchOptions;
|
|
585
|
+
readonly provider: string;
|
|
559
586
|
}
|
|
560
587
|
/**
|
|
561
588
|
* SAP AI Language Model V2 implementation.
|
|
@@ -767,7 +794,7 @@ interface SAPAIProviderSettings {
|
|
|
767
794
|
* Default model settings applied to every model instance created by this provider.
|
|
768
795
|
* Per-call settings provided to the model will override these.
|
|
769
796
|
*/
|
|
770
|
-
defaultSettings?: SAPAISettings;
|
|
797
|
+
readonly defaultSettings?: SAPAISettings;
|
|
771
798
|
/**
|
|
772
799
|
* SAP AI Core deployment ID.
|
|
773
800
|
*
|
|
@@ -778,7 +805,7 @@ interface SAPAIProviderSettings {
|
|
|
778
805
|
* deploymentId: 'd65d81e7c077e583'
|
|
779
806
|
* ```
|
|
780
807
|
*/
|
|
781
|
-
deploymentId?: string;
|
|
808
|
+
readonly deploymentId?: string;
|
|
782
809
|
/**
|
|
783
810
|
* Custom destination configuration for SAP AI Core.
|
|
784
811
|
*
|
|
@@ -793,7 +820,32 @@ interface SAPAIProviderSettings {
|
|
|
793
820
|
* }
|
|
794
821
|
* ```
|
|
795
822
|
*/
|
|
796
|
-
destination?: HttpDestinationOrFetchOptions;
|
|
823
|
+
readonly destination?: HttpDestinationOrFetchOptions;
|
|
824
|
+
/**
|
|
825
|
+
* Provider name.
|
|
826
|
+
*
|
|
827
|
+
* Used as the key for `providerOptions` and `providerMetadata` in AI SDK calls.
|
|
828
|
+
* The provider identifier (exposed via `model.provider`) follows the AI SDK convention
|
|
829
|
+
* `{name}.{type}` (e.g., `"sap-ai.chat"`, `"sap-ai.embedding"`).
|
|
830
|
+
* @default 'sap-ai'
|
|
831
|
+
* @example
|
|
832
|
+
* ```typescript
|
|
833
|
+
* const provider = createSAPAIProvider({ name: 'sap-ai-core' });
|
|
834
|
+
* const model = provider('gpt-4o');
|
|
835
|
+
*
|
|
836
|
+
* console.log(model.provider); // => "sap-ai-core.chat"
|
|
837
|
+
*
|
|
838
|
+
* // Use provider name in providerOptions:
|
|
839
|
+
* await generateText({
|
|
840
|
+
* model,
|
|
841
|
+
* prompt: 'Hello',
|
|
842
|
+
* providerOptions: {
|
|
843
|
+
* 'sap-ai-core': { includeReasoning: true }
|
|
844
|
+
* }
|
|
845
|
+
* });
|
|
846
|
+
* ```
|
|
847
|
+
*/
|
|
848
|
+
readonly name?: string;
|
|
797
849
|
/**
|
|
798
850
|
* SAP AI Core resource group.
|
|
799
851
|
*
|
|
@@ -808,14 +860,14 @@ interface SAPAIProviderSettings {
|
|
|
808
860
|
* resourceGroup: 'development' // Development environment
|
|
809
861
|
* ```
|
|
810
862
|
*/
|
|
811
|
-
resourceGroup?: string;
|
|
863
|
+
readonly resourceGroup?: string;
|
|
812
864
|
/**
|
|
813
865
|
* Whether to emit warnings for ambiguous configurations.
|
|
814
866
|
*
|
|
815
867
|
* When enabled (default), the provider will warn when mutually-exclusive
|
|
816
868
|
* settings are provided (e.g. both `deploymentId` and `resourceGroup`).
|
|
817
869
|
*/
|
|
818
|
-
warnOnAmbiguousConfig?: boolean;
|
|
870
|
+
readonly warnOnAmbiguousConfig?: boolean;
|
|
819
871
|
}
|
|
820
872
|
/**
|
|
821
873
|
* SAP AI Provider V2 interface.
|
|
@@ -843,7 +895,7 @@ interface SAPAIProviderSettings {
|
|
|
843
895
|
* const chatModel = provider.languageModel('gpt-4o');
|
|
844
896
|
* ```
|
|
845
897
|
*/
|
|
846
|
-
interface SAPAIProviderV2 {
|
|
898
|
+
interface SAPAIProviderV2 extends ProviderV2 {
|
|
847
899
|
/**
|
|
848
900
|
* Create a language model instance (V2).
|
|
849
901
|
* @param modelId - The SAP AI Core model identifier (e.g., 'gpt-4o', 'anthropic--claude-3.5-sonnet')
|
|
@@ -868,12 +920,37 @@ interface SAPAIProviderV2 {
|
|
|
868
920
|
* @param modelId - The embedding model identifier (e.g., 'text-embedding-ada-002')
|
|
869
921
|
* @param settings - Optional embedding model settings
|
|
870
922
|
* @returns Configured SAP AI embedding model instance (V2)
|
|
923
|
+
* @example
|
|
924
|
+
* ```typescript
|
|
925
|
+
* import { embed } from 'ai';
|
|
926
|
+
*
|
|
927
|
+
* const { embedding } = await embed({
|
|
928
|
+
* model: provider.embedding('text-embedding-ada-002'),
|
|
929
|
+
* value: 'Hello, world!'
|
|
930
|
+
* });
|
|
931
|
+
* ```
|
|
871
932
|
*/
|
|
872
933
|
embedding(modelId: SAPAIEmbeddingModelId, settings?: SAPAIEmbeddingSettings): SAPAIEmbeddingModelV2;
|
|
934
|
+
/**
|
|
935
|
+
* Image model stub for ProviderV2 interface compliance.
|
|
936
|
+
*
|
|
937
|
+
* SAP AI Core Orchestration Service does not currently support image generation.
|
|
938
|
+
* This method always throws a `NoSuchModelError` to indicate that image generation
|
|
939
|
+
* is not available through this provider.
|
|
940
|
+
* @param modelId - The image model identifier (not used)
|
|
941
|
+
* @throws {NoSuchModelError} Always throws - image generation is not supported
|
|
942
|
+
* @example
|
|
943
|
+
* ```typescript
|
|
944
|
+
* // This will always throw NoSuchModelError
|
|
945
|
+
* provider.imageModel('dall-e-3'); // throws NoSuchModelError
|
|
946
|
+
* ```
|
|
947
|
+
*/
|
|
948
|
+
imageModel(modelId: string): ImageModelV2;
|
|
873
949
|
/**
|
|
874
950
|
* Create a language model instance (V2).
|
|
875
951
|
*
|
|
876
|
-
*
|
|
952
|
+
* Standard ProviderV2 method for creating language models.
|
|
953
|
+
* Equivalent to calling the provider function directly or using `chat()`.
|
|
877
954
|
* @param modelId - The SAP AI Core model identifier
|
|
878
955
|
* @param settings - Optional model configuration settings
|
|
879
956
|
* @returns Configured SAP AI language model instance (V2)
|
|
@@ -882,7 +959,8 @@ interface SAPAIProviderV2 {
|
|
|
882
959
|
/**
|
|
883
960
|
* Create a text embedding model instance (V2).
|
|
884
961
|
*
|
|
885
|
-
*
|
|
962
|
+
* Standard ProviderV2 method for creating embedding models.
|
|
963
|
+
* Equivalent to calling `embedding()`.
|
|
886
964
|
* @param modelId - The embedding model identifier
|
|
887
965
|
* @param settings - Optional embedding model settings
|
|
888
966
|
* @returns Configured SAP AI embedding model instance (V2)
|
|
@@ -969,4 +1047,4 @@ declare function createSAPAIProvider(options?: SAPAIProviderSettings): SAPAIProv
|
|
|
969
1047
|
*/
|
|
970
1048
|
declare const sapai: SAPAIProviderV2;
|
|
971
1049
|
|
|
972
|
-
export { type DeploymentConfig, SAPAIEmbeddingModelV2 as SAPAIEmbeddingModel, type SAPAIEmbeddingModelId, type SAPAIEmbeddingProviderOptions, type SAPAIEmbeddingSettings, type SAPAILanguageModelProviderOptions, type SAPAIModelId, type SAPAIProviderV2 as SAPAIProvider, type SAPAIProviderSettings, type SAPAISettings, SAP_AI_PROVIDER_NAME, createSAPAIProvider, sapAIEmbeddingProviderOptions, sapAILanguageModelProviderOptions, sapai };
|
|
1050
|
+
export { type DeploymentConfig, SAPAIEmbeddingModelV2 as SAPAIEmbeddingModel, type SAPAIEmbeddingModelId, type SAPAIEmbeddingProviderOptions, type SAPAIEmbeddingSettings, type SAPAILanguageModelProviderOptions, type SAPAIModelId, type SAPAIProviderV2 as SAPAIProvider, type SAPAIProviderSettings, type SAPAISettings, SAP_AI_PROVIDER_NAME, createSAPAIProvider, getProviderName, sapAIEmbeddingProviderOptions, sapAILanguageModelProviderOptions, sapai };
|
package/dist/index.js
CHANGED
|
@@ -30207,6 +30207,10 @@ function tryExtractSAPErrorFromMessage(message) {
|
|
|
30207
30207
|
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
30208
30208
|
import { z } from "zod";
|
|
30209
30209
|
var SAP_AI_PROVIDER_NAME = "sap-ai";
|
|
30210
|
+
function getProviderName(providerIdentifier) {
|
|
30211
|
+
const dotIndex = providerIdentifier.indexOf(".");
|
|
30212
|
+
return dotIndex === -1 ? providerIdentifier : providerIdentifier.slice(0, dotIndex);
|
|
30213
|
+
}
|
|
30210
30214
|
var modelParamsSchema = z.object({
|
|
30211
30215
|
/**
|
|
30212
30216
|
* Frequency penalty between -2.0 and 2.0.
|
|
@@ -30381,6 +30385,7 @@ var SAPAIEmbeddingModel = class {
|
|
|
30381
30385
|
* the SAP AI SDK's OrchestrationEmbeddingClient.
|
|
30382
30386
|
* @param options - The embedding request options
|
|
30383
30387
|
* @returns Promise resolving to embeddings and usage information
|
|
30388
|
+
* @since 1.0.0
|
|
30384
30389
|
* @example
|
|
30385
30390
|
* ```typescript
|
|
30386
30391
|
* const result = await model.doEmbed({
|
|
@@ -30393,8 +30398,9 @@ var SAPAIEmbeddingModel = class {
|
|
|
30393
30398
|
*/
|
|
30394
30399
|
async doEmbed(options) {
|
|
30395
30400
|
const { abortSignal, providerOptions, values } = options;
|
|
30401
|
+
const providerName = getProviderName(this.config.provider);
|
|
30396
30402
|
const sapOptions = await parseProviderOptions({
|
|
30397
|
-
provider:
|
|
30403
|
+
provider: providerName,
|
|
30398
30404
|
providerOptions,
|
|
30399
30405
|
schema: sapAIEmbeddingProviderOptions
|
|
30400
30406
|
});
|
|
@@ -30424,7 +30430,7 @@ var SAPAIEmbeddingModel = class {
|
|
|
30424
30430
|
(data) => this.normalizeEmbedding(data.embedding)
|
|
30425
30431
|
);
|
|
30426
30432
|
const providerMetadata = {
|
|
30427
|
-
|
|
30433
|
+
[providerName]: {
|
|
30428
30434
|
model: this.modelId
|
|
30429
30435
|
}
|
|
30430
30436
|
};
|
|
@@ -30523,6 +30529,7 @@ var SAPAIEmbeddingModelV2 = class {
|
|
|
30523
30529
|
* @param options.providerOptions - Optional provider-specific options
|
|
30524
30530
|
* @param options.headers - Optional HTTP headers
|
|
30525
30531
|
* @returns Promise resolving to embeddings and metadata in V2 format
|
|
30532
|
+
* @since 1.0.0
|
|
30526
30533
|
*/
|
|
30527
30534
|
async doEmbed(options) {
|
|
30528
30535
|
const v3Options = {
|
|
@@ -30563,6 +30570,9 @@ function castProviderMetadataV3ToV2(v3Metadata) {
|
|
|
30563
30570
|
return v3Metadata;
|
|
30564
30571
|
}
|
|
30565
30572
|
|
|
30573
|
+
// src/sap-ai-provider-v2.ts
|
|
30574
|
+
import { NoSuchModelError as NoSuchModelError2 } from "@ai-sdk/provider";
|
|
30575
|
+
|
|
30566
30576
|
// src/sap-ai-language-model.ts
|
|
30567
30577
|
import { parseProviderOptions as parseProviderOptions2 } from "@ai-sdk/provider-utils";
|
|
30568
30578
|
import {
|
|
@@ -30947,11 +30957,12 @@ var SAPAILanguageModel = class {
|
|
|
30947
30957
|
tokenUsage,
|
|
30948
30958
|
toolCalls
|
|
30949
30959
|
};
|
|
30960
|
+
const providerName = getProviderName(this.config.provider);
|
|
30950
30961
|
return {
|
|
30951
30962
|
content,
|
|
30952
30963
|
finishReason,
|
|
30953
30964
|
providerMetadata: {
|
|
30954
|
-
|
|
30965
|
+
[providerName]: {
|
|
30955
30966
|
finishReason: finishReasonRaw ?? "unknown",
|
|
30956
30967
|
finishReasonMapped: finishReason,
|
|
30957
30968
|
...typeof responseHeaders?.["x-request-id"] === "string" ? { requestId: responseHeaders["x-request-id"] } : {}
|
|
@@ -31082,6 +31093,7 @@ var SAPAILanguageModel = class {
|
|
|
31082
31093
|
const toolCallsInProgress = /* @__PURE__ */ new Map();
|
|
31083
31094
|
const sdkStream = streamResponse.stream;
|
|
31084
31095
|
const modelId = this.modelId;
|
|
31096
|
+
const providerName = getProviderName(this.config.provider);
|
|
31085
31097
|
const warningsSnapshot = [...warnings];
|
|
31086
31098
|
const warningsOut = [...warningsSnapshot];
|
|
31087
31099
|
const transformedStream = new ReadableStream({
|
|
@@ -31270,7 +31282,7 @@ var SAPAILanguageModel = class {
|
|
|
31270
31282
|
controller.enqueue({
|
|
31271
31283
|
finishReason: streamState.finishReason,
|
|
31272
31284
|
providerMetadata: {
|
|
31273
|
-
|
|
31285
|
+
[providerName]: {
|
|
31274
31286
|
finishReason: streamState.finishReason.raw,
|
|
31275
31287
|
responseId
|
|
31276
31288
|
}
|
|
@@ -31326,8 +31338,9 @@ var SAPAILanguageModel = class {
|
|
|
31326
31338
|
* @internal
|
|
31327
31339
|
*/
|
|
31328
31340
|
async buildOrchestrationConfig(options) {
|
|
31341
|
+
const providerName = getProviderName(this.config.provider);
|
|
31329
31342
|
const sapOptions = await parseProviderOptions2({
|
|
31330
|
-
provider:
|
|
31343
|
+
provider: providerName,
|
|
31331
31344
|
providerOptions: options.providerOptions,
|
|
31332
31345
|
schema: sapAILanguageModelProviderOptions
|
|
31333
31346
|
});
|
|
@@ -31449,21 +31462,26 @@ var SAPAILanguageModel = class {
|
|
|
31449
31462
|
type: "unsupported"
|
|
31450
31463
|
});
|
|
31451
31464
|
}
|
|
31465
|
+
let responseFormat;
|
|
31452
31466
|
if (options.responseFormat?.type === "json") {
|
|
31467
|
+
responseFormat = options.responseFormat.schema ? {
|
|
31468
|
+
json_schema: {
|
|
31469
|
+
description: options.responseFormat.description,
|
|
31470
|
+
name: options.responseFormat.name ?? "response",
|
|
31471
|
+
schema: options.responseFormat.schema,
|
|
31472
|
+
strict: null
|
|
31473
|
+
},
|
|
31474
|
+
type: "json_schema"
|
|
31475
|
+
} : { type: "json_object" };
|
|
31476
|
+
} else if (this.settings.responseFormat) {
|
|
31477
|
+
responseFormat = this.settings.responseFormat;
|
|
31478
|
+
}
|
|
31479
|
+
if (responseFormat && responseFormat.type !== "text") {
|
|
31453
31480
|
warnings.push({
|
|
31454
31481
|
message: "responseFormat JSON mode is forwarded to the underlying model; support and schema adherence depend on the model/deployment.",
|
|
31455
31482
|
type: "other"
|
|
31456
31483
|
});
|
|
31457
31484
|
}
|
|
31458
|
-
const responseFormat = options.responseFormat?.type === "json" ? options.responseFormat.schema ? {
|
|
31459
|
-
json_schema: {
|
|
31460
|
-
description: options.responseFormat.description,
|
|
31461
|
-
name: options.responseFormat.name ?? "response",
|
|
31462
|
-
schema: options.responseFormat.schema,
|
|
31463
|
-
strict: null
|
|
31464
|
-
},
|
|
31465
|
-
type: "json_schema"
|
|
31466
|
-
} : { type: "json_object" } : void 0;
|
|
31467
31485
|
const orchestrationConfig = {
|
|
31468
31486
|
promptTemplating: {
|
|
31469
31487
|
model: {
|
|
@@ -31745,6 +31763,7 @@ function createSAPAIProvider(options = {}) {
|
|
|
31745
31763
|
if (options.defaultSettings?.modelParams) {
|
|
31746
31764
|
validateModelParamsSettings(options.defaultSettings.modelParams);
|
|
31747
31765
|
}
|
|
31766
|
+
const providerName = options.name ?? SAP_AI_PROVIDER_NAME;
|
|
31748
31767
|
const resourceGroup = options.resourceGroup ?? "default";
|
|
31749
31768
|
const warnOnAmbiguousConfig = options.warnOnAmbiguousConfig ?? true;
|
|
31750
31769
|
if (warnOnAmbiguousConfig && options.deploymentId && options.resourceGroup) {
|
|
@@ -31769,14 +31788,14 @@ function createSAPAIProvider(options = {}) {
|
|
|
31769
31788
|
return new SAPAILanguageModelV2(modelId, mergedSettings, {
|
|
31770
31789
|
deploymentConfig,
|
|
31771
31790
|
destination: options.destination,
|
|
31772
|
-
provider:
|
|
31791
|
+
provider: `${providerName}.chat`
|
|
31773
31792
|
});
|
|
31774
31793
|
};
|
|
31775
31794
|
const createEmbeddingModel = (modelId, settings = {}) => {
|
|
31776
31795
|
return new SAPAIEmbeddingModelV2(modelId, settings, {
|
|
31777
31796
|
deploymentConfig,
|
|
31778
31797
|
destination: options.destination,
|
|
31779
|
-
provider:
|
|
31798
|
+
provider: `${providerName}.embedding`
|
|
31780
31799
|
});
|
|
31781
31800
|
};
|
|
31782
31801
|
const provider = function(modelId, settings) {
|
|
@@ -31785,10 +31804,17 @@ function createSAPAIProvider(options = {}) {
|
|
|
31785
31804
|
}
|
|
31786
31805
|
return createModel(modelId, settings);
|
|
31787
31806
|
};
|
|
31788
|
-
provider.languageModel = createModel;
|
|
31789
31807
|
provider.chat = createModel;
|
|
31808
|
+
provider.languageModel = createModel;
|
|
31790
31809
|
provider.embedding = createEmbeddingModel;
|
|
31791
31810
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
31811
|
+
provider.imageModel = (modelId) => {
|
|
31812
|
+
throw new NoSuchModelError2({
|
|
31813
|
+
message: `SAP AI Core Orchestration Service does not support image generation. Model '${modelId}' is not available.`,
|
|
31814
|
+
modelId,
|
|
31815
|
+
modelType: "imageModel"
|
|
31816
|
+
});
|
|
31817
|
+
};
|
|
31792
31818
|
return provider;
|
|
31793
31819
|
}
|
|
31794
31820
|
var sapai = createSAPAIProvider();
|
|
@@ -31824,6 +31850,7 @@ export {
|
|
|
31824
31850
|
buildLlamaGuard38BFilter,
|
|
31825
31851
|
buildTranslationConfig,
|
|
31826
31852
|
createSAPAIProvider,
|
|
31853
|
+
getProviderName,
|
|
31827
31854
|
isConfigReference,
|
|
31828
31855
|
sapAIEmbeddingProviderOptions,
|
|
31829
31856
|
sapAILanguageModelProviderOptions,
|