@jerome-benoit/sap-ai-provider-v2 4.1.2-rc.2 → 4.1.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 +26 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +65 -40
- package/dist/index.d.ts +65 -40
- package/dist/index.js +26 -9
- 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;
|
|
@@ -327,7 +337,7 @@ interface SAPAISettings {
|
|
|
327
337
|
* });
|
|
328
338
|
* ```
|
|
329
339
|
*/
|
|
330
|
-
filtering?: FilteringModule;
|
|
340
|
+
readonly filtering?: FilteringModule;
|
|
331
341
|
/**
|
|
332
342
|
* Grounding module configuration for document-based retrieval (RAG).
|
|
333
343
|
* Enables retrieval-augmented generation using SAP Document Grounding Service.
|
|
@@ -356,7 +366,7 @@ interface SAPAISettings {
|
|
|
356
366
|
* });
|
|
357
367
|
* ```
|
|
358
368
|
*/
|
|
359
|
-
grounding?: GroundingModule;
|
|
369
|
+
readonly grounding?: GroundingModule;
|
|
360
370
|
/**
|
|
361
371
|
* Whether to include assistant reasoning parts in the SAP prompt conversion.
|
|
362
372
|
*
|
|
@@ -370,7 +380,7 @@ interface SAPAISettings {
|
|
|
370
380
|
* const prodModel = provider('gpt-4o'); // includeReasoning defaults to false
|
|
371
381
|
* ```
|
|
372
382
|
*/
|
|
373
|
-
includeReasoning?: boolean;
|
|
383
|
+
readonly includeReasoning?: boolean;
|
|
374
384
|
/**
|
|
375
385
|
* Masking configuration for SAP AI Core orchestration.
|
|
376
386
|
* When provided, sensitive information in prompts can be anonymized or
|
|
@@ -392,22 +402,22 @@ interface SAPAISettings {
|
|
|
392
402
|
* });
|
|
393
403
|
* ```
|
|
394
404
|
*/
|
|
395
|
-
masking?: MaskingModule;
|
|
405
|
+
readonly masking?: MaskingModule;
|
|
396
406
|
/**
|
|
397
407
|
* Model generation parameters that control the output.
|
|
398
408
|
*/
|
|
399
|
-
modelParams?: {
|
|
409
|
+
readonly modelParams?: {
|
|
400
410
|
/**
|
|
401
411
|
* Frequency penalty between -2.0 and 2.0.
|
|
402
412
|
* Positive values penalize tokens based on their frequency.
|
|
403
413
|
* If not specified, the model's default is used (typically 0).
|
|
404
414
|
*/
|
|
405
|
-
frequencyPenalty?: number;
|
|
415
|
+
readonly frequencyPenalty?: number;
|
|
406
416
|
/**
|
|
407
417
|
* Maximum number of tokens to generate.
|
|
408
418
|
* Higher values allow for longer responses but increase latency and cost.
|
|
409
419
|
*/
|
|
410
|
-
maxTokens?: number;
|
|
420
|
+
readonly maxTokens?: number;
|
|
411
421
|
/**
|
|
412
422
|
* Number of completions to generate.
|
|
413
423
|
* Multiple completions provide alternative responses.
|
|
@@ -416,38 +426,38 @@ interface SAPAISettings {
|
|
|
416
426
|
* models, the parameter is silently omitted from the request.
|
|
417
427
|
* If not specified, typically defaults to 1 on the model side.
|
|
418
428
|
*/
|
|
419
|
-
n?: number;
|
|
429
|
+
readonly n?: number;
|
|
420
430
|
/**
|
|
421
431
|
* Whether to enable parallel tool calls.
|
|
422
432
|
* When enabled, the model can call multiple tools in parallel.
|
|
423
433
|
*
|
|
424
434
|
* Note: This uses the SAP/OpenAI-style key `parallel_tool_calls`.
|
|
425
435
|
*/
|
|
426
|
-
parallel_tool_calls?: boolean;
|
|
436
|
+
readonly parallel_tool_calls?: boolean;
|
|
427
437
|
/**
|
|
428
438
|
* Presence penalty between -2.0 and 2.0.
|
|
429
439
|
* Positive values penalize tokens that have appeared in the text.
|
|
430
440
|
* If not specified, the model's default is used (typically 0).
|
|
431
441
|
*/
|
|
432
|
-
presencePenalty?: number;
|
|
442
|
+
readonly presencePenalty?: number;
|
|
433
443
|
/**
|
|
434
444
|
* Sampling temperature between 0 and 2.
|
|
435
445
|
* Higher values make output more random, lower values more deterministic.
|
|
436
446
|
* If not specified, the model's default temperature is used.
|
|
437
447
|
*/
|
|
438
|
-
temperature?: number;
|
|
448
|
+
readonly temperature?: number;
|
|
439
449
|
/**
|
|
440
450
|
* Nucleus sampling parameter between 0 and 1.
|
|
441
451
|
* Controls diversity via cumulative probability cutoff.
|
|
442
452
|
* If not specified, the model's default topP is used (typically 1).
|
|
443
453
|
*/
|
|
444
|
-
topP?: number;
|
|
454
|
+
readonly topP?: number;
|
|
445
455
|
};
|
|
446
456
|
/**
|
|
447
457
|
* Specific version of the model to use.
|
|
448
458
|
* If not provided, the latest version will be used.
|
|
449
459
|
*/
|
|
450
|
-
modelVersion?: string;
|
|
460
|
+
readonly modelVersion?: string;
|
|
451
461
|
/**
|
|
452
462
|
* Response format for templating prompt (OpenAI-compatible)
|
|
453
463
|
* Allows specifying structured output formats
|
|
@@ -464,18 +474,18 @@ interface SAPAISettings {
|
|
|
464
474
|
* });
|
|
465
475
|
* ```
|
|
466
476
|
*/
|
|
467
|
-
responseFormat?: {
|
|
468
|
-
json_schema: {
|
|
469
|
-
description?: string;
|
|
470
|
-
name: string;
|
|
471
|
-
schema?: unknown;
|
|
472
|
-
strict?: boolean | null;
|
|
477
|
+
readonly responseFormat?: {
|
|
478
|
+
readonly json_schema: {
|
|
479
|
+
readonly description?: string;
|
|
480
|
+
readonly name: string;
|
|
481
|
+
readonly schema?: unknown;
|
|
482
|
+
readonly strict?: boolean | null;
|
|
473
483
|
};
|
|
474
|
-
type: "json_schema";
|
|
484
|
+
readonly type: "json_schema";
|
|
475
485
|
} | {
|
|
476
|
-
type: "json_object";
|
|
486
|
+
readonly type: "json_object";
|
|
477
487
|
} | {
|
|
478
|
-
type: "text";
|
|
488
|
+
readonly type: "text";
|
|
479
489
|
};
|
|
480
490
|
/**
|
|
481
491
|
* Tool definitions in SAP AI SDK format
|
|
@@ -508,7 +518,7 @@ interface SAPAISettings {
|
|
|
508
518
|
* });
|
|
509
519
|
* ```
|
|
510
520
|
*/
|
|
511
|
-
tools?: ChatCompletionTool[];
|
|
521
|
+
readonly tools?: ChatCompletionTool[];
|
|
512
522
|
/**
|
|
513
523
|
* Translation module configuration for input/output translation.
|
|
514
524
|
* Enables automatic translation using SAP Document Translation service.
|
|
@@ -532,7 +542,7 @@ interface SAPAISettings {
|
|
|
532
542
|
* });
|
|
533
543
|
* ```
|
|
534
544
|
*/
|
|
535
|
-
translation?: TranslationModule;
|
|
545
|
+
readonly translation?: TranslationModule;
|
|
536
546
|
}
|
|
537
547
|
|
|
538
548
|
/**
|
|
@@ -553,9 +563,9 @@ interface SAPAISettings {
|
|
|
553
563
|
* @internal
|
|
554
564
|
*/
|
|
555
565
|
interface SAPAIConfig {
|
|
556
|
-
deploymentConfig: DeploymentIdConfig | ResourceGroupConfig;
|
|
557
|
-
destination?: HttpDestinationOrFetchOptions;
|
|
558
|
-
provider: string;
|
|
566
|
+
readonly deploymentConfig: DeploymentIdConfig | ResourceGroupConfig;
|
|
567
|
+
readonly destination?: HttpDestinationOrFetchOptions;
|
|
568
|
+
readonly provider: string;
|
|
559
569
|
}
|
|
560
570
|
/**
|
|
561
571
|
* SAP AI Language Model V2 implementation.
|
|
@@ -767,7 +777,7 @@ interface SAPAIProviderSettings {
|
|
|
767
777
|
* Default model settings applied to every model instance created by this provider.
|
|
768
778
|
* Per-call settings provided to the model will override these.
|
|
769
779
|
*/
|
|
770
|
-
defaultSettings?: SAPAISettings;
|
|
780
|
+
readonly defaultSettings?: SAPAISettings;
|
|
771
781
|
/**
|
|
772
782
|
* SAP AI Core deployment ID.
|
|
773
783
|
*
|
|
@@ -778,7 +788,7 @@ interface SAPAIProviderSettings {
|
|
|
778
788
|
* deploymentId: 'd65d81e7c077e583'
|
|
779
789
|
* ```
|
|
780
790
|
*/
|
|
781
|
-
deploymentId?: string;
|
|
791
|
+
readonly deploymentId?: string;
|
|
782
792
|
/**
|
|
783
793
|
* Custom destination configuration for SAP AI Core.
|
|
784
794
|
*
|
|
@@ -793,7 +803,7 @@ interface SAPAIProviderSettings {
|
|
|
793
803
|
* }
|
|
794
804
|
* ```
|
|
795
805
|
*/
|
|
796
|
-
destination?: HttpDestinationOrFetchOptions;
|
|
806
|
+
readonly destination?: HttpDestinationOrFetchOptions;
|
|
797
807
|
/**
|
|
798
808
|
* SAP AI Core resource group.
|
|
799
809
|
*
|
|
@@ -808,14 +818,14 @@ interface SAPAIProviderSettings {
|
|
|
808
818
|
* resourceGroup: 'development' // Development environment
|
|
809
819
|
* ```
|
|
810
820
|
*/
|
|
811
|
-
resourceGroup?: string;
|
|
821
|
+
readonly resourceGroup?: string;
|
|
812
822
|
/**
|
|
813
823
|
* Whether to emit warnings for ambiguous configurations.
|
|
814
824
|
*
|
|
815
825
|
* When enabled (default), the provider will warn when mutually-exclusive
|
|
816
826
|
* settings are provided (e.g. both `deploymentId` and `resourceGroup`).
|
|
817
827
|
*/
|
|
818
|
-
warnOnAmbiguousConfig?: boolean;
|
|
828
|
+
readonly warnOnAmbiguousConfig?: boolean;
|
|
819
829
|
}
|
|
820
830
|
/**
|
|
821
831
|
* SAP AI Provider V2 interface.
|
|
@@ -843,7 +853,7 @@ interface SAPAIProviderSettings {
|
|
|
843
853
|
* const chatModel = provider.languageModel('gpt-4o');
|
|
844
854
|
* ```
|
|
845
855
|
*/
|
|
846
|
-
interface SAPAIProviderV2 {
|
|
856
|
+
interface SAPAIProviderV2 extends ProviderV2 {
|
|
847
857
|
/**
|
|
848
858
|
* Create a language model instance (V2).
|
|
849
859
|
* @param modelId - The SAP AI Core model identifier (e.g., 'gpt-4o', 'anthropic--claude-3.5-sonnet')
|
|
@@ -870,6 +880,21 @@ interface SAPAIProviderV2 {
|
|
|
870
880
|
* @returns Configured SAP AI embedding model instance (V2)
|
|
871
881
|
*/
|
|
872
882
|
embedding(modelId: SAPAIEmbeddingModelId, settings?: SAPAIEmbeddingSettings): SAPAIEmbeddingModelV2;
|
|
883
|
+
/**
|
|
884
|
+
* Image model stub for ProviderV2 interface compliance.
|
|
885
|
+
*
|
|
886
|
+
* SAP AI Core Orchestration Service does not currently support image generation.
|
|
887
|
+
* This method always throws a `NoSuchModelError` to indicate that image generation
|
|
888
|
+
* is not available through this provider.
|
|
889
|
+
* @param modelId - The image model identifier (not used)
|
|
890
|
+
* @throws {NoSuchModelError} Always throws - image generation is not supported
|
|
891
|
+
* @example
|
|
892
|
+
* ```typescript
|
|
893
|
+
* // This will always throw NoSuchModelError
|
|
894
|
+
* provider.imageModel('dall-e-3'); // throws NoSuchModelError
|
|
895
|
+
* ```
|
|
896
|
+
*/
|
|
897
|
+
imageModel(modelId: string): ImageModelV2;
|
|
873
898
|
/**
|
|
874
899
|
* Create a language model instance (V2).
|
|
875
900
|
*
|
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;
|
|
@@ -327,7 +337,7 @@ interface SAPAISettings {
|
|
|
327
337
|
* });
|
|
328
338
|
* ```
|
|
329
339
|
*/
|
|
330
|
-
filtering?: FilteringModule;
|
|
340
|
+
readonly filtering?: FilteringModule;
|
|
331
341
|
/**
|
|
332
342
|
* Grounding module configuration for document-based retrieval (RAG).
|
|
333
343
|
* Enables retrieval-augmented generation using SAP Document Grounding Service.
|
|
@@ -356,7 +366,7 @@ interface SAPAISettings {
|
|
|
356
366
|
* });
|
|
357
367
|
* ```
|
|
358
368
|
*/
|
|
359
|
-
grounding?: GroundingModule;
|
|
369
|
+
readonly grounding?: GroundingModule;
|
|
360
370
|
/**
|
|
361
371
|
* Whether to include assistant reasoning parts in the SAP prompt conversion.
|
|
362
372
|
*
|
|
@@ -370,7 +380,7 @@ interface SAPAISettings {
|
|
|
370
380
|
* const prodModel = provider('gpt-4o'); // includeReasoning defaults to false
|
|
371
381
|
* ```
|
|
372
382
|
*/
|
|
373
|
-
includeReasoning?: boolean;
|
|
383
|
+
readonly includeReasoning?: boolean;
|
|
374
384
|
/**
|
|
375
385
|
* Masking configuration for SAP AI Core orchestration.
|
|
376
386
|
* When provided, sensitive information in prompts can be anonymized or
|
|
@@ -392,22 +402,22 @@ interface SAPAISettings {
|
|
|
392
402
|
* });
|
|
393
403
|
* ```
|
|
394
404
|
*/
|
|
395
|
-
masking?: MaskingModule;
|
|
405
|
+
readonly masking?: MaskingModule;
|
|
396
406
|
/**
|
|
397
407
|
* Model generation parameters that control the output.
|
|
398
408
|
*/
|
|
399
|
-
modelParams?: {
|
|
409
|
+
readonly modelParams?: {
|
|
400
410
|
/**
|
|
401
411
|
* Frequency penalty between -2.0 and 2.0.
|
|
402
412
|
* Positive values penalize tokens based on their frequency.
|
|
403
413
|
* If not specified, the model's default is used (typically 0).
|
|
404
414
|
*/
|
|
405
|
-
frequencyPenalty?: number;
|
|
415
|
+
readonly frequencyPenalty?: number;
|
|
406
416
|
/**
|
|
407
417
|
* Maximum number of tokens to generate.
|
|
408
418
|
* Higher values allow for longer responses but increase latency and cost.
|
|
409
419
|
*/
|
|
410
|
-
maxTokens?: number;
|
|
420
|
+
readonly maxTokens?: number;
|
|
411
421
|
/**
|
|
412
422
|
* Number of completions to generate.
|
|
413
423
|
* Multiple completions provide alternative responses.
|
|
@@ -416,38 +426,38 @@ interface SAPAISettings {
|
|
|
416
426
|
* models, the parameter is silently omitted from the request.
|
|
417
427
|
* If not specified, typically defaults to 1 on the model side.
|
|
418
428
|
*/
|
|
419
|
-
n?: number;
|
|
429
|
+
readonly n?: number;
|
|
420
430
|
/**
|
|
421
431
|
* Whether to enable parallel tool calls.
|
|
422
432
|
* When enabled, the model can call multiple tools in parallel.
|
|
423
433
|
*
|
|
424
434
|
* Note: This uses the SAP/OpenAI-style key `parallel_tool_calls`.
|
|
425
435
|
*/
|
|
426
|
-
parallel_tool_calls?: boolean;
|
|
436
|
+
readonly parallel_tool_calls?: boolean;
|
|
427
437
|
/**
|
|
428
438
|
* Presence penalty between -2.0 and 2.0.
|
|
429
439
|
* Positive values penalize tokens that have appeared in the text.
|
|
430
440
|
* If not specified, the model's default is used (typically 0).
|
|
431
441
|
*/
|
|
432
|
-
presencePenalty?: number;
|
|
442
|
+
readonly presencePenalty?: number;
|
|
433
443
|
/**
|
|
434
444
|
* Sampling temperature between 0 and 2.
|
|
435
445
|
* Higher values make output more random, lower values more deterministic.
|
|
436
446
|
* If not specified, the model's default temperature is used.
|
|
437
447
|
*/
|
|
438
|
-
temperature?: number;
|
|
448
|
+
readonly temperature?: number;
|
|
439
449
|
/**
|
|
440
450
|
* Nucleus sampling parameter between 0 and 1.
|
|
441
451
|
* Controls diversity via cumulative probability cutoff.
|
|
442
452
|
* If not specified, the model's default topP is used (typically 1).
|
|
443
453
|
*/
|
|
444
|
-
topP?: number;
|
|
454
|
+
readonly topP?: number;
|
|
445
455
|
};
|
|
446
456
|
/**
|
|
447
457
|
* Specific version of the model to use.
|
|
448
458
|
* If not provided, the latest version will be used.
|
|
449
459
|
*/
|
|
450
|
-
modelVersion?: string;
|
|
460
|
+
readonly modelVersion?: string;
|
|
451
461
|
/**
|
|
452
462
|
* Response format for templating prompt (OpenAI-compatible)
|
|
453
463
|
* Allows specifying structured output formats
|
|
@@ -464,18 +474,18 @@ interface SAPAISettings {
|
|
|
464
474
|
* });
|
|
465
475
|
* ```
|
|
466
476
|
*/
|
|
467
|
-
responseFormat?: {
|
|
468
|
-
json_schema: {
|
|
469
|
-
description?: string;
|
|
470
|
-
name: string;
|
|
471
|
-
schema?: unknown;
|
|
472
|
-
strict?: boolean | null;
|
|
477
|
+
readonly responseFormat?: {
|
|
478
|
+
readonly json_schema: {
|
|
479
|
+
readonly description?: string;
|
|
480
|
+
readonly name: string;
|
|
481
|
+
readonly schema?: unknown;
|
|
482
|
+
readonly strict?: boolean | null;
|
|
473
483
|
};
|
|
474
|
-
type: "json_schema";
|
|
484
|
+
readonly type: "json_schema";
|
|
475
485
|
} | {
|
|
476
|
-
type: "json_object";
|
|
486
|
+
readonly type: "json_object";
|
|
477
487
|
} | {
|
|
478
|
-
type: "text";
|
|
488
|
+
readonly type: "text";
|
|
479
489
|
};
|
|
480
490
|
/**
|
|
481
491
|
* Tool definitions in SAP AI SDK format
|
|
@@ -508,7 +518,7 @@ interface SAPAISettings {
|
|
|
508
518
|
* });
|
|
509
519
|
* ```
|
|
510
520
|
*/
|
|
511
|
-
tools?: ChatCompletionTool[];
|
|
521
|
+
readonly tools?: ChatCompletionTool[];
|
|
512
522
|
/**
|
|
513
523
|
* Translation module configuration for input/output translation.
|
|
514
524
|
* Enables automatic translation using SAP Document Translation service.
|
|
@@ -532,7 +542,7 @@ interface SAPAISettings {
|
|
|
532
542
|
* });
|
|
533
543
|
* ```
|
|
534
544
|
*/
|
|
535
|
-
translation?: TranslationModule;
|
|
545
|
+
readonly translation?: TranslationModule;
|
|
536
546
|
}
|
|
537
547
|
|
|
538
548
|
/**
|
|
@@ -553,9 +563,9 @@ interface SAPAISettings {
|
|
|
553
563
|
* @internal
|
|
554
564
|
*/
|
|
555
565
|
interface SAPAIConfig {
|
|
556
|
-
deploymentConfig: DeploymentIdConfig | ResourceGroupConfig;
|
|
557
|
-
destination?: HttpDestinationOrFetchOptions;
|
|
558
|
-
provider: string;
|
|
566
|
+
readonly deploymentConfig: DeploymentIdConfig | ResourceGroupConfig;
|
|
567
|
+
readonly destination?: HttpDestinationOrFetchOptions;
|
|
568
|
+
readonly provider: string;
|
|
559
569
|
}
|
|
560
570
|
/**
|
|
561
571
|
* SAP AI Language Model V2 implementation.
|
|
@@ -767,7 +777,7 @@ interface SAPAIProviderSettings {
|
|
|
767
777
|
* Default model settings applied to every model instance created by this provider.
|
|
768
778
|
* Per-call settings provided to the model will override these.
|
|
769
779
|
*/
|
|
770
|
-
defaultSettings?: SAPAISettings;
|
|
780
|
+
readonly defaultSettings?: SAPAISettings;
|
|
771
781
|
/**
|
|
772
782
|
* SAP AI Core deployment ID.
|
|
773
783
|
*
|
|
@@ -778,7 +788,7 @@ interface SAPAIProviderSettings {
|
|
|
778
788
|
* deploymentId: 'd65d81e7c077e583'
|
|
779
789
|
* ```
|
|
780
790
|
*/
|
|
781
|
-
deploymentId?: string;
|
|
791
|
+
readonly deploymentId?: string;
|
|
782
792
|
/**
|
|
783
793
|
* Custom destination configuration for SAP AI Core.
|
|
784
794
|
*
|
|
@@ -793,7 +803,7 @@ interface SAPAIProviderSettings {
|
|
|
793
803
|
* }
|
|
794
804
|
* ```
|
|
795
805
|
*/
|
|
796
|
-
destination?: HttpDestinationOrFetchOptions;
|
|
806
|
+
readonly destination?: HttpDestinationOrFetchOptions;
|
|
797
807
|
/**
|
|
798
808
|
* SAP AI Core resource group.
|
|
799
809
|
*
|
|
@@ -808,14 +818,14 @@ interface SAPAIProviderSettings {
|
|
|
808
818
|
* resourceGroup: 'development' // Development environment
|
|
809
819
|
* ```
|
|
810
820
|
*/
|
|
811
|
-
resourceGroup?: string;
|
|
821
|
+
readonly resourceGroup?: string;
|
|
812
822
|
/**
|
|
813
823
|
* Whether to emit warnings for ambiguous configurations.
|
|
814
824
|
*
|
|
815
825
|
* When enabled (default), the provider will warn when mutually-exclusive
|
|
816
826
|
* settings are provided (e.g. both `deploymentId` and `resourceGroup`).
|
|
817
827
|
*/
|
|
818
|
-
warnOnAmbiguousConfig?: boolean;
|
|
828
|
+
readonly warnOnAmbiguousConfig?: boolean;
|
|
819
829
|
}
|
|
820
830
|
/**
|
|
821
831
|
* SAP AI Provider V2 interface.
|
|
@@ -843,7 +853,7 @@ interface SAPAIProviderSettings {
|
|
|
843
853
|
* const chatModel = provider.languageModel('gpt-4o');
|
|
844
854
|
* ```
|
|
845
855
|
*/
|
|
846
|
-
interface SAPAIProviderV2 {
|
|
856
|
+
interface SAPAIProviderV2 extends ProviderV2 {
|
|
847
857
|
/**
|
|
848
858
|
* Create a language model instance (V2).
|
|
849
859
|
* @param modelId - The SAP AI Core model identifier (e.g., 'gpt-4o', 'anthropic--claude-3.5-sonnet')
|
|
@@ -870,6 +880,21 @@ interface SAPAIProviderV2 {
|
|
|
870
880
|
* @returns Configured SAP AI embedding model instance (V2)
|
|
871
881
|
*/
|
|
872
882
|
embedding(modelId: SAPAIEmbeddingModelId, settings?: SAPAIEmbeddingSettings): SAPAIEmbeddingModelV2;
|
|
883
|
+
/**
|
|
884
|
+
* Image model stub for ProviderV2 interface compliance.
|
|
885
|
+
*
|
|
886
|
+
* SAP AI Core Orchestration Service does not currently support image generation.
|
|
887
|
+
* This method always throws a `NoSuchModelError` to indicate that image generation
|
|
888
|
+
* is not available through this provider.
|
|
889
|
+
* @param modelId - The image model identifier (not used)
|
|
890
|
+
* @throws {NoSuchModelError} Always throws - image generation is not supported
|
|
891
|
+
* @example
|
|
892
|
+
* ```typescript
|
|
893
|
+
* // This will always throw NoSuchModelError
|
|
894
|
+
* provider.imageModel('dall-e-3'); // throws NoSuchModelError
|
|
895
|
+
* ```
|
|
896
|
+
*/
|
|
897
|
+
imageModel(modelId: string): ImageModelV2;
|
|
873
898
|
/**
|
|
874
899
|
* Create a language model instance (V2).
|
|
875
900
|
*
|
package/dist/index.js
CHANGED
|
@@ -30381,6 +30381,7 @@ var SAPAIEmbeddingModel = class {
|
|
|
30381
30381
|
* the SAP AI SDK's OrchestrationEmbeddingClient.
|
|
30382
30382
|
* @param options - The embedding request options
|
|
30383
30383
|
* @returns Promise resolving to embeddings and usage information
|
|
30384
|
+
* @since 1.0.0
|
|
30384
30385
|
* @example
|
|
30385
30386
|
* ```typescript
|
|
30386
30387
|
* const result = await model.doEmbed({
|
|
@@ -30523,6 +30524,7 @@ var SAPAIEmbeddingModelV2 = class {
|
|
|
30523
30524
|
* @param options.providerOptions - Optional provider-specific options
|
|
30524
30525
|
* @param options.headers - Optional HTTP headers
|
|
30525
30526
|
* @returns Promise resolving to embeddings and metadata in V2 format
|
|
30527
|
+
* @since 1.0.0
|
|
30526
30528
|
*/
|
|
30527
30529
|
async doEmbed(options) {
|
|
30528
30530
|
const v3Options = {
|
|
@@ -30563,6 +30565,9 @@ function castProviderMetadataV3ToV2(v3Metadata) {
|
|
|
30563
30565
|
return v3Metadata;
|
|
30564
30566
|
}
|
|
30565
30567
|
|
|
30568
|
+
// src/sap-ai-provider-v2.ts
|
|
30569
|
+
import { NoSuchModelError as NoSuchModelError2 } from "@ai-sdk/provider";
|
|
30570
|
+
|
|
30566
30571
|
// src/sap-ai-language-model.ts
|
|
30567
30572
|
import { parseProviderOptions as parseProviderOptions2 } from "@ai-sdk/provider-utils";
|
|
30568
30573
|
import {
|
|
@@ -31449,21 +31454,26 @@ var SAPAILanguageModel = class {
|
|
|
31449
31454
|
type: "unsupported"
|
|
31450
31455
|
});
|
|
31451
31456
|
}
|
|
31457
|
+
let responseFormat;
|
|
31452
31458
|
if (options.responseFormat?.type === "json") {
|
|
31459
|
+
responseFormat = options.responseFormat.schema ? {
|
|
31460
|
+
json_schema: {
|
|
31461
|
+
description: options.responseFormat.description,
|
|
31462
|
+
name: options.responseFormat.name ?? "response",
|
|
31463
|
+
schema: options.responseFormat.schema,
|
|
31464
|
+
strict: null
|
|
31465
|
+
},
|
|
31466
|
+
type: "json_schema"
|
|
31467
|
+
} : { type: "json_object" };
|
|
31468
|
+
} else if (this.settings.responseFormat) {
|
|
31469
|
+
responseFormat = this.settings.responseFormat;
|
|
31470
|
+
}
|
|
31471
|
+
if (responseFormat && responseFormat.type !== "text") {
|
|
31453
31472
|
warnings.push({
|
|
31454
31473
|
message: "responseFormat JSON mode is forwarded to the underlying model; support and schema adherence depend on the model/deployment.",
|
|
31455
31474
|
type: "other"
|
|
31456
31475
|
});
|
|
31457
31476
|
}
|
|
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
31477
|
const orchestrationConfig = {
|
|
31468
31478
|
promptTemplating: {
|
|
31469
31479
|
model: {
|
|
@@ -31789,6 +31799,13 @@ function createSAPAIProvider(options = {}) {
|
|
|
31789
31799
|
provider.chat = createModel;
|
|
31790
31800
|
provider.embedding = createEmbeddingModel;
|
|
31791
31801
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
31802
|
+
provider.imageModel = (modelId) => {
|
|
31803
|
+
throw new NoSuchModelError2({
|
|
31804
|
+
message: `SAP AI Core Orchestration Service does not support image generation. Model '${modelId}' is not available.`,
|
|
31805
|
+
modelId,
|
|
31806
|
+
modelType: "imageModel"
|
|
31807
|
+
});
|
|
31808
|
+
};
|
|
31792
31809
|
return provider;
|
|
31793
31810
|
}
|
|
31794
31811
|
var sapai = createSAPAIProvider();
|