@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.cts
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 };
|