@ai-sdk/provider 2.0.0-canary.1 → 2.0.0-canary.11
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/CHANGELOG.md +102 -0
- package/dist/index.d.mts +984 -791
- package/dist/index.d.ts +984 -791
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
@@ -1,11 +1,65 @@
|
|
1
1
|
import { JSONSchema7 } from 'json-schema';
|
2
2
|
export { JSONSchema7, JSONSchema7Definition } from 'json-schema';
|
3
3
|
|
4
|
+
type SharedV2Headers = Record<string, string>;
|
5
|
+
|
6
|
+
type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
|
7
|
+
type JSONObject = {
|
8
|
+
[key: string]: JSONValue;
|
9
|
+
};
|
10
|
+
type JSONArray = JSONValue[];
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Additional provider-specific metadata.
|
14
|
+
* Metadata are additional outputs from the provider.
|
15
|
+
* They are passed through to the provider from the AI SDK
|
16
|
+
* and enable provider-specific functionality
|
17
|
+
* that can be fully encapsulated in the provider.
|
18
|
+
*
|
19
|
+
* This enables us to quickly ship provider-specific functionality
|
20
|
+
* without affecting the core AI SDK.
|
21
|
+
*
|
22
|
+
* The outer record is keyed by the provider name, and the inner
|
23
|
+
* record is keyed by the provider-specific metadata key.
|
24
|
+
*
|
25
|
+
* ```ts
|
26
|
+
* {
|
27
|
+
* "anthropic": {
|
28
|
+
* "cacheControl": { "type": "ephemeral" }
|
29
|
+
* }
|
30
|
+
* }
|
31
|
+
* ```
|
32
|
+
*/
|
33
|
+
type SharedV2ProviderMetadata = Record<string, Record<string, JSONValue>>;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Additional provider-specific options.
|
37
|
+
* Options are additional input to the provider.
|
38
|
+
* They are passed through to the provider from the AI SDK
|
39
|
+
* and enable provider-specific functionality
|
40
|
+
* that can be fully encapsulated in the provider.
|
41
|
+
*
|
42
|
+
* This enables us to quickly ship provider-specific functionality
|
43
|
+
* without affecting the core AI SDK.
|
44
|
+
*
|
45
|
+
* The outer record is keyed by the provider name, and the inner
|
46
|
+
* record is keyed by the provider-specific metadata key.
|
47
|
+
*
|
48
|
+
* ```ts
|
49
|
+
* {
|
50
|
+
* "anthropic": {
|
51
|
+
* "cacheControl": { "type": "ephemeral" }
|
52
|
+
* }
|
53
|
+
* }
|
54
|
+
* ```
|
55
|
+
*/
|
56
|
+
type SharedV2ProviderOptions = Record<string, Record<string, JSONValue>>;
|
57
|
+
|
4
58
|
/**
|
5
59
|
An embedding is a vector, i.e. an array of numbers.
|
6
60
|
It is e.g. used to represent a text as a vector of word embeddings.
|
7
61
|
*/
|
8
|
-
type
|
62
|
+
type EmbeddingModelV2Embedding = Array<number>;
|
9
63
|
|
10
64
|
/**
|
11
65
|
Specification for an embedding model that implements the embedding model
|
@@ -15,7 +69,7 @@ VALUE is the type of the values that the model can embed.
|
|
15
69
|
This will allow us to go beyond text embeddings in the future,
|
16
70
|
e.g. to support image embeddings
|
17
71
|
*/
|
18
|
-
type
|
72
|
+
type EmbeddingModelV2<VALUE> = {
|
19
73
|
/**
|
20
74
|
The embedding model must specify which embedding model interface
|
21
75
|
version it implements. This will allow us to evolve the embedding
|
@@ -23,7 +77,7 @@ type EmbeddingModelV1<VALUE> = {
|
|
23
77
|
implementation versions can be handled as a discriminated union
|
24
78
|
on our side.
|
25
79
|
*/
|
26
|
-
readonly specificationVersion: '
|
80
|
+
readonly specificationVersion: 'v2';
|
27
81
|
/**
|
28
82
|
Name of the provider for logging purposes.
|
29
83
|
*/
|
@@ -34,12 +88,14 @@ type EmbeddingModelV1<VALUE> = {
|
|
34
88
|
readonly modelId: string;
|
35
89
|
/**
|
36
90
|
Limit of how many embeddings can be generated in a single API call.
|
91
|
+
|
92
|
+
Use Infinity for models that do not have a limit.
|
37
93
|
*/
|
38
|
-
readonly maxEmbeddingsPerCall: number | undefined;
|
94
|
+
readonly maxEmbeddingsPerCall: PromiseLike<number | undefined> | number | undefined;
|
39
95
|
/**
|
40
96
|
True if the model can handle multiple embedding calls in parallel.
|
41
97
|
*/
|
42
|
-
readonly supportsParallelCalls: boolean;
|
98
|
+
readonly supportsParallelCalls: PromiseLike<boolean> | boolean;
|
43
99
|
/**
|
44
100
|
Generates a list of embeddings for the given input text.
|
45
101
|
|
@@ -56,6 +112,12 @@ type EmbeddingModelV1<VALUE> = {
|
|
56
112
|
*/
|
57
113
|
abortSignal?: AbortSignal;
|
58
114
|
/**
|
115
|
+
Additional provider-specific options. They are passed through
|
116
|
+
to the provider from the AI SDK and enable provider-specific
|
117
|
+
functionality that can be fully encapsulated in the provider.
|
118
|
+
*/
|
119
|
+
providerOptions?: SharedV2ProviderOptions;
|
120
|
+
/**
|
59
121
|
Additional HTTP headers to be sent with the request.
|
60
122
|
Only applicable for HTTP-based providers.
|
61
123
|
*/
|
@@ -64,7 +126,7 @@ type EmbeddingModelV1<VALUE> = {
|
|
64
126
|
/**
|
65
127
|
Generated embeddings. They are in the same order as the input values.
|
66
128
|
*/
|
67
|
-
embeddings: Array<
|
129
|
+
embeddings: Array<EmbeddingModelV2Embedding>;
|
68
130
|
/**
|
69
131
|
Token usage. We only have input tokens for embeddings.
|
70
132
|
*/
|
@@ -72,13 +134,17 @@ type EmbeddingModelV1<VALUE> = {
|
|
72
134
|
tokens: number;
|
73
135
|
};
|
74
136
|
/**
|
75
|
-
Optional
|
137
|
+
Optional response information for debugging purposes.
|
76
138
|
*/
|
77
|
-
|
139
|
+
response?: {
|
78
140
|
/**
|
79
141
|
Response headers.
|
80
142
|
*/
|
81
|
-
headers?:
|
143
|
+
headers?: SharedV2Headers;
|
144
|
+
/**
|
145
|
+
The response body.
|
146
|
+
*/
|
147
|
+
body?: unknown;
|
82
148
|
};
|
83
149
|
}>;
|
84
150
|
};
|
@@ -305,13 +371,7 @@ declare class UnsupportedFunctionalityError extends AISDKError {
|
|
305
371
|
static isInstance(error: unknown): error is UnsupportedFunctionalityError;
|
306
372
|
}
|
307
373
|
|
308
|
-
type
|
309
|
-
type JSONObject = {
|
310
|
-
[key: string]: JSONValue;
|
311
|
-
};
|
312
|
-
type JSONArray = JSONValue[];
|
313
|
-
|
314
|
-
type ImageModelV1CallOptions = {
|
374
|
+
type ImageModelV2CallOptions = {
|
315
375
|
/**
|
316
376
|
Prompt for the image generation.
|
317
377
|
*/
|
@@ -367,9 +427,9 @@ type ImageModelV1CallOptions = {
|
|
367
427
|
Warning from the model provider for this call. The call will proceed, but e.g.
|
368
428
|
some settings might not be supported, which can lead to suboptimal results.
|
369
429
|
*/
|
370
|
-
type
|
430
|
+
type ImageModelV2CallWarning = {
|
371
431
|
type: 'unsupported-setting';
|
372
|
-
setting: keyof
|
432
|
+
setting: keyof ImageModelV2CallOptions;
|
373
433
|
details?: string;
|
374
434
|
} | {
|
375
435
|
type: 'other';
|
@@ -379,7 +439,7 @@ type ImageModelV1CallWarning = {
|
|
379
439
|
/**
|
380
440
|
Image generation model specification version 1.
|
381
441
|
*/
|
382
|
-
type
|
442
|
+
type ImageModelV2 = {
|
383
443
|
/**
|
384
444
|
The image model must specify which image model interface
|
385
445
|
version it implements. This will allow us to evolve the image
|
@@ -404,7 +464,7 @@ type ImageModelV1 = {
|
|
404
464
|
/**
|
405
465
|
Generates an array of images.
|
406
466
|
*/
|
407
|
-
doGenerate(options:
|
467
|
+
doGenerate(options: ImageModelV2CallOptions): PromiseLike<{
|
408
468
|
/**
|
409
469
|
Generated images as base64 encoded strings or binary data.
|
410
470
|
The images should be returned without any unnecessary conversion.
|
@@ -416,7 +476,7 @@ type ImageModelV1 = {
|
|
416
476
|
/**
|
417
477
|
Warnings for the call, e.g. unsupported settings.
|
418
478
|
*/
|
419
|
-
warnings: Array<
|
479
|
+
warnings: Array<ImageModelV2CallWarning>;
|
420
480
|
/**
|
421
481
|
Response information for telemetry and debugging purposes.
|
422
482
|
*/
|
@@ -441,138 +501,13 @@ declare function isJSONValue(value: unknown): value is JSONValue;
|
|
441
501
|
declare function isJSONArray(value: unknown): value is JSONArray;
|
442
502
|
declare function isJSONObject(value: unknown): value is JSONObject;
|
443
503
|
|
444
|
-
/**
|
445
|
-
* Additional provider-specific metadata. They are passed through
|
446
|
-
* to the provider from the AI SDK and enable provider-specific
|
447
|
-
* functionality that can be fully encapsulated in the provider.
|
448
|
-
*
|
449
|
-
* This enables us to quickly ship provider-specific functionality
|
450
|
-
* without affecting the core AI SDK.
|
451
|
-
*
|
452
|
-
* The outer record is keyed by the provider name, and the inner
|
453
|
-
* record is keyed by the provider-specific metadata key.
|
454
|
-
*
|
455
|
-
* ```ts
|
456
|
-
* {
|
457
|
-
* "anthropic": {
|
458
|
-
* "cacheControl": { "type": "ephemeral" }
|
459
|
-
* }
|
460
|
-
* }
|
461
|
-
* ```
|
462
|
-
*/
|
463
|
-
type LanguageModelV1ProviderMetadata = Record<string, Record<string, JSONValue>>;
|
464
|
-
|
465
|
-
/**
|
466
|
-
* A source that has been used as input to generate the response.
|
467
|
-
*/
|
468
|
-
type LanguageModelV1Source = {
|
469
|
-
/**
|
470
|
-
* A URL source. This is return by web search RAG models.
|
471
|
-
*/
|
472
|
-
sourceType: 'url';
|
473
|
-
/**
|
474
|
-
* The ID of the source.
|
475
|
-
*/
|
476
|
-
id: string;
|
477
|
-
/**
|
478
|
-
* The URL of the source.
|
479
|
-
*/
|
480
|
-
url: string;
|
481
|
-
/**
|
482
|
-
* The title of the source.
|
483
|
-
*/
|
484
|
-
title?: string;
|
485
|
-
/**
|
486
|
-
* Additional provider metadata for the source.
|
487
|
-
*/
|
488
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
489
|
-
};
|
490
|
-
|
491
|
-
type LanguageModelV1CallSettings = {
|
492
|
-
/**
|
493
|
-
Maximum number of tokens to generate.
|
494
|
-
*/
|
495
|
-
maxTokens?: number;
|
496
|
-
/**
|
497
|
-
Temperature setting.
|
498
|
-
|
499
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
500
|
-
*/
|
501
|
-
temperature?: number;
|
502
|
-
/**
|
503
|
-
Stop sequences.
|
504
|
-
If set, the model will stop generating text when one of the stop sequences is generated.
|
505
|
-
Providers may have limits on the number of stop sequences.
|
506
|
-
*/
|
507
|
-
stopSequences?: string[];
|
508
|
-
/**
|
509
|
-
Nucleus sampling.
|
510
|
-
|
511
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
512
|
-
*/
|
513
|
-
topP?: number;
|
514
|
-
/**
|
515
|
-
Only sample from the top K options for each subsequent token.
|
516
|
-
|
517
|
-
Used to remove "long tail" low probability responses.
|
518
|
-
Recommended for advanced use cases only. You usually only need to use temperature.
|
519
|
-
*/
|
520
|
-
topK?: number;
|
521
|
-
/**
|
522
|
-
Presence penalty setting. It affects the likelihood of the model to
|
523
|
-
repeat information that is already in the prompt.
|
524
|
-
*/
|
525
|
-
presencePenalty?: number;
|
526
|
-
/**
|
527
|
-
Frequency penalty setting. It affects the likelihood of the model
|
528
|
-
to repeatedly use the same words or phrases.
|
529
|
-
*/
|
530
|
-
frequencyPenalty?: number;
|
531
|
-
/**
|
532
|
-
Response format. The output can either be text or JSON. Default is text.
|
533
|
-
|
534
|
-
If JSON is selected, a schema can optionally be provided to guide the LLM.
|
535
|
-
*/
|
536
|
-
responseFormat?: {
|
537
|
-
type: 'text';
|
538
|
-
} | {
|
539
|
-
type: 'json';
|
540
|
-
/**
|
541
|
-
* JSON schema that the generated output should conform to.
|
542
|
-
*/
|
543
|
-
schema?: JSONSchema7;
|
544
|
-
/**
|
545
|
-
* Name of output that should be generated. Used by some providers for additional LLM guidance.
|
546
|
-
*/
|
547
|
-
name?: string;
|
548
|
-
/**
|
549
|
-
* Description of the output that should be generated. Used by some providers for additional LLM guidance.
|
550
|
-
*/
|
551
|
-
description?: string;
|
552
|
-
};
|
553
|
-
/**
|
554
|
-
The seed (integer) to use for random sampling. If set and supported
|
555
|
-
by the model, calls will generate deterministic results.
|
556
|
-
*/
|
557
|
-
seed?: number;
|
558
|
-
/**
|
559
|
-
Abort signal for cancelling the operation.
|
560
|
-
*/
|
561
|
-
abortSignal?: AbortSignal;
|
562
|
-
/**
|
563
|
-
Additional HTTP headers to be sent with the request.
|
564
|
-
Only applicable for HTTP-based providers.
|
565
|
-
*/
|
566
|
-
headers?: Record<string, string | undefined>;
|
567
|
-
};
|
568
|
-
|
569
504
|
/**
|
570
505
|
A tool has a name, a description, and a set of parameters.
|
571
506
|
|
572
507
|
Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
573
508
|
map the user-facing tool definitions to this format.
|
574
509
|
*/
|
575
|
-
type
|
510
|
+
type LanguageModelV2FunctionTool = {
|
576
511
|
/**
|
577
512
|
The type of the tool (always 'function').
|
578
513
|
*/
|
@@ -593,6 +528,11 @@ type LanguageModelV1FunctionTool = {
|
|
593
528
|
parameters: JSONSchema7;
|
594
529
|
};
|
595
530
|
|
531
|
+
/**
|
532
|
+
Data content. Can be a Uint8Array, base64 encoded data as a string or a URL.
|
533
|
+
*/
|
534
|
+
type LanguageModelV2DataContent = Uint8Array | string | URL;
|
535
|
+
|
596
536
|
/**
|
597
537
|
A prompt is a list of messages.
|
598
538
|
|
@@ -602,128 +542,92 @@ tool calls. The validation happens at runtime.
|
|
602
542
|
Note: This is not a user-facing prompt. The AI SDK methods will map the
|
603
543
|
user-facing prompt types such as chat or instruction prompts to this format.
|
604
544
|
*/
|
605
|
-
type
|
606
|
-
type
|
545
|
+
type LanguageModelV2Prompt = Array<LanguageModelV2Message>;
|
546
|
+
type LanguageModelV2Message = ({
|
607
547
|
role: 'system';
|
608
548
|
content: string;
|
609
549
|
} | {
|
610
550
|
role: 'user';
|
611
|
-
content: Array<
|
551
|
+
content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart>;
|
612
552
|
} | {
|
613
553
|
role: 'assistant';
|
614
|
-
content: Array<
|
554
|
+
content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart | LanguageModelV2ReasoningPart | LanguageModelV2ToolCallPart>;
|
615
555
|
} | {
|
616
556
|
role: 'tool';
|
617
|
-
content: Array<
|
557
|
+
content: Array<LanguageModelV2ToolResultPart>;
|
618
558
|
}) & {
|
619
559
|
/**
|
620
|
-
* Additional provider-specific
|
560
|
+
* Additional provider-specific options. They are passed through
|
621
561
|
* to the provider from the AI SDK and enable provider-specific
|
622
562
|
* functionality that can be fully encapsulated in the provider.
|
623
563
|
*/
|
624
|
-
|
564
|
+
providerOptions?: SharedV2ProviderOptions;
|
625
565
|
};
|
626
566
|
/**
|
627
567
|
Text content part of a prompt. It contains a string of text.
|
628
568
|
*/
|
629
|
-
interface
|
569
|
+
interface LanguageModelV2TextPart {
|
630
570
|
type: 'text';
|
631
571
|
/**
|
632
572
|
The text content.
|
633
573
|
*/
|
634
574
|
text: string;
|
635
575
|
/**
|
636
|
-
* Additional provider-specific
|
576
|
+
* Additional provider-specific options. They are passed through
|
637
577
|
* to the provider from the AI SDK and enable provider-specific
|
638
578
|
* functionality that can be fully encapsulated in the provider.
|
639
579
|
*/
|
640
|
-
|
580
|
+
providerOptions?: SharedV2ProviderOptions;
|
641
581
|
}
|
642
582
|
/**
|
643
583
|
Reasoning content part of a prompt. It contains a string of reasoning text.
|
644
584
|
*/
|
645
|
-
interface
|
585
|
+
interface LanguageModelV2ReasoningPart {
|
646
586
|
type: 'reasoning';
|
647
587
|
/**
|
648
588
|
The reasoning text.
|
649
589
|
*/
|
650
590
|
text: string;
|
651
591
|
/**
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
/**
|
656
|
-
Additional provider-specific metadata. They are passed through
|
657
|
-
to the provider from the AI SDK and enable provider-specific
|
658
|
-
functionality that can be fully encapsulated in the provider.
|
592
|
+
* Additional provider-specific options. They are passed through
|
593
|
+
* to the provider from the AI SDK and enable provider-specific
|
594
|
+
* functionality that can be fully encapsulated in the provider.
|
659
595
|
*/
|
660
|
-
|
596
|
+
providerOptions?: SharedV2ProviderOptions;
|
661
597
|
}
|
662
598
|
/**
|
663
|
-
|
599
|
+
File content part of a prompt. It contains a file.
|
664
600
|
*/
|
665
|
-
interface
|
666
|
-
type: '
|
601
|
+
interface LanguageModelV2FilePart {
|
602
|
+
type: 'file';
|
667
603
|
/**
|
668
|
-
|
604
|
+
* Optional filename of the file.
|
669
605
|
*/
|
670
|
-
|
606
|
+
filename?: string;
|
671
607
|
/**
|
672
|
-
|
673
|
-
|
674
|
-
|
608
|
+
File data. Can be a Uint8Array, base64 encoded data as a string or a URL.
|
609
|
+
*/
|
610
|
+
data: LanguageModelV2DataContent;
|
611
|
+
/**
|
612
|
+
IANA media type of the file.
|
613
|
+
|
614
|
+
Can support wildcards, e.g. `image/*` (in which case the provider needs to take appropriate action).
|
615
|
+
|
616
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
675
617
|
*/
|
676
|
-
|
618
|
+
mediaType: string;
|
619
|
+
/**
|
620
|
+
* Additional provider-specific options. They are passed through
|
621
|
+
* to the provider from the AI SDK and enable provider-specific
|
622
|
+
* functionality that can be fully encapsulated in the provider.
|
623
|
+
*/
|
624
|
+
providerOptions?: SharedV2ProviderOptions;
|
677
625
|
}
|
678
626
|
/**
|
679
|
-
|
627
|
+
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
680
628
|
*/
|
681
|
-
interface
|
682
|
-
type: '
|
683
|
-
/**
|
684
|
-
Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
|
685
|
-
*/
|
686
|
-
image: Uint8Array | URL;
|
687
|
-
/**
|
688
|
-
Optional mime type of the image.
|
689
|
-
*/
|
690
|
-
mimeType?: string;
|
691
|
-
/**
|
692
|
-
* Additional provider-specific metadata. They are passed through
|
693
|
-
* to the provider from the AI SDK and enable provider-specific
|
694
|
-
* functionality that can be fully encapsulated in the provider.
|
695
|
-
*/
|
696
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
697
|
-
}
|
698
|
-
/**
|
699
|
-
File content part of a prompt. It contains a file.
|
700
|
-
*/
|
701
|
-
interface LanguageModelV1FilePart {
|
702
|
-
type: 'file';
|
703
|
-
/**
|
704
|
-
* Optional filename of the file.
|
705
|
-
*/
|
706
|
-
filename?: string;
|
707
|
-
/**
|
708
|
-
File data as base64 encoded string or as a URL.
|
709
|
-
*/
|
710
|
-
data: string | URL;
|
711
|
-
/**
|
712
|
-
Mime type of the file.
|
713
|
-
*/
|
714
|
-
mimeType: string;
|
715
|
-
/**
|
716
|
-
* Additional provider-specific metadata. They are passed through
|
717
|
-
* to the provider from the AI SDK and enable provider-specific
|
718
|
-
* functionality that can be fully encapsulated in the provider.
|
719
|
-
*/
|
720
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
721
|
-
}
|
722
|
-
/**
|
723
|
-
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
724
|
-
*/
|
725
|
-
interface LanguageModelV1ToolCallPart {
|
726
|
-
type: 'tool-call';
|
629
|
+
interface LanguageModelV2ToolCallPart {
|
630
|
+
type: 'tool-call';
|
727
631
|
/**
|
728
632
|
ID of the tool call. This ID is used to match the tool call with the tool result.
|
729
633
|
*/
|
@@ -737,16 +641,16 @@ interface LanguageModelV1ToolCallPart {
|
|
737
641
|
*/
|
738
642
|
args: unknown;
|
739
643
|
/**
|
740
|
-
* Additional provider-specific
|
644
|
+
* Additional provider-specific options. They are passed through
|
741
645
|
* to the provider from the AI SDK and enable provider-specific
|
742
646
|
* functionality that can be fully encapsulated in the provider.
|
743
647
|
*/
|
744
|
-
|
648
|
+
providerOptions?: SharedV2ProviderOptions;
|
745
649
|
}
|
746
650
|
/**
|
747
651
|
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
748
652
|
*/
|
749
|
-
interface
|
653
|
+
interface LanguageModelV2ToolResultPart {
|
750
654
|
type: 'tool-result';
|
751
655
|
/**
|
752
656
|
ID of the tool call that this result is associated with.
|
@@ -781,22 +685,24 @@ base-64 encoded image data
|
|
781
685
|
*/
|
782
686
|
data: string;
|
783
687
|
/**
|
784
|
-
|
688
|
+
IANA media type of the image.
|
689
|
+
|
690
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
785
691
|
*/
|
786
|
-
|
692
|
+
mediaType?: string;
|
787
693
|
}>;
|
788
694
|
/**
|
789
|
-
* Additional provider-specific
|
695
|
+
* Additional provider-specific options. They are passed through
|
790
696
|
* to the provider from the AI SDK and enable provider-specific
|
791
697
|
* functionality that can be fully encapsulated in the provider.
|
792
698
|
*/
|
793
|
-
|
699
|
+
providerOptions?: SharedV2ProviderOptions;
|
794
700
|
}
|
795
701
|
|
796
702
|
/**
|
797
703
|
The configuration of a tool that is defined by the provider.
|
798
704
|
*/
|
799
|
-
type
|
705
|
+
type LanguageModelV2ProviderDefinedTool = {
|
800
706
|
/**
|
801
707
|
The type of the tool (always 'provider-defined').
|
802
708
|
*/
|
@@ -815,7 +721,7 @@ type LanguageModelV1ProviderDefinedTool = {
|
|
815
721
|
args: Record<string, unknown>;
|
816
722
|
};
|
817
723
|
|
818
|
-
type
|
724
|
+
type LanguageModelV2ToolChoice = {
|
819
725
|
type: 'auto';
|
820
726
|
} | {
|
821
727
|
type: 'none';
|
@@ -826,38 +732,64 @@ type LanguageModelV1ToolChoice = {
|
|
826
732
|
toolName: string;
|
827
733
|
};
|
828
734
|
|
829
|
-
type
|
735
|
+
type LanguageModelV2CallOptions = {
|
830
736
|
/**
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
737
|
+
A language mode prompt is a standardized prompt type.
|
738
|
+
|
739
|
+
Note: This is **not** the user-facing prompt. The AI SDK methods will map the
|
740
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
741
|
+
That approach allows us to evolve the user facing prompts without breaking
|
742
|
+
the language model interface.
|
835
743
|
*/
|
836
|
-
|
744
|
+
prompt: LanguageModelV2Prompt;
|
837
745
|
/**
|
838
|
-
|
839
|
-
support provider-independent streaming and generation of structured objects.
|
840
|
-
The model can take this information and e.g. configure json mode, the correct
|
841
|
-
low level grammar, etc. It can also be used to optimize the efficiency of the
|
842
|
-
streaming, e.g. tool-delta stream parts are only needed in the
|
843
|
-
object-tool mode.
|
844
|
-
|
845
|
-
@deprecated mode will be removed in v2.
|
846
|
-
All necessary settings will be directly supported through the call settings,
|
847
|
-
in particular responseFormat, toolChoice, and tools.
|
746
|
+
Maximum number of tokens to generate.
|
848
747
|
*/
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
748
|
+
maxOutputTokens?: number;
|
749
|
+
/**
|
750
|
+
Temperature setting.
|
751
|
+
|
752
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
753
|
+
*/
|
754
|
+
temperature?: number;
|
755
|
+
/**
|
756
|
+
Stop sequences.
|
757
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
758
|
+
Providers may have limits on the number of stop sequences.
|
759
|
+
*/
|
760
|
+
stopSequences?: string[];
|
761
|
+
/**
|
762
|
+
Nucleus sampling.
|
763
|
+
|
764
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
765
|
+
*/
|
766
|
+
topP?: number;
|
767
|
+
/**
|
768
|
+
Only sample from the top K options for each subsequent token.
|
769
|
+
|
770
|
+
Used to remove "long tail" low probability responses.
|
771
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
772
|
+
*/
|
773
|
+
topK?: number;
|
774
|
+
/**
|
775
|
+
Presence penalty setting. It affects the likelihood of the model to
|
776
|
+
repeat information that is already in the prompt.
|
777
|
+
*/
|
778
|
+
presencePenalty?: number;
|
779
|
+
/**
|
780
|
+
Frequency penalty setting. It affects the likelihood of the model
|
781
|
+
to repeatedly use the same words or phrases.
|
782
|
+
*/
|
783
|
+
frequencyPenalty?: number;
|
784
|
+
/**
|
785
|
+
Response format. The output can either be text or JSON. Default is text.
|
786
|
+
|
787
|
+
If JSON is selected, a schema can optionally be provided to guide the LLM.
|
788
|
+
*/
|
789
|
+
responseFormat?: {
|
790
|
+
type: 'text';
|
859
791
|
} | {
|
860
|
-
type: '
|
792
|
+
type: 'json';
|
861
793
|
/**
|
862
794
|
* JSON schema that the generated output should conform to.
|
863
795
|
*/
|
@@ -870,38 +802,48 @@ Specifies how the tool should be selected. Defaults to 'auto'.
|
|
870
802
|
* Description of the output that should be generated. Used by some providers for additional LLM guidance.
|
871
803
|
*/
|
872
804
|
description?: string;
|
873
|
-
} | {
|
874
|
-
type: 'object-tool';
|
875
|
-
tool: LanguageModelV1FunctionTool;
|
876
805
|
};
|
877
806
|
/**
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
That approach allows us to evolve the user facing prompts without breaking
|
883
|
-
the language model interface.
|
884
|
-
*/
|
885
|
-
prompt: LanguageModelV1Prompt;
|
807
|
+
The seed (integer) to use for random sampling. If set and supported
|
808
|
+
by the model, calls will generate deterministic results.
|
809
|
+
*/
|
810
|
+
seed?: number;
|
886
811
|
/**
|
887
|
-
|
888
|
-
|
889
|
-
|
812
|
+
The tools that are available for the model.
|
813
|
+
*/
|
814
|
+
tools?: Array<LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool>;
|
815
|
+
/**
|
816
|
+
Specifies how the tool should be selected. Defaults to 'auto'.
|
817
|
+
*/
|
818
|
+
toolChoice?: LanguageModelV2ToolChoice;
|
819
|
+
/**
|
820
|
+
Abort signal for cancelling the operation.
|
821
|
+
*/
|
822
|
+
abortSignal?: AbortSignal;
|
823
|
+
/**
|
824
|
+
Additional HTTP headers to be sent with the request.
|
825
|
+
Only applicable for HTTP-based providers.
|
826
|
+
*/
|
827
|
+
headers?: Record<string, string | undefined>;
|
828
|
+
/**
|
829
|
+
* Additional provider-specific options. They are passed through
|
830
|
+
* to the provider from the AI SDK and enable provider-specific
|
831
|
+
* functionality that can be fully encapsulated in the provider.
|
890
832
|
*/
|
891
|
-
|
833
|
+
providerOptions?: SharedV2ProviderOptions;
|
892
834
|
};
|
893
835
|
|
894
836
|
/**
|
895
837
|
Warning from the model provider for this call. The call will proceed, but e.g.
|
896
838
|
some settings might not be supported, which can lead to suboptimal results.
|
897
839
|
*/
|
898
|
-
type
|
840
|
+
type LanguageModelV2CallWarning = {
|
899
841
|
type: 'unsupported-setting';
|
900
|
-
setting: keyof
|
842
|
+
setting: Omit<keyof LanguageModelV2CallOptions, 'prompt'>;
|
901
843
|
details?: string;
|
902
844
|
} | {
|
903
845
|
type: 'unsupported-tool';
|
904
|
-
tool:
|
846
|
+
tool: LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool;
|
905
847
|
details?: string;
|
906
848
|
} | {
|
907
849
|
type: 'other';
|
@@ -909,230 +851,247 @@ type LanguageModelV1CallWarning = {
|
|
909
851
|
};
|
910
852
|
|
911
853
|
/**
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
- `stop`: model generated stop sequence
|
916
|
-
- `length`: model generated maximum number of tokens
|
917
|
-
- `content-filter`: content filter violation stopped the model
|
918
|
-
- `tool-calls`: model triggered tool calls
|
919
|
-
- `error`: model stopped because of an error
|
920
|
-
- `other`: model stopped for other reasons
|
921
|
-
- `unknown`: the model has not transmitted a finish reason
|
854
|
+
A file that has been generated by the model.
|
855
|
+
Generated files as base64 encoded strings or binary data.
|
856
|
+
The files should be returned without any unnecessary conversion.
|
922
857
|
*/
|
923
|
-
type
|
924
|
-
|
925
|
-
type LanguageModelV1FunctionToolCall = {
|
926
|
-
toolCallType: 'function';
|
927
|
-
toolCallId: string;
|
928
|
-
toolName: string;
|
858
|
+
type LanguageModelV2File = {
|
859
|
+
type: 'file';
|
929
860
|
/**
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
861
|
+
The IANA media type of the file, e.g. `image/png` or `audio/mp3`.
|
862
|
+
|
863
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
864
|
+
*/
|
865
|
+
mediaType: string;
|
866
|
+
/**
|
867
|
+
Generated file data as base64 encoded strings or binary data.
|
868
|
+
|
869
|
+
The file data should be returned without any unnecessary conversion.
|
870
|
+
If the API returns base64 encoded strings, the file data should be returned
|
871
|
+
as base64 encoded strings. If the API returns binary data, the file data should
|
872
|
+
be returned as binary data.
|
873
|
+
*/
|
874
|
+
data: string | Uint8Array;
|
934
875
|
};
|
935
876
|
|
936
877
|
/**
|
937
|
-
|
878
|
+
Reasoning that the model has generated.
|
938
879
|
*/
|
939
|
-
type
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
}
|
880
|
+
type LanguageModelV2Reasoning = {
|
881
|
+
type: 'reasoning';
|
882
|
+
text: string;
|
883
|
+
/**
|
884
|
+
* Optional provider-specific metadata for the reasoning part.
|
885
|
+
*/
|
886
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
887
|
+
};
|
947
888
|
|
948
889
|
/**
|
949
|
-
|
890
|
+
A source that has been used as input to generate the response.
|
950
891
|
*/
|
951
|
-
type
|
892
|
+
type LanguageModelV2Source = {
|
893
|
+
type: 'source';
|
952
894
|
/**
|
953
|
-
|
954
|
-
version it implements. This will allow us to evolve the language
|
955
|
-
model interface and retain backwards compatibility. The different
|
956
|
-
implementation versions can be handled as a discriminated union
|
957
|
-
on our side.
|
895
|
+
* A URL source. This is return by web search RAG models.
|
958
896
|
*/
|
959
|
-
|
897
|
+
sourceType: 'url';
|
960
898
|
/**
|
961
|
-
|
899
|
+
* The ID of the source.
|
962
900
|
*/
|
963
|
-
|
901
|
+
id: string;
|
964
902
|
/**
|
965
|
-
|
903
|
+
* The URL of the source.
|
966
904
|
*/
|
967
|
-
|
905
|
+
url: string;
|
968
906
|
/**
|
969
|
-
|
970
|
-
no mode is specified. Should be the mode with the best results for this
|
971
|
-
model. `undefined` can be returned if object generation is not supported.
|
972
|
-
|
973
|
-
This is needed to generate the best objects possible w/o requiring the
|
974
|
-
user to explicitly specify the object generation mode.
|
907
|
+
* The title of the source.
|
975
908
|
*/
|
976
|
-
|
909
|
+
title?: string;
|
977
910
|
/**
|
978
|
-
|
979
|
-
|
980
|
-
When the flag is set to `false`, the AI SDK will download the image and
|
981
|
-
pass the image data to the model.
|
911
|
+
* Additional provider metadata for the source.
|
982
912
|
*/
|
983
|
-
|
913
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
914
|
+
};
|
915
|
+
|
916
|
+
/**
|
917
|
+
Text that the model has generated.
|
918
|
+
*/
|
919
|
+
type LanguageModelV2Text = {
|
920
|
+
type: 'text';
|
984
921
|
/**
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
922
|
+
The text content.
|
923
|
+
*/
|
924
|
+
text: string;
|
925
|
+
};
|
926
|
+
|
927
|
+
/**
|
928
|
+
Tool calls that the model has generated.
|
929
|
+
*/
|
930
|
+
type LanguageModelV2ToolCall = {
|
931
|
+
type: 'tool-call';
|
932
|
+
toolCallType: 'function';
|
933
|
+
toolCallId: string;
|
934
|
+
toolName: string;
|
935
|
+
/**
|
936
|
+
Stringified JSON object with the tool call arguments. Must match the
|
937
|
+
parameters schema of the tool.
|
938
|
+
*/
|
939
|
+
args: string;
|
940
|
+
};
|
941
|
+
|
942
|
+
type LanguageModelV2Content = LanguageModelV2Text | LanguageModelV2Reasoning | LanguageModelV2File | LanguageModelV2Source | LanguageModelV2ToolCall;
|
943
|
+
|
944
|
+
/**
|
945
|
+
Reason why a language model finished generating a response.
|
946
|
+
|
947
|
+
Can be one of the following:
|
948
|
+
- `stop`: model generated stop sequence
|
949
|
+
- `length`: model generated maximum number of tokens
|
950
|
+
- `content-filter`: content filter violation stopped the model
|
951
|
+
- `tool-calls`: model triggered tool calls
|
952
|
+
- `error`: model stopped because of an error
|
953
|
+
- `other`: model stopped for other reasons
|
954
|
+
- `unknown`: the model has not transmitted a finish reason
|
955
|
+
*/
|
956
|
+
type LanguageModelV2FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
|
957
|
+
|
958
|
+
interface LanguageModelV2ResponseMetadata {
|
959
|
+
/**
|
960
|
+
ID for the generated response, if the provider sends one.
|
961
|
+
*/
|
962
|
+
id?: string;
|
963
|
+
/**
|
964
|
+
Timestamp for the start of the generated response, if the provider sends one.
|
999
965
|
*/
|
1000
|
-
|
966
|
+
timestamp?: Date;
|
1001
967
|
/**
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
968
|
+
The ID of the response model that was used to generate the response, if the provider sends one.
|
969
|
+
*/
|
970
|
+
modelId?: string;
|
971
|
+
}
|
972
|
+
|
973
|
+
type LanguageModelV2ToolCallDelta = {
|
974
|
+
type: 'tool-call-delta';
|
975
|
+
toolCallType: 'function';
|
976
|
+
toolCallId: string;
|
977
|
+
toolName: string;
|
978
|
+
argsTextDelta: string;
|
979
|
+
};
|
980
|
+
|
981
|
+
/**
|
982
|
+
* Usage information for a language model call.
|
983
|
+
*/
|
984
|
+
type LanguageModelV2Usage = {
|
985
|
+
/**
|
986
|
+
* The number of input (prompt) tokens used.
|
1007
987
|
*/
|
1008
|
-
|
988
|
+
inputTokens: number | undefined;
|
989
|
+
/**
|
990
|
+
* The number of output (completion) tokens used.
|
991
|
+
*/
|
992
|
+
outputTokens: number | undefined;
|
993
|
+
};
|
994
|
+
|
995
|
+
type LanguageModelV2StreamPart = LanguageModelV2Content | {
|
996
|
+
type: 'reasoning-part-finish';
|
997
|
+
} | LanguageModelV2ToolCallDelta | {
|
998
|
+
type: 'stream-start';
|
999
|
+
warnings: Array<LanguageModelV2CallWarning>;
|
1000
|
+
} | ({
|
1001
|
+
type: 'response-metadata';
|
1002
|
+
} & LanguageModelV2ResponseMetadata) | {
|
1003
|
+
type: 'finish';
|
1004
|
+
usage: LanguageModelV2Usage;
|
1005
|
+
finishReason: LanguageModelV2FinishReason;
|
1006
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1007
|
+
} | {
|
1008
|
+
type: 'error';
|
1009
|
+
error: unknown;
|
1010
|
+
};
|
1011
|
+
|
1012
|
+
/**
|
1013
|
+
Specification for a language model that implements the language model interface version 2.
|
1014
|
+
*/
|
1015
|
+
type LanguageModelV2 = {
|
1016
|
+
/**
|
1017
|
+
The language model must specify which language model interface
|
1018
|
+
version it implements. This will allow us to evolve the language
|
1019
|
+
model interface and retain backwards compatibility. The different
|
1020
|
+
implementation versions can be handled as a discriminated union
|
1021
|
+
on our side.
|
1022
|
+
*/
|
1023
|
+
readonly specificationVersion: 'v2';
|
1024
|
+
/**
|
1025
|
+
Name of the provider for logging purposes.
|
1026
|
+
*/
|
1027
|
+
readonly provider: string;
|
1028
|
+
/**
|
1029
|
+
Provider-specific model ID for logging purposes.
|
1030
|
+
*/
|
1031
|
+
readonly modelId: string;
|
1032
|
+
/**
|
1033
|
+
* Returns a map of supported URL patterns for the model.
|
1034
|
+
* The keys are media type patterns or full media types (e.g. `*\/*` for everything, `audio/*`, `video/*`, or `application/pdf`).
|
1035
|
+
* and the values are arrays of regular expressions that match the URL paths.
|
1036
|
+
*
|
1037
|
+
* The matching should be against lower-case URLs.
|
1038
|
+
*
|
1039
|
+
* Matched URLs are supported natively by the model and are not downloaded.
|
1040
|
+
*
|
1041
|
+
* @returns A promise resolving to a map of supported URL patterns.
|
1042
|
+
*/
|
1043
|
+
getSupportedUrls(): PromiseLike<Record<string, RegExp[]>>;
|
1009
1044
|
/**
|
1010
1045
|
Generates a language model output (non-streaming).
|
1011
1046
|
|
1012
1047
|
Naming: "do" prefix to prevent accidental direct usage of the method
|
1013
1048
|
by the user.
|
1014
1049
|
*/
|
1015
|
-
doGenerate(options:
|
1016
|
-
/**
|
1017
|
-
Text that the model has generated.
|
1018
|
-
Can be undefined if the model did not generate any text.
|
1019
|
-
*/
|
1020
|
-
text?: string;
|
1021
|
-
/**
|
1022
|
-
Reasoning that the model has generated.
|
1023
|
-
Can be undefined if the model does not support reasoning.
|
1024
|
-
*/
|
1025
|
-
reasoning?: string | Array<{
|
1026
|
-
type: 'text';
|
1027
|
-
text: string;
|
1028
|
-
/**
|
1029
|
-
An optional signature for verifying that the reasoning originated from the model.
|
1030
|
-
*/
|
1031
|
-
signature?: string;
|
1032
|
-
} | {
|
1033
|
-
type: 'redacted';
|
1034
|
-
data: string;
|
1035
|
-
}>;
|
1050
|
+
doGenerate(options: LanguageModelV2CallOptions): PromiseLike<{
|
1036
1051
|
/**
|
1037
|
-
|
1038
|
-
The files should be returned without any unnecessary conversion.
|
1039
|
-
If the API returns base64 encoded strings, the files should be returned
|
1040
|
-
as base64 encoded strings. If the API returns binary data, the files should
|
1041
|
-
be returned as binary data.
|
1052
|
+
Ordered content that the model has generated.
|
1042
1053
|
*/
|
1043
|
-
|
1044
|
-
data: string | Uint8Array;
|
1045
|
-
mimeType: string;
|
1046
|
-
}>;
|
1047
|
-
/**
|
1048
|
-
Tool calls that the model has generated.
|
1049
|
-
Can be undefined if the model did not generate any tool calls.
|
1050
|
-
*/
|
1051
|
-
toolCalls?: Array<LanguageModelV1FunctionToolCall>;
|
1054
|
+
content: Array<LanguageModelV2Content>;
|
1052
1055
|
/**
|
1053
1056
|
Finish reason.
|
1054
1057
|
*/
|
1055
|
-
finishReason:
|
1058
|
+
finishReason: LanguageModelV2FinishReason;
|
1056
1059
|
/**
|
1057
1060
|
Usage information.
|
1058
1061
|
*/
|
1059
|
-
usage:
|
1060
|
-
promptTokens: number;
|
1061
|
-
completionTokens: number;
|
1062
|
-
};
|
1063
|
-
/**
|
1064
|
-
Raw prompt and setting information for observability provider integration.
|
1065
|
-
*/
|
1066
|
-
rawCall: {
|
1067
|
-
/**
|
1068
|
-
Raw prompt after expansion and conversion to the format that the
|
1069
|
-
provider uses to send the information to their API.
|
1070
|
-
*/
|
1071
|
-
rawPrompt: unknown;
|
1072
|
-
/**
|
1073
|
-
Raw settings that are used for the API call. Includes provider-specific
|
1074
|
-
settings.
|
1075
|
-
*/
|
1076
|
-
rawSettings: Record<string, unknown>;
|
1077
|
-
};
|
1062
|
+
usage: LanguageModelV2Usage;
|
1078
1063
|
/**
|
1079
|
-
|
1064
|
+
Additional provider-specific metadata. They are passed through
|
1065
|
+
from the provider to the AI SDK and enable provider-specific
|
1066
|
+
results that can be fully encapsulated in the provider.
|
1080
1067
|
*/
|
1081
|
-
|
1082
|
-
/**
|
1083
|
-
Response headers.
|
1084
|
-
*/
|
1085
|
-
headers?: Record<string, string>;
|
1086
|
-
/**
|
1087
|
-
Response body.
|
1088
|
-
*/
|
1089
|
-
body?: unknown;
|
1090
|
-
};
|
1068
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1091
1069
|
/**
|
1092
1070
|
Optional request information for telemetry and debugging purposes.
|
1093
1071
|
*/
|
1094
1072
|
request?: {
|
1095
1073
|
/**
|
1096
|
-
|
1097
|
-
Non-HTTP(s) providers should not set this.
|
1074
|
+
Request HTTP body that was sent to the provider API.
|
1098
1075
|
*/
|
1099
|
-
body?:
|
1076
|
+
body?: unknown;
|
1100
1077
|
};
|
1101
1078
|
/**
|
1102
1079
|
Optional response information for telemetry and debugging purposes.
|
1103
1080
|
*/
|
1104
|
-
response?: {
|
1105
|
-
/**
|
1106
|
-
ID for the generated response, if the provider sends one.
|
1107
|
-
*/
|
1108
|
-
id?: string;
|
1081
|
+
response?: LanguageModelV2ResponseMetadata & {
|
1109
1082
|
/**
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1083
|
+
Response headers.
|
1084
|
+
*/
|
1085
|
+
headers?: SharedV2Headers;
|
1113
1086
|
/**
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1087
|
+
Response HTTP body.
|
1088
|
+
*/
|
1089
|
+
body?: unknown;
|
1117
1090
|
};
|
1118
|
-
warnings?: LanguageModelV1CallWarning[];
|
1119
|
-
/**
|
1120
|
-
Additional provider-specific metadata. They are passed through
|
1121
|
-
from the provider to the AI SDK and enable provider-specific
|
1122
|
-
results that can be fully encapsulated in the provider.
|
1123
|
-
*/
|
1124
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1125
1091
|
/**
|
1126
|
-
|
1127
|
-
*/
|
1128
|
-
sources?: LanguageModelV1Source[];
|
1129
|
-
/**
|
1130
|
-
Logprobs for the completion.
|
1131
|
-
`undefined` if the mode does not support logprobs or if was not enabled
|
1132
|
-
|
1133
|
-
@deprecated will be changed into a provider-specific extension in v2
|
1092
|
+
Warnings for the call, e.g. unsupported settings.
|
1134
1093
|
*/
|
1135
|
-
|
1094
|
+
warnings: Array<LanguageModelV2CallWarning>;
|
1136
1095
|
}>;
|
1137
1096
|
/**
|
1138
1097
|
Generates a language model output (streaming).
|
@@ -1142,105 +1101,209 @@ An optional signature for verifying that the reasoning originated from the model
|
|
1142
1101
|
*
|
1143
1102
|
@return A stream of higher-level language model output parts.
|
1144
1103
|
*/
|
1145
|
-
doStream(options:
|
1146
|
-
stream: ReadableStream<
|
1104
|
+
doStream(options: LanguageModelV2CallOptions): PromiseLike<{
|
1105
|
+
stream: ReadableStream<LanguageModelV2StreamPart>;
|
1147
1106
|
/**
|
1148
|
-
|
1107
|
+
Optional request information for telemetry and debugging purposes.
|
1149
1108
|
*/
|
1150
|
-
|
1151
|
-
/**
|
1152
|
-
Raw prompt after expansion and conversion to the format that the
|
1153
|
-
provider uses to send the information to their API.
|
1154
|
-
*/
|
1155
|
-
rawPrompt: unknown;
|
1109
|
+
request?: {
|
1156
1110
|
/**
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
rawSettings: Record<string, unknown>;
|
1111
|
+
Request HTTP body that was sent to the provider API.
|
1112
|
+
*/
|
1113
|
+
body?: unknown;
|
1161
1114
|
};
|
1162
1115
|
/**
|
1163
|
-
Optional
|
1116
|
+
Optional response data.
|
1164
1117
|
*/
|
1165
|
-
|
1118
|
+
response?: {
|
1166
1119
|
/**
|
1167
1120
|
Response headers.
|
1168
1121
|
*/
|
1169
|
-
headers?:
|
1122
|
+
headers?: SharedV2Headers;
|
1170
1123
|
};
|
1124
|
+
}>;
|
1125
|
+
};
|
1126
|
+
|
1127
|
+
/**
|
1128
|
+
* Experimental middleware for LanguageModelV2.
|
1129
|
+
* This type defines the structure for middleware that can be used to modify
|
1130
|
+
* the behavior of LanguageModelV2 operations.
|
1131
|
+
*/
|
1132
|
+
type LanguageModelV2Middleware = {
|
1133
|
+
/**
|
1134
|
+
* Middleware specification version. Use `v2` for the current version.
|
1135
|
+
*/
|
1136
|
+
middlewareVersion?: 'v2' | undefined;
|
1137
|
+
/**
|
1138
|
+
* Transforms the parameters before they are passed to the language model.
|
1139
|
+
* @param options - Object containing the type of operation and the parameters.
|
1140
|
+
* @param options.type - The type of operation ('generate' or 'stream').
|
1141
|
+
* @param options.params - The original parameters for the language model call.
|
1142
|
+
* @returns A promise that resolves to the transformed parameters.
|
1143
|
+
*/
|
1144
|
+
transformParams?: (options: {
|
1145
|
+
type: 'generate' | 'stream';
|
1146
|
+
params: LanguageModelV2CallOptions;
|
1147
|
+
}) => PromiseLike<LanguageModelV2CallOptions>;
|
1148
|
+
/**
|
1149
|
+
* Wraps the generate operation of the language model.
|
1150
|
+
* @param options - Object containing the generate function, parameters, and model.
|
1151
|
+
* @param options.doGenerate - The original generate function.
|
1152
|
+
* @param options.doStream - The original stream function.
|
1153
|
+
* @param options.params - The parameters for the generate call. If the
|
1154
|
+
* `transformParams` middleware is used, this will be the transformed parameters.
|
1155
|
+
* @param options.model - The language model instance.
|
1156
|
+
* @returns A promise that resolves to the result of the generate operation.
|
1157
|
+
*/
|
1158
|
+
wrapGenerate?: (options: {
|
1159
|
+
doGenerate: () => ReturnType<LanguageModelV2['doGenerate']>;
|
1160
|
+
doStream: () => ReturnType<LanguageModelV2['doStream']>;
|
1161
|
+
params: LanguageModelV2CallOptions;
|
1162
|
+
model: LanguageModelV2;
|
1163
|
+
}) => Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
|
1164
|
+
/**
|
1165
|
+
* Wraps the stream operation of the language model.
|
1166
|
+
*
|
1167
|
+
* @param options - Object containing the stream function, parameters, and model.
|
1168
|
+
* @param options.doGenerate - The original generate function.
|
1169
|
+
* @param options.doStream - The original stream function.
|
1170
|
+
* @param options.params - The parameters for the stream call. If the
|
1171
|
+
* `transformParams` middleware is used, this will be the transformed parameters.
|
1172
|
+
* @param options.model - The language model instance.
|
1173
|
+
* @returns A promise that resolves to the result of the stream operation.
|
1174
|
+
*/
|
1175
|
+
wrapStream?: (options: {
|
1176
|
+
doGenerate: () => ReturnType<LanguageModelV2['doGenerate']>;
|
1177
|
+
doStream: () => ReturnType<LanguageModelV2['doStream']>;
|
1178
|
+
params: LanguageModelV2CallOptions;
|
1179
|
+
model: LanguageModelV2;
|
1180
|
+
}) => PromiseLike<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
|
1181
|
+
};
|
1182
|
+
|
1183
|
+
/**
|
1184
|
+
* Additional provider-specific metadata. They are passed through
|
1185
|
+
* to the provider from the AI SDK and enable provider-specific
|
1186
|
+
* functionality that can be fully encapsulated in the provider.
|
1187
|
+
*
|
1188
|
+
* This enables us to quickly ship provider-specific functionality
|
1189
|
+
* without affecting the core AI SDK.
|
1190
|
+
*
|
1191
|
+
* The outer record is keyed by the provider name, and the inner
|
1192
|
+
* record is keyed by the provider-specific metadata key.
|
1193
|
+
*
|
1194
|
+
* ```ts
|
1195
|
+
* {
|
1196
|
+
* "anthropic": {
|
1197
|
+
* "cacheControl": { "type": "ephemeral" }
|
1198
|
+
* }
|
1199
|
+
* }
|
1200
|
+
* ```
|
1201
|
+
*/
|
1202
|
+
type LanguageModelV1ProviderMetadata = Record<string, Record<string, JSONValue>>;
|
1203
|
+
|
1204
|
+
/**
|
1205
|
+
* A source that has been used as input to generate the response.
|
1206
|
+
*/
|
1207
|
+
type LanguageModelV1Source = {
|
1208
|
+
/**
|
1209
|
+
* A URL source. This is return by web search RAG models.
|
1210
|
+
*/
|
1211
|
+
sourceType: 'url';
|
1212
|
+
/**
|
1213
|
+
* The ID of the source.
|
1214
|
+
*/
|
1215
|
+
id: string;
|
1216
|
+
/**
|
1217
|
+
* The URL of the source.
|
1218
|
+
*/
|
1219
|
+
url: string;
|
1220
|
+
/**
|
1221
|
+
* The title of the source.
|
1222
|
+
*/
|
1223
|
+
title?: string;
|
1224
|
+
/**
|
1225
|
+
* Additional provider metadata for the source.
|
1226
|
+
*/
|
1227
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1228
|
+
};
|
1229
|
+
|
1230
|
+
type LanguageModelV1CallSettings = {
|
1231
|
+
/**
|
1232
|
+
Maximum number of tokens to generate.
|
1233
|
+
*/
|
1234
|
+
maxTokens?: number;
|
1235
|
+
/**
|
1236
|
+
Temperature setting.
|
1237
|
+
|
1238
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
1239
|
+
*/
|
1240
|
+
temperature?: number;
|
1241
|
+
/**
|
1242
|
+
Stop sequences.
|
1243
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
1244
|
+
Providers may have limits on the number of stop sequences.
|
1245
|
+
*/
|
1246
|
+
stopSequences?: string[];
|
1247
|
+
/**
|
1248
|
+
Nucleus sampling.
|
1249
|
+
|
1250
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
1251
|
+
*/
|
1252
|
+
topP?: number;
|
1253
|
+
/**
|
1254
|
+
Only sample from the top K options for each subsequent token.
|
1255
|
+
|
1256
|
+
Used to remove "long tail" low probability responses.
|
1257
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
1258
|
+
*/
|
1259
|
+
topK?: number;
|
1260
|
+
/**
|
1261
|
+
Presence penalty setting. It affects the likelihood of the model to
|
1262
|
+
repeat information that is already in the prompt.
|
1263
|
+
*/
|
1264
|
+
presencePenalty?: number;
|
1265
|
+
/**
|
1266
|
+
Frequency penalty setting. It affects the likelihood of the model
|
1267
|
+
to repeatedly use the same words or phrases.
|
1268
|
+
*/
|
1269
|
+
frequencyPenalty?: number;
|
1270
|
+
/**
|
1271
|
+
Response format. The output can either be text or JSON. Default is text.
|
1272
|
+
|
1273
|
+
If JSON is selected, a schema can optionally be provided to guide the LLM.
|
1274
|
+
*/
|
1275
|
+
responseFormat?: {
|
1276
|
+
type: 'text';
|
1277
|
+
} | {
|
1278
|
+
type: 'json';
|
1171
1279
|
/**
|
1172
|
-
|
1280
|
+
* JSON schema that the generated output should conform to.
|
1173
1281
|
*/
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
Non-HTTP(s) providers should not set this.
|
1282
|
+
schema?: JSONSchema7;
|
1283
|
+
/**
|
1284
|
+
* Name of output that should be generated. Used by some providers for additional LLM guidance.
|
1178
1285
|
*/
|
1179
|
-
|
1180
|
-
};
|
1286
|
+
name?: string;
|
1181
1287
|
/**
|
1182
|
-
|
1288
|
+
* Description of the output that should be generated. Used by some providers for additional LLM guidance.
|
1183
1289
|
*/
|
1184
|
-
|
1185
|
-
}
|
1186
|
-
};
|
1187
|
-
type LanguageModelV1StreamPart = {
|
1188
|
-
type: 'text-delta';
|
1189
|
-
textDelta: string;
|
1190
|
-
} | {
|
1191
|
-
type: 'reasoning';
|
1192
|
-
textDelta: string;
|
1193
|
-
} | {
|
1194
|
-
type: 'reasoning-signature';
|
1195
|
-
signature: string;
|
1196
|
-
} | {
|
1197
|
-
type: 'redacted-reasoning';
|
1198
|
-
data: string;
|
1199
|
-
} | {
|
1200
|
-
type: 'source';
|
1201
|
-
source: LanguageModelV1Source;
|
1202
|
-
} | {
|
1203
|
-
type: 'file';
|
1204
|
-
mimeType: string;
|
1290
|
+
description?: string;
|
1291
|
+
};
|
1205
1292
|
/**
|
1206
|
-
|
1207
|
-
|
1208
|
-
If the API returns base64 encoded strings, the file data should be returned
|
1209
|
-
as base64 encoded strings. If the API returns binary data, the file data should
|
1210
|
-
be returned as binary data.
|
1293
|
+
The seed (integer) to use for random sampling. If set and supported
|
1294
|
+
by the model, calls will generate deterministic results.
|
1211
1295
|
*/
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
id?: string;
|
1224
|
-
timestamp?: Date;
|
1225
|
-
modelId?: string;
|
1226
|
-
} | {
|
1227
|
-
type: 'finish';
|
1228
|
-
finishReason: LanguageModelV1FinishReason;
|
1229
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1230
|
-
usage: {
|
1231
|
-
promptTokens: number;
|
1232
|
-
completionTokens: number;
|
1233
|
-
};
|
1234
|
-
logprobs?: LanguageModelV1LogProbs;
|
1235
|
-
} | {
|
1236
|
-
type: 'error';
|
1237
|
-
error: unknown;
|
1238
|
-
};
|
1239
|
-
/**
|
1240
|
-
The object generation modes available for use with a model. `undefined`
|
1241
|
-
represents no support for object generation.
|
1242
|
-
*/
|
1243
|
-
type LanguageModelV1ObjectGenerationMode = 'json' | 'tool' | undefined;
|
1296
|
+
seed?: number;
|
1297
|
+
/**
|
1298
|
+
Abort signal for cancelling the operation.
|
1299
|
+
*/
|
1300
|
+
abortSignal?: AbortSignal;
|
1301
|
+
/**
|
1302
|
+
Additional HTTP headers to be sent with the request.
|
1303
|
+
Only applicable for HTTP-based providers.
|
1304
|
+
*/
|
1305
|
+
headers?: Record<string, string | undefined>;
|
1306
|
+
};
|
1244
1307
|
|
1245
1308
|
/**
|
1246
1309
|
A tool has a name, a description, and a set of parameters.
|
@@ -1248,7 +1311,7 @@ A tool has a name, a description, and a set of parameters.
|
|
1248
1311
|
Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
1249
1312
|
map the user-facing tool definitions to this format.
|
1250
1313
|
*/
|
1251
|
-
type
|
1314
|
+
type LanguageModelV1FunctionTool = {
|
1252
1315
|
/**
|
1253
1316
|
The type of the tool (always 'function').
|
1254
1317
|
*/
|
@@ -1269,29 +1332,6 @@ type LanguageModelV2FunctionTool = {
|
|
1269
1332
|
parameters: JSONSchema7;
|
1270
1333
|
};
|
1271
1334
|
|
1272
|
-
/**
|
1273
|
-
* Additional provider-specific options.
|
1274
|
-
* Options are additional input to the provider.
|
1275
|
-
* They are passed through to the provider from the AI SDK
|
1276
|
-
* and enable provider-specific functionality
|
1277
|
-
* that can be fully encapsulated in the provider.
|
1278
|
-
*
|
1279
|
-
* This enables us to quickly ship provider-specific functionality
|
1280
|
-
* without affecting the core AI SDK.
|
1281
|
-
*
|
1282
|
-
* The outer record is keyed by the provider name, and the inner
|
1283
|
-
* record is keyed by the provider-specific metadata key.
|
1284
|
-
*
|
1285
|
-
* ```ts
|
1286
|
-
* {
|
1287
|
-
* "anthropic": {
|
1288
|
-
* "cacheControl": { "type": "ephemeral" }
|
1289
|
-
* }
|
1290
|
-
* }
|
1291
|
-
* ```
|
1292
|
-
*/
|
1293
|
-
type LanguageModelV2ProviderOptions = Record<string, Record<string, JSONValue>>;
|
1294
|
-
|
1295
1335
|
/**
|
1296
1336
|
A prompt is a list of messages.
|
1297
1337
|
|
@@ -1301,47 +1341,47 @@ tool calls. The validation happens at runtime.
|
|
1301
1341
|
Note: This is not a user-facing prompt. The AI SDK methods will map the
|
1302
1342
|
user-facing prompt types such as chat or instruction prompts to this format.
|
1303
1343
|
*/
|
1304
|
-
type
|
1305
|
-
type
|
1344
|
+
type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
|
1345
|
+
type LanguageModelV1Message = ({
|
1306
1346
|
role: 'system';
|
1307
1347
|
content: string;
|
1308
1348
|
} | {
|
1309
1349
|
role: 'user';
|
1310
|
-
content: Array<
|
1350
|
+
content: Array<LanguageModelV1TextPart | LanguageModelV1ImagePart | LanguageModelV1FilePart>;
|
1311
1351
|
} | {
|
1312
1352
|
role: 'assistant';
|
1313
|
-
content: Array<
|
1353
|
+
content: Array<LanguageModelV1TextPart | LanguageModelV1FilePart | LanguageModelV1ReasoningPart | LanguageModelV1RedactedReasoningPart | LanguageModelV1ToolCallPart>;
|
1314
1354
|
} | {
|
1315
1355
|
role: 'tool';
|
1316
|
-
content: Array<
|
1356
|
+
content: Array<LanguageModelV1ToolResultPart>;
|
1317
1357
|
}) & {
|
1318
1358
|
/**
|
1319
|
-
* Additional provider-specific
|
1359
|
+
* Additional provider-specific metadata. They are passed through
|
1320
1360
|
* to the provider from the AI SDK and enable provider-specific
|
1321
1361
|
* functionality that can be fully encapsulated in the provider.
|
1322
1362
|
*/
|
1323
|
-
|
1363
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1324
1364
|
};
|
1325
1365
|
/**
|
1326
1366
|
Text content part of a prompt. It contains a string of text.
|
1327
1367
|
*/
|
1328
|
-
interface
|
1368
|
+
interface LanguageModelV1TextPart {
|
1329
1369
|
type: 'text';
|
1330
1370
|
/**
|
1331
1371
|
The text content.
|
1332
1372
|
*/
|
1333
1373
|
text: string;
|
1334
1374
|
/**
|
1335
|
-
* Additional provider-specific
|
1375
|
+
* Additional provider-specific metadata. They are passed through
|
1336
1376
|
* to the provider from the AI SDK and enable provider-specific
|
1337
1377
|
* functionality that can be fully encapsulated in the provider.
|
1338
1378
|
*/
|
1339
|
-
|
1379
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1340
1380
|
}
|
1341
1381
|
/**
|
1342
1382
|
Reasoning content part of a prompt. It contains a string of reasoning text.
|
1343
1383
|
*/
|
1344
|
-
interface
|
1384
|
+
interface LanguageModelV1ReasoningPart {
|
1345
1385
|
type: 'reasoning';
|
1346
1386
|
/**
|
1347
1387
|
The reasoning text.
|
@@ -1352,32 +1392,32 @@ interface LanguageModelV2ReasoningPart {
|
|
1352
1392
|
*/
|
1353
1393
|
signature?: string;
|
1354
1394
|
/**
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1395
|
+
Additional provider-specific metadata. They are passed through
|
1396
|
+
to the provider from the AI SDK and enable provider-specific
|
1397
|
+
functionality that can be fully encapsulated in the provider.
|
1358
1398
|
*/
|
1359
|
-
|
1399
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1360
1400
|
}
|
1361
1401
|
/**
|
1362
1402
|
Redacted reasoning content part of a prompt.
|
1363
1403
|
*/
|
1364
|
-
interface
|
1404
|
+
interface LanguageModelV1RedactedReasoningPart {
|
1365
1405
|
type: 'redacted-reasoning';
|
1366
1406
|
/**
|
1367
1407
|
Redacted reasoning data.
|
1368
1408
|
*/
|
1369
1409
|
data: string;
|
1370
1410
|
/**
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1411
|
+
Additional provider-specific metadata. They are passed through
|
1412
|
+
to the provider from the AI SDK and enable provider-specific
|
1413
|
+
functionality that can be fully encapsulated in the provider.
|
1374
1414
|
*/
|
1375
|
-
|
1415
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1376
1416
|
}
|
1377
1417
|
/**
|
1378
1418
|
Image content part of a prompt. It contains an image.
|
1379
1419
|
*/
|
1380
|
-
interface
|
1420
|
+
interface LanguageModelV1ImagePart {
|
1381
1421
|
type: 'image';
|
1382
1422
|
/**
|
1383
1423
|
Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
|
@@ -1388,16 +1428,16 @@ interface LanguageModelV2ImagePart {
|
|
1388
1428
|
*/
|
1389
1429
|
mimeType?: string;
|
1390
1430
|
/**
|
1391
|
-
* Additional provider-specific
|
1431
|
+
* Additional provider-specific metadata. They are passed through
|
1392
1432
|
* to the provider from the AI SDK and enable provider-specific
|
1393
1433
|
* functionality that can be fully encapsulated in the provider.
|
1394
1434
|
*/
|
1395
|
-
|
1435
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1396
1436
|
}
|
1397
1437
|
/**
|
1398
1438
|
File content part of a prompt. It contains a file.
|
1399
1439
|
*/
|
1400
|
-
interface
|
1440
|
+
interface LanguageModelV1FilePart {
|
1401
1441
|
type: 'file';
|
1402
1442
|
/**
|
1403
1443
|
* Optional filename of the file.
|
@@ -1412,16 +1452,16 @@ interface LanguageModelV2FilePart {
|
|
1412
1452
|
*/
|
1413
1453
|
mimeType: string;
|
1414
1454
|
/**
|
1415
|
-
* Additional provider-specific
|
1455
|
+
* Additional provider-specific metadata. They are passed through
|
1416
1456
|
* to the provider from the AI SDK and enable provider-specific
|
1417
1457
|
* functionality that can be fully encapsulated in the provider.
|
1418
1458
|
*/
|
1419
|
-
|
1459
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1420
1460
|
}
|
1421
1461
|
/**
|
1422
1462
|
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
1423
1463
|
*/
|
1424
|
-
interface
|
1464
|
+
interface LanguageModelV1ToolCallPart {
|
1425
1465
|
type: 'tool-call';
|
1426
1466
|
/**
|
1427
1467
|
ID of the tool call. This ID is used to match the tool call with the tool result.
|
@@ -1436,16 +1476,16 @@ interface LanguageModelV2ToolCallPart {
|
|
1436
1476
|
*/
|
1437
1477
|
args: unknown;
|
1438
1478
|
/**
|
1439
|
-
* Additional provider-specific
|
1479
|
+
* Additional provider-specific metadata. They are passed through
|
1440
1480
|
* to the provider from the AI SDK and enable provider-specific
|
1441
1481
|
* functionality that can be fully encapsulated in the provider.
|
1442
1482
|
*/
|
1443
|
-
|
1483
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1444
1484
|
}
|
1445
1485
|
/**
|
1446
1486
|
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
1447
1487
|
*/
|
1448
|
-
interface
|
1488
|
+
interface LanguageModelV1ToolResultPart {
|
1449
1489
|
type: 'tool-result';
|
1450
1490
|
/**
|
1451
1491
|
ID of the tool call that this result is associated with.
|
@@ -1485,17 +1525,17 @@ Mime type of the image.
|
|
1485
1525
|
mimeType?: string;
|
1486
1526
|
}>;
|
1487
1527
|
/**
|
1488
|
-
* Additional provider-specific
|
1528
|
+
* Additional provider-specific metadata. They are passed through
|
1489
1529
|
* to the provider from the AI SDK and enable provider-specific
|
1490
1530
|
* functionality that can be fully encapsulated in the provider.
|
1491
1531
|
*/
|
1492
|
-
|
1532
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1493
1533
|
}
|
1494
1534
|
|
1495
1535
|
/**
|
1496
1536
|
The configuration of a tool that is defined by the provider.
|
1497
1537
|
*/
|
1498
|
-
type
|
1538
|
+
type LanguageModelV1ProviderDefinedTool = {
|
1499
1539
|
/**
|
1500
1540
|
The type of the tool (always 'provider-defined').
|
1501
1541
|
*/
|
@@ -1514,7 +1554,7 @@ type LanguageModelV2ProviderDefinedTool = {
|
|
1514
1554
|
args: Record<string, unknown>;
|
1515
1555
|
};
|
1516
1556
|
|
1517
|
-
type
|
1557
|
+
type LanguageModelV1ToolChoice = {
|
1518
1558
|
type: 'auto';
|
1519
1559
|
} | {
|
1520
1560
|
type: 'none';
|
@@ -1525,7 +1565,7 @@ type LanguageModelV2ToolChoice = {
|
|
1525
1565
|
toolName: string;
|
1526
1566
|
};
|
1527
1567
|
|
1528
|
-
type
|
1568
|
+
type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
|
1529
1569
|
/**
|
1530
1570
|
Whether the user provided the input as messages or as
|
1531
1571
|
a prompt. This can help guide non-chat models in the
|
@@ -1534,62 +1574,29 @@ type LanguageModelV2CallOptions = {
|
|
1534
1574
|
*/
|
1535
1575
|
inputFormat: 'messages' | 'prompt';
|
1536
1576
|
/**
|
1537
|
-
|
1577
|
+
The mode affects the behavior of the language model. It is required to
|
1578
|
+
support provider-independent streaming and generation of structured objects.
|
1579
|
+
The model can take this information and e.g. configure json mode, the correct
|
1580
|
+
low level grammar, etc. It can also be used to optimize the efficiency of the
|
1581
|
+
streaming, e.g. tool-delta stream parts are only needed in the
|
1582
|
+
object-tool mode.
|
1538
1583
|
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
the language model interface.
|
1543
|
-
*/
|
1544
|
-
prompt: LanguageModelV2Prompt;
|
1545
|
-
/**
|
1546
|
-
Maximum number of tokens to generate.
|
1584
|
+
@deprecated mode will be removed in v2.
|
1585
|
+
All necessary settings will be directly supported through the call settings,
|
1586
|
+
in particular responseFormat, toolChoice, and tools.
|
1547
1587
|
*/
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
Providers may have limits on the number of stop sequences.
|
1559
|
-
*/
|
1560
|
-
stopSequences?: string[];
|
1561
|
-
/**
|
1562
|
-
Nucleus sampling.
|
1563
|
-
|
1564
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
1565
|
-
*/
|
1566
|
-
topP?: number;
|
1567
|
-
/**
|
1568
|
-
Only sample from the top K options for each subsequent token.
|
1569
|
-
|
1570
|
-
Used to remove "long tail" low probability responses.
|
1571
|
-
Recommended for advanced use cases only. You usually only need to use temperature.
|
1572
|
-
*/
|
1573
|
-
topK?: number;
|
1574
|
-
/**
|
1575
|
-
Presence penalty setting. It affects the likelihood of the model to
|
1576
|
-
repeat information that is already in the prompt.
|
1577
|
-
*/
|
1578
|
-
presencePenalty?: number;
|
1579
|
-
/**
|
1580
|
-
Frequency penalty setting. It affects the likelihood of the model
|
1581
|
-
to repeatedly use the same words or phrases.
|
1582
|
-
*/
|
1583
|
-
frequencyPenalty?: number;
|
1584
|
-
/**
|
1585
|
-
Response format. The output can either be text or JSON. Default is text.
|
1586
|
-
|
1587
|
-
If JSON is selected, a schema can optionally be provided to guide the LLM.
|
1588
|
-
*/
|
1589
|
-
responseFormat?: {
|
1590
|
-
type: 'text';
|
1588
|
+
mode: {
|
1589
|
+
type: 'regular';
|
1590
|
+
/**
|
1591
|
+
The tools that are available for the model.
|
1592
|
+
*/
|
1593
|
+
tools?: Array<LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool>;
|
1594
|
+
/**
|
1595
|
+
Specifies how the tool should be selected. Defaults to 'auto'.
|
1596
|
+
*/
|
1597
|
+
toolChoice?: LanguageModelV1ToolChoice;
|
1591
1598
|
} | {
|
1592
|
-
type: 'json';
|
1599
|
+
type: 'object-json';
|
1593
1600
|
/**
|
1594
1601
|
* JSON schema that the generated output should conform to.
|
1595
1602
|
*/
|
@@ -1602,48 +1609,38 @@ type LanguageModelV2CallOptions = {
|
|
1602
1609
|
* Description of the output that should be generated. Used by some providers for additional LLM guidance.
|
1603
1610
|
*/
|
1604
1611
|
description?: string;
|
1612
|
+
} | {
|
1613
|
+
type: 'object-tool';
|
1614
|
+
tool: LanguageModelV1FunctionTool;
|
1605
1615
|
};
|
1606
1616
|
/**
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
/**
|
1616
|
-
Specifies how the tool should be selected. Defaults to 'auto'.
|
1617
|
-
*/
|
1618
|
-
toolChoice?: LanguageModelV2ToolChoice;
|
1619
|
-
/**
|
1620
|
-
Abort signal for cancelling the operation.
|
1621
|
-
*/
|
1622
|
-
abortSignal?: AbortSignal;
|
1623
|
-
/**
|
1624
|
-
Additional HTTP headers to be sent with the request.
|
1625
|
-
Only applicable for HTTP-based providers.
|
1626
|
-
*/
|
1627
|
-
headers?: Record<string, string | undefined>;
|
1617
|
+
A language mode prompt is a standardized prompt type.
|
1618
|
+
|
1619
|
+
Note: This is **not** the user-facing prompt. The AI SDK methods will map the
|
1620
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
1621
|
+
That approach allows us to evolve the user facing prompts without breaking
|
1622
|
+
the language model interface.
|
1623
|
+
*/
|
1624
|
+
prompt: LanguageModelV1Prompt;
|
1628
1625
|
/**
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1626
|
+
Additional provider-specific metadata.
|
1627
|
+
The metadata is passed through to the provider from the AI SDK and enables
|
1628
|
+
provider-specific functionality that can be fully encapsulated in the provider.
|
1632
1629
|
*/
|
1633
|
-
|
1630
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1634
1631
|
};
|
1635
1632
|
|
1636
1633
|
/**
|
1637
1634
|
Warning from the model provider for this call. The call will proceed, but e.g.
|
1638
1635
|
some settings might not be supported, which can lead to suboptimal results.
|
1639
1636
|
*/
|
1640
|
-
type
|
1637
|
+
type LanguageModelV1CallWarning = {
|
1641
1638
|
type: 'unsupported-setting';
|
1642
|
-
setting:
|
1639
|
+
setting: keyof LanguageModelV1CallSettings;
|
1643
1640
|
details?: string;
|
1644
1641
|
} | {
|
1645
1642
|
type: 'unsupported-tool';
|
1646
|
-
tool:
|
1643
|
+
tool: LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool;
|
1647
1644
|
details?: string;
|
1648
1645
|
} | {
|
1649
1646
|
type: 'other';
|
@@ -1662,9 +1659,9 @@ Can be one of the following:
|
|
1662
1659
|
- `other`: model stopped for other reasons
|
1663
1660
|
- `unknown`: the model has not transmitted a finish reason
|
1664
1661
|
*/
|
1665
|
-
type
|
1662
|
+
type LanguageModelV1FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
|
1666
1663
|
|
1667
|
-
type
|
1664
|
+
type LanguageModelV1FunctionToolCall = {
|
1668
1665
|
toolCallType: 'function';
|
1669
1666
|
toolCallId: string;
|
1670
1667
|
toolName: string;
|
@@ -1678,7 +1675,7 @@ type LanguageModelV2FunctionToolCall = {
|
|
1678
1675
|
/**
|
1679
1676
|
Log probabilities for each token and its top log probabilities.
|
1680
1677
|
*/
|
1681
|
-
type
|
1678
|
+
type LanguageModelV1LogProbs = Array<{
|
1682
1679
|
token: string;
|
1683
1680
|
logprob: number;
|
1684
1681
|
topLogprobs: Array<{
|
@@ -1688,58 +1685,9 @@ type LanguageModelV2LogProbs = Array<{
|
|
1688
1685
|
}>;
|
1689
1686
|
|
1690
1687
|
/**
|
1691
|
-
|
1692
|
-
* Metadata are additional outputs from the provider.
|
1693
|
-
* They are passed through to the provider from the AI SDK
|
1694
|
-
* and enable provider-specific functionality
|
1695
|
-
* that can be fully encapsulated in the provider.
|
1696
|
-
*
|
1697
|
-
* This enables us to quickly ship provider-specific functionality
|
1698
|
-
* without affecting the core AI SDK.
|
1699
|
-
*
|
1700
|
-
* The outer record is keyed by the provider name, and the inner
|
1701
|
-
* record is keyed by the provider-specific metadata key.
|
1702
|
-
*
|
1703
|
-
* ```ts
|
1704
|
-
* {
|
1705
|
-
* "anthropic": {
|
1706
|
-
* "cacheControl": { "type": "ephemeral" }
|
1707
|
-
* }
|
1708
|
-
* }
|
1709
|
-
* ```
|
1710
|
-
*/
|
1711
|
-
type LanguageModelV2ProviderMetadata = Record<string, Record<string, JSONValue>>;
|
1712
|
-
|
1713
|
-
/**
|
1714
|
-
* A source that has been used as input to generate the response.
|
1715
|
-
*/
|
1716
|
-
type LanguageModelV2Source = {
|
1717
|
-
/**
|
1718
|
-
* A URL source. This is return by web search RAG models.
|
1719
|
-
*/
|
1720
|
-
sourceType: 'url';
|
1721
|
-
/**
|
1722
|
-
* The ID of the source.
|
1723
|
-
*/
|
1724
|
-
id: string;
|
1725
|
-
/**
|
1726
|
-
* The URL of the source.
|
1727
|
-
*/
|
1728
|
-
url: string;
|
1729
|
-
/**
|
1730
|
-
* The title of the source.
|
1731
|
-
*/
|
1732
|
-
title?: string;
|
1733
|
-
/**
|
1734
|
-
* Additional provider metadata for the source.
|
1735
|
-
*/
|
1736
|
-
providerMetadata?: LanguageModelV2ProviderMetadata;
|
1737
|
-
};
|
1738
|
-
|
1739
|
-
/**
|
1740
|
-
Specification for a language model that implements the language model interface version 2.
|
1688
|
+
Specification for a language model that implements the language model interface version 1.
|
1741
1689
|
*/
|
1742
|
-
type
|
1690
|
+
type LanguageModelV1 = {
|
1743
1691
|
/**
|
1744
1692
|
The language model must specify which language model interface
|
1745
1693
|
version it implements. This will allow us to evolve the language
|
@@ -1747,7 +1695,7 @@ type LanguageModelV2 = {
|
|
1747
1695
|
implementation versions can be handled as a discriminated union
|
1748
1696
|
on our side.
|
1749
1697
|
*/
|
1750
|
-
readonly specificationVersion: '
|
1698
|
+
readonly specificationVersion: 'v1';
|
1751
1699
|
/**
|
1752
1700
|
Name of the provider for logging purposes.
|
1753
1701
|
*/
|
@@ -1764,7 +1712,7 @@ type LanguageModelV2 = {
|
|
1764
1712
|
This is needed to generate the best objects possible w/o requiring the
|
1765
1713
|
user to explicitly specify the object generation mode.
|
1766
1714
|
*/
|
1767
|
-
readonly defaultObjectGenerationMode:
|
1715
|
+
readonly defaultObjectGenerationMode: LanguageModelV1ObjectGenerationMode;
|
1768
1716
|
/**
|
1769
1717
|
Flag whether this model supports image URLs. Default is `true`.
|
1770
1718
|
|
@@ -1803,7 +1751,7 @@ type LanguageModelV2 = {
|
|
1803
1751
|
Naming: "do" prefix to prevent accidental direct usage of the method
|
1804
1752
|
by the user.
|
1805
1753
|
*/
|
1806
|
-
doGenerate(options:
|
1754
|
+
doGenerate(options: LanguageModelV1CallOptions): PromiseLike<{
|
1807
1755
|
/**
|
1808
1756
|
Text that the model has generated.
|
1809
1757
|
Can be undefined if the model did not generate any text.
|
@@ -1839,11 +1787,11 @@ An optional signature for verifying that the reasoning originated from the model
|
|
1839
1787
|
Tool calls that the model has generated.
|
1840
1788
|
Can be undefined if the model did not generate any tool calls.
|
1841
1789
|
*/
|
1842
|
-
toolCalls?: Array<
|
1790
|
+
toolCalls?: Array<LanguageModelV1FunctionToolCall>;
|
1843
1791
|
/**
|
1844
1792
|
Finish reason.
|
1845
1793
|
*/
|
1846
|
-
finishReason:
|
1794
|
+
finishReason: LanguageModelV1FinishReason;
|
1847
1795
|
/**
|
1848
1796
|
Usage information.
|
1849
1797
|
*/
|
@@ -1906,24 +1854,24 @@ An optional signature for verifying that the reasoning originated from the model
|
|
1906
1854
|
*/
|
1907
1855
|
modelId?: string;
|
1908
1856
|
};
|
1909
|
-
warnings?:
|
1857
|
+
warnings?: LanguageModelV1CallWarning[];
|
1910
1858
|
/**
|
1911
1859
|
Additional provider-specific metadata. They are passed through
|
1912
1860
|
from the provider to the AI SDK and enable provider-specific
|
1913
1861
|
results that can be fully encapsulated in the provider.
|
1914
1862
|
*/
|
1915
|
-
providerMetadata?:
|
1863
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1916
1864
|
/**
|
1917
1865
|
Sources that have been used as input to generate the response.
|
1918
1866
|
*/
|
1919
|
-
sources?:
|
1867
|
+
sources?: LanguageModelV1Source[];
|
1920
1868
|
/**
|
1921
1869
|
Logprobs for the completion.
|
1922
1870
|
`undefined` if the mode does not support logprobs or if was not enabled
|
1923
1871
|
|
1924
1872
|
@deprecated will be changed into a provider-specific extension in v2
|
1925
1873
|
*/
|
1926
|
-
logprobs?:
|
1874
|
+
logprobs?: LanguageModelV1LogProbs;
|
1927
1875
|
}>;
|
1928
1876
|
/**
|
1929
1877
|
Generates a language model output (streaming).
|
@@ -1933,8 +1881,8 @@ An optional signature for verifying that the reasoning originated from the model
|
|
1933
1881
|
*
|
1934
1882
|
@return A stream of higher-level language model output parts.
|
1935
1883
|
*/
|
1936
|
-
doStream(options:
|
1937
|
-
stream: ReadableStream<
|
1884
|
+
doStream(options: LanguageModelV1CallOptions): PromiseLike<{
|
1885
|
+
stream: ReadableStream<LanguageModelV1StreamPart>;
|
1938
1886
|
/**
|
1939
1887
|
Raw prompt and setting information for observability provider integration.
|
1940
1888
|
*/
|
@@ -1972,10 +1920,10 @@ An optional signature for verifying that the reasoning originated from the model
|
|
1972
1920
|
/**
|
1973
1921
|
Warnings for the call, e.g. unsupported settings.
|
1974
1922
|
*/
|
1975
|
-
warnings?: Array<
|
1923
|
+
warnings?: Array<LanguageModelV1CallWarning>;
|
1976
1924
|
}>;
|
1977
1925
|
};
|
1978
|
-
type
|
1926
|
+
type LanguageModelV1StreamPart = {
|
1979
1927
|
type: 'text-delta';
|
1980
1928
|
textDelta: string;
|
1981
1929
|
} | {
|
@@ -1989,7 +1937,7 @@ type LanguageModelV2StreamPart = {
|
|
1989
1937
|
data: string;
|
1990
1938
|
} | {
|
1991
1939
|
type: 'source';
|
1992
|
-
source:
|
1940
|
+
source: LanguageModelV1Source;
|
1993
1941
|
} | {
|
1994
1942
|
type: 'file';
|
1995
1943
|
mimeType: string;
|
@@ -2003,7 +1951,7 @@ be returned as binary data.
|
|
2003
1951
|
data: string | Uint8Array;
|
2004
1952
|
} | ({
|
2005
1953
|
type: 'tool-call';
|
2006
|
-
} &
|
1954
|
+
} & LanguageModelV1FunctionToolCall) | {
|
2007
1955
|
type: 'tool-call-delta';
|
2008
1956
|
toolCallType: 'function';
|
2009
1957
|
toolCallId: string;
|
@@ -2016,13 +1964,13 @@ be returned as binary data.
|
|
2016
1964
|
modelId?: string;
|
2017
1965
|
} | {
|
2018
1966
|
type: 'finish';
|
2019
|
-
finishReason:
|
2020
|
-
providerMetadata?:
|
1967
|
+
finishReason: LanguageModelV1FinishReason;
|
1968
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
2021
1969
|
usage: {
|
2022
1970
|
promptTokens: number;
|
2023
1971
|
completionTokens: number;
|
2024
1972
|
};
|
2025
|
-
logprobs?:
|
1973
|
+
logprobs?: LanguageModelV1LogProbs;
|
2026
1974
|
} | {
|
2027
1975
|
type: 'error';
|
2028
1976
|
error: unknown;
|
@@ -2031,67 +1979,294 @@ be returned as binary data.
|
|
2031
1979
|
The object generation modes available for use with a model. `undefined`
|
2032
1980
|
represents no support for object generation.
|
2033
1981
|
*/
|
2034
|
-
type
|
1982
|
+
type LanguageModelV1ObjectGenerationMode = 'json' | 'tool' | undefined;
|
1983
|
+
|
1984
|
+
type TranscriptionModelV1ProviderOptions = Record<string, Record<string, JSONValue>>;
|
1985
|
+
type TranscriptionModelV1CallOptions = {
|
1986
|
+
/**
|
1987
|
+
Audio data to transcribe.
|
1988
|
+
Accepts a `Uint8Array` or `string`, where `string` is a base64 encoded audio file.
|
1989
|
+
*/
|
1990
|
+
audio: Uint8Array | string;
|
1991
|
+
/**
|
1992
|
+
The IANA media type of the audio data.
|
1993
|
+
|
1994
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
1995
|
+
*/
|
1996
|
+
mediaType: string;
|
1997
|
+
/**
|
1998
|
+
Additional provider-specific options that are passed through to the provider
|
1999
|
+
as body parameters.
|
2000
|
+
|
2001
|
+
The outer record is keyed by the provider name, and the inner
|
2002
|
+
record is keyed by the provider-specific metadata key.
|
2003
|
+
```ts
|
2004
|
+
{
|
2005
|
+
"openai": {
|
2006
|
+
"timestampGranularities": ["word"]
|
2007
|
+
}
|
2008
|
+
}
|
2009
|
+
```
|
2010
|
+
*/
|
2011
|
+
providerOptions?: TranscriptionModelV1ProviderOptions;
|
2012
|
+
/**
|
2013
|
+
Abort signal for cancelling the operation.
|
2014
|
+
*/
|
2015
|
+
abortSignal?: AbortSignal;
|
2016
|
+
/**
|
2017
|
+
Additional HTTP headers to be sent with the request.
|
2018
|
+
Only applicable for HTTP-based providers.
|
2019
|
+
*/
|
2020
|
+
headers?: Record<string, string | undefined>;
|
2021
|
+
};
|
2035
2022
|
|
2036
2023
|
/**
|
2037
|
-
|
2038
|
-
|
2039
|
-
* the behavior of LanguageModelV2 operations.
|
2024
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
2025
|
+
some settings might not be supported, which can lead to suboptimal results.
|
2040
2026
|
*/
|
2041
|
-
type
|
2027
|
+
type TranscriptionModelV1CallWarning = {
|
2028
|
+
type: 'unsupported-setting';
|
2029
|
+
setting: keyof TranscriptionModelV1CallOptions;
|
2030
|
+
details?: string;
|
2031
|
+
} | {
|
2032
|
+
type: 'other';
|
2033
|
+
message: string;
|
2034
|
+
};
|
2035
|
+
|
2036
|
+
/**
|
2037
|
+
Transcription model specification version 1.
|
2038
|
+
*/
|
2039
|
+
type TranscriptionModelV1 = {
|
2042
2040
|
/**
|
2043
|
-
|
2041
|
+
The transcription model must specify which transcription model interface
|
2042
|
+
version it implements. This will allow us to evolve the transcription
|
2043
|
+
model interface and retain backwards compatibility. The different
|
2044
|
+
implementation versions can be handled as a discriminated union
|
2045
|
+
on our side.
|
2044
2046
|
*/
|
2045
|
-
|
2047
|
+
readonly specificationVersion: 'v1';
|
2046
2048
|
/**
|
2047
|
-
|
2048
|
-
* @param options - Object containing the type of operation and the parameters.
|
2049
|
-
* @param options.type - The type of operation ('generate' or 'stream').
|
2050
|
-
* @param options.params - The original parameters for the language model call.
|
2051
|
-
* @returns A promise that resolves to the transformed parameters.
|
2049
|
+
Name of the provider for logging purposes.
|
2052
2050
|
*/
|
2053
|
-
|
2054
|
-
type: 'generate' | 'stream';
|
2055
|
-
params: LanguageModelV2CallOptions;
|
2056
|
-
}) => PromiseLike<LanguageModelV2CallOptions>;
|
2051
|
+
readonly provider: string;
|
2057
2052
|
/**
|
2058
|
-
|
2059
|
-
* @param options - Object containing the generate function, parameters, and model.
|
2060
|
-
* @param options.doGenerate - The original generate function.
|
2061
|
-
* @param options.doStream - The original stream function.
|
2062
|
-
* @param options.params - The parameters for the generate call. If the
|
2063
|
-
* `transformParams` middleware is used, this will be the transformed parameters.
|
2064
|
-
* @param options.model - The language model instance.
|
2065
|
-
* @returns A promise that resolves to the result of the generate operation.
|
2053
|
+
Provider-specific model ID for logging purposes.
|
2066
2054
|
*/
|
2067
|
-
|
2068
|
-
doGenerate: () => ReturnType<LanguageModelV2['doGenerate']>;
|
2069
|
-
doStream: () => ReturnType<LanguageModelV2['doStream']>;
|
2070
|
-
params: LanguageModelV2CallOptions;
|
2071
|
-
model: LanguageModelV2;
|
2072
|
-
}) => Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
|
2055
|
+
readonly modelId: string;
|
2073
2056
|
/**
|
2074
|
-
|
2057
|
+
Generates a transcript.
|
2058
|
+
*/
|
2059
|
+
doGenerate(options: TranscriptionModelV1CallOptions): PromiseLike<{
|
2060
|
+
/**
|
2061
|
+
* The complete transcribed text from the audio.
|
2062
|
+
*/
|
2063
|
+
text: string;
|
2064
|
+
/**
|
2065
|
+
* Array of transcript segments with timing information.
|
2066
|
+
* Each segment represents a portion of the transcribed text with start and end times.
|
2067
|
+
*/
|
2068
|
+
segments: Array<{
|
2069
|
+
/**
|
2070
|
+
* The text content of this segment.
|
2071
|
+
*/
|
2072
|
+
text: string;
|
2073
|
+
/**
|
2074
|
+
* The start time of this segment in seconds.
|
2075
|
+
*/
|
2076
|
+
startSecond: number;
|
2077
|
+
/**
|
2078
|
+
* The end time of this segment in seconds.
|
2079
|
+
*/
|
2080
|
+
endSecond: number;
|
2081
|
+
}>;
|
2082
|
+
/**
|
2083
|
+
* The detected language of the audio content, as an ISO-639-1 code (e.g., 'en' for English).
|
2084
|
+
* May be undefined if the language couldn't be detected.
|
2085
|
+
*/
|
2086
|
+
language: string | undefined;
|
2087
|
+
/**
|
2088
|
+
* The total duration of the audio file in seconds.
|
2089
|
+
* May be undefined if the duration couldn't be determined.
|
2090
|
+
*/
|
2091
|
+
durationInSeconds: number | undefined;
|
2092
|
+
/**
|
2093
|
+
Warnings for the call, e.g. unsupported settings.
|
2094
|
+
*/
|
2095
|
+
warnings: Array<TranscriptionModelV1CallWarning>;
|
2096
|
+
/**
|
2097
|
+
Optional request information for telemetry and debugging purposes.
|
2098
|
+
*/
|
2099
|
+
request?: {
|
2100
|
+
/**
|
2101
|
+
Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
|
2102
|
+
Non-HTTP(s) providers should not set this.
|
2103
|
+
*/
|
2104
|
+
body?: string;
|
2105
|
+
};
|
2106
|
+
/**
|
2107
|
+
Response information for telemetry and debugging purposes.
|
2108
|
+
*/
|
2109
|
+
response: {
|
2110
|
+
/**
|
2111
|
+
Timestamp for the start of the generated response.
|
2112
|
+
*/
|
2113
|
+
timestamp: Date;
|
2114
|
+
/**
|
2115
|
+
The ID of the response model that was used to generate the response.
|
2116
|
+
*/
|
2117
|
+
modelId: string;
|
2118
|
+
/**
|
2119
|
+
Response headers.
|
2120
|
+
*/
|
2121
|
+
headers?: SharedV2Headers;
|
2122
|
+
/**
|
2123
|
+
Response body.
|
2124
|
+
*/
|
2125
|
+
body?: unknown;
|
2126
|
+
};
|
2127
|
+
/**
|
2128
|
+
Additional provider-specific metadata. They are passed through
|
2129
|
+
from the provider to the AI SDK and enable provider-specific
|
2130
|
+
results that can be fully encapsulated in the provider.
|
2131
|
+
*/
|
2132
|
+
providerMetadata?: Record<string, Record<string, JSONValue>>;
|
2133
|
+
}>;
|
2134
|
+
};
|
2135
|
+
|
2136
|
+
type SpeechModelV1ProviderOptions = Record<string, Record<string, JSONValue>>;
|
2137
|
+
type SpeechModelV1CallOptions = {
|
2138
|
+
/**
|
2139
|
+
* Text to convert to speech.
|
2140
|
+
*/
|
2141
|
+
text: string;
|
2142
|
+
/**
|
2143
|
+
* The voice to use for speech synthesis.
|
2144
|
+
* This is provider-specific and may be a voice ID, name, or other identifier.
|
2145
|
+
*/
|
2146
|
+
voice?: string;
|
2147
|
+
/**
|
2148
|
+
* The desired output format for the audio e.g. "mp3", "wav", etc.
|
2149
|
+
*/
|
2150
|
+
outputFormat?: string;
|
2151
|
+
/**
|
2152
|
+
* Instructions for the speech generation e.g. "Speak in a slow and steady tone".
|
2153
|
+
*/
|
2154
|
+
instructions?: string;
|
2155
|
+
/**
|
2156
|
+
* The speed of the speech generation.
|
2157
|
+
*/
|
2158
|
+
speed?: number;
|
2159
|
+
/**
|
2160
|
+
* Additional provider-specific options that are passed through to the provider
|
2161
|
+
* as body parameters.
|
2075
2162
|
*
|
2076
|
-
*
|
2077
|
-
*
|
2078
|
-
*
|
2079
|
-
*
|
2080
|
-
*
|
2081
|
-
*
|
2082
|
-
*
|
2163
|
+
* The outer record is keyed by the provider name, and the inner
|
2164
|
+
* record is keyed by the provider-specific metadata key.
|
2165
|
+
* ```ts
|
2166
|
+
* {
|
2167
|
+
* "openai": {}
|
2168
|
+
* }
|
2169
|
+
* ```
|
2083
2170
|
*/
|
2084
|
-
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2171
|
+
providerOptions?: SpeechModelV1ProviderOptions;
|
2172
|
+
/**
|
2173
|
+
* Abort signal for cancelling the operation.
|
2174
|
+
*/
|
2175
|
+
abortSignal?: AbortSignal;
|
2176
|
+
/**
|
2177
|
+
* Additional HTTP headers to be sent with the request.
|
2178
|
+
* Only applicable for HTTP-based providers.
|
2179
|
+
*/
|
2180
|
+
headers?: Record<string, string | undefined>;
|
2181
|
+
};
|
2182
|
+
|
2183
|
+
/**
|
2184
|
+
* Warning from the model provider for this call. The call will proceed, but e.g.
|
2185
|
+
* some settings might not be supported, which can lead to suboptimal results.
|
2186
|
+
*/
|
2187
|
+
type SpeechModelV1CallWarning = {
|
2188
|
+
type: 'unsupported-setting';
|
2189
|
+
setting: keyof SpeechModelV1CallOptions;
|
2190
|
+
details?: string;
|
2191
|
+
} | {
|
2192
|
+
type: 'other';
|
2193
|
+
message: string;
|
2090
2194
|
};
|
2195
|
+
|
2091
2196
|
/**
|
2092
|
-
*
|
2197
|
+
* Speech model specification version 1.
|
2093
2198
|
*/
|
2094
|
-
type
|
2199
|
+
type SpeechModelV1 = {
|
2200
|
+
/**
|
2201
|
+
* The speech model must specify which speech model interface
|
2202
|
+
* version it implements. This will allow us to evolve the speech
|
2203
|
+
* model interface and retain backwards compatibility. The different
|
2204
|
+
* implementation versions can be handled as a discriminated union
|
2205
|
+
* on our side.
|
2206
|
+
*/
|
2207
|
+
readonly specificationVersion: 'v1';
|
2208
|
+
/**
|
2209
|
+
* Name of the provider for logging purposes.
|
2210
|
+
*/
|
2211
|
+
readonly provider: string;
|
2212
|
+
/**
|
2213
|
+
* Provider-specific model ID for logging purposes.
|
2214
|
+
*/
|
2215
|
+
readonly modelId: string;
|
2216
|
+
/**
|
2217
|
+
* Generates speech audio from text.
|
2218
|
+
*/
|
2219
|
+
doGenerate(options: SpeechModelV1CallOptions): PromiseLike<{
|
2220
|
+
/**
|
2221
|
+
* Generated audio as an ArrayBuffer.
|
2222
|
+
* The audio should be returned without any unnecessary conversion.
|
2223
|
+
* If the API returns base64 encoded strings, the audio should be returned
|
2224
|
+
* as base64 encoded strings. If the API returns binary data, the audio
|
2225
|
+
* should be returned as binary data.
|
2226
|
+
*/
|
2227
|
+
audio: string | Uint8Array;
|
2228
|
+
/**
|
2229
|
+
* Warnings for the call, e.g. unsupported settings.
|
2230
|
+
*/
|
2231
|
+
warnings: Array<SpeechModelV1CallWarning>;
|
2232
|
+
/**
|
2233
|
+
* Optional request information for telemetry and debugging purposes.
|
2234
|
+
*/
|
2235
|
+
request?: {
|
2236
|
+
/**
|
2237
|
+
* Response body (available only for providers that use HTTP requests).
|
2238
|
+
*/
|
2239
|
+
body?: unknown;
|
2240
|
+
};
|
2241
|
+
/**
|
2242
|
+
* Response information for telemetry and debugging purposes.
|
2243
|
+
*/
|
2244
|
+
response: {
|
2245
|
+
/**
|
2246
|
+
* Timestamp for the start of the generated response.
|
2247
|
+
*/
|
2248
|
+
timestamp: Date;
|
2249
|
+
/**
|
2250
|
+
* The ID of the response model that was used to generate the response.
|
2251
|
+
*/
|
2252
|
+
modelId: string;
|
2253
|
+
/**
|
2254
|
+
* Response headers.
|
2255
|
+
*/
|
2256
|
+
headers?: SharedV2Headers;
|
2257
|
+
/**
|
2258
|
+
* Response body.
|
2259
|
+
*/
|
2260
|
+
body?: unknown;
|
2261
|
+
};
|
2262
|
+
/**
|
2263
|
+
* Additional provider-specific metadata. They are passed through
|
2264
|
+
* from the provider to the AI SDK and enable provider-specific
|
2265
|
+
* results that can be fully encapsulated in the provider.
|
2266
|
+
*/
|
2267
|
+
providerMetadata?: Record<string, Record<string, JSONValue>>;
|
2268
|
+
}>;
|
2269
|
+
};
|
2095
2270
|
|
2096
2271
|
/**
|
2097
2272
|
* Provider for language, text embedding, and image generation models.
|
@@ -2118,7 +2293,7 @@ interface ProviderV1 {
|
|
2118
2293
|
|
2119
2294
|
@throws {NoSuchModelError} If no such model exists.
|
2120
2295
|
*/
|
2121
|
-
textEmbeddingModel(modelId: string):
|
2296
|
+
textEmbeddingModel(modelId: string): EmbeddingModelV2<string>;
|
2122
2297
|
/**
|
2123
2298
|
Returns the image model with the given id.
|
2124
2299
|
The model id is then passed to the provider function to get the model.
|
@@ -2127,7 +2302,25 @@ interface ProviderV1 {
|
|
2127
2302
|
|
2128
2303
|
@returns {ImageModel} The image model associated with the id
|
2129
2304
|
*/
|
2130
|
-
readonly imageModel?: (modelId: string) =>
|
2305
|
+
readonly imageModel?: (modelId: string) => ImageModelV2;
|
2306
|
+
/**
|
2307
|
+
Returns the transcription model with the given id.
|
2308
|
+
The model id is then passed to the provider function to get the model.
|
2309
|
+
|
2310
|
+
@param {string} modelId - The id of the model to return.
|
2311
|
+
|
2312
|
+
@returns {TranscriptionModel} The transcription model associated with the id
|
2313
|
+
*/
|
2314
|
+
readonly transcriptionModel?: (modelId: string) => TranscriptionModelV1;
|
2315
|
+
/**
|
2316
|
+
Returns the speech model with the given id.
|
2317
|
+
The model id is then passed to the provider function to get the model.
|
2318
|
+
|
2319
|
+
@param {string} modelId - The id of the model to return.
|
2320
|
+
|
2321
|
+
@returns {SpeechModel} The speech model associated with the id
|
2322
|
+
*/
|
2323
|
+
readonly speechModel?: (modelId: string) => SpeechModelV1;
|
2131
2324
|
}
|
2132
2325
|
|
2133
2326
|
/**
|
@@ -2155,7 +2348,7 @@ interface ProviderV2 {
|
|
2155
2348
|
|
2156
2349
|
@throws {NoSuchModelError} If no such model exists.
|
2157
2350
|
*/
|
2158
|
-
textEmbeddingModel(modelId: string):
|
2351
|
+
textEmbeddingModel(modelId: string): EmbeddingModelV2<string>;
|
2159
2352
|
/**
|
2160
2353
|
Returns the image model with the given id.
|
2161
2354
|
The model id is then passed to the provider function to get the model.
|
@@ -2164,7 +2357,7 @@ interface ProviderV2 {
|
|
2164
2357
|
|
2165
2358
|
@returns {ImageModel} The image model associated with the id
|
2166
2359
|
*/
|
2167
|
-
readonly imageModel: (modelId: string) =>
|
2360
|
+
readonly imageModel: (modelId: string) => ImageModelV2;
|
2168
2361
|
}
|
2169
2362
|
|
2170
|
-
export { AISDKError, APICallError, type
|
2363
|
+
export { AISDKError, APICallError, type EmbeddingModelV2, type EmbeddingModelV2Embedding, EmptyResponseBodyError, type ImageModelV2, type ImageModelV2CallOptions, type ImageModelV2CallWarning, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, type JSONArray, type JSONObject, JSONParseError, type JSONValue, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FilePart, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1LogProbs, type LanguageModelV1Message, type LanguageModelV1ObjectGenerationMode, type LanguageModelV1Prompt, type LanguageModelV1ProviderDefinedTool, type LanguageModelV1ProviderMetadata, type LanguageModelV1ReasoningPart, type LanguageModelV1RedactedReasoningPart, type LanguageModelV1Source, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolChoice, type LanguageModelV1ToolResultPart, type LanguageModelV2, type LanguageModelV2CallOptions, type LanguageModelV2CallWarning, type LanguageModelV2Content, type LanguageModelV2DataContent, type LanguageModelV2File, type LanguageModelV2FilePart, type LanguageModelV2FinishReason, type LanguageModelV2FunctionTool, type LanguageModelV2Message, type LanguageModelV2Middleware, type LanguageModelV2Prompt, type LanguageModelV2ProviderDefinedTool, type LanguageModelV2Reasoning, type LanguageModelV2ReasoningPart, type LanguageModelV2ResponseMetadata, type LanguageModelV2Source, type LanguageModelV2StreamPart, type LanguageModelV2Text, type LanguageModelV2TextPart, type LanguageModelV2ToolCall, type LanguageModelV2ToolCallDelta, type LanguageModelV2ToolCallPart, type LanguageModelV2ToolChoice, type LanguageModelV2ToolResultPart, type LanguageModelV2Usage, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, type ProviderV1, type ProviderV2, type SharedV2Headers, type SharedV2ProviderMetadata, type SharedV2ProviderOptions, type SpeechModelV1, type SpeechModelV1CallOptions, type SpeechModelV1CallWarning, TooManyEmbeddingValuesForCallError, type TranscriptionModelV1, type TranscriptionModelV1CallOptions, type TranscriptionModelV1CallWarning, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };
|