ai 7.0.93 → 7.0.94
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 +17 -0
- package/dist/index.d.ts +63 -62
- package/dist/index.js +260 -123
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +3 -2
- package/dist/internal/index.js +7 -4
- package/dist/internal/index.js.map +1 -1
- package/docs/02-foundations/02-providers-and-models.mdx +0 -1
- package/docs/03-ai-sdk-core/35-image-generation.mdx +2 -0
- package/docs/03-ai-sdk-core/37-speech.mdx +0 -17
- package/docs/07-reference/01-ai-sdk-core/10-generate-image.mdx +2 -1
- package/package.json +12 -12
- package/src/batch/batch-types.ts +76 -68
- package/src/batch/batch.ts +169 -101
- package/src/batch/index.ts +9 -7
- package/src/generate-image/generate-image.ts +50 -9
- package/src/generate-text/stream-language-model-call.ts +82 -0
- package/src/generate-text/stream-text.ts +5 -1
- package/src/util/prepare-retries.ts +7 -1
- package/src/util/retry-with-exponential-backoff.ts +9 -4
|
@@ -44,7 +44,6 @@ The AI SDK comes with a wide range of providers that you can use to interact wit
|
|
|
44
44
|
- [Groq Provider](/providers/ai-sdk-providers/groq) (`@ai-sdk/groq`)
|
|
45
45
|
- [Perplexity Provider](/providers/ai-sdk-providers/perplexity) (`@ai-sdk/perplexity`)
|
|
46
46
|
- [ElevenLabs Provider](/providers/ai-sdk-providers/elevenlabs) (`@ai-sdk/elevenlabs`)
|
|
47
|
-
- [LMNT Provider](/providers/ai-sdk-providers/lmnt) (`@ai-sdk/lmnt`)
|
|
48
47
|
- [Hume Provider](/providers/ai-sdk-providers/hume) (`@ai-sdk/hume`)
|
|
49
48
|
- [Rev.ai Provider](/providers/ai-sdk-providers/revai) (`@ai-sdk/revai`)
|
|
50
49
|
- [Deepgram Provider](/providers/ai-sdk-providers/deepgram) (`@ai-sdk/deepgram`)
|
|
@@ -222,6 +222,8 @@ for (const call of calls) {
|
|
|
222
222
|
### Error Handling
|
|
223
223
|
|
|
224
224
|
When `generateImage` cannot generate a valid image, it throws a [`AI_NoImageGeneratedError`](/docs/reference/ai-sdk-errors/ai-no-image-generated-error).
|
|
225
|
+
Unclassified empty image responses are retried according to `maxRetries` before this error is thrown.
|
|
226
|
+
Providers can classify terminal empty responses, such as moderation blocks, with `isRetryable: false`; these responses are not retried.
|
|
225
227
|
|
|
226
228
|
This error occurs when the AI provider fails to generate an image. It can arise due to the following reasons:
|
|
227
229
|
|
|
@@ -19,21 +19,6 @@ const audio = await generateSpeech({
|
|
|
19
19
|
});
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
### Language Setting
|
|
23
|
-
|
|
24
|
-
You can specify the language for speech generation (provider support varies):
|
|
25
|
-
|
|
26
|
-
```ts
|
|
27
|
-
import { generateSpeech } from 'ai';
|
|
28
|
-
import { lmnt } from '@ai-sdk/lmnt';
|
|
29
|
-
|
|
30
|
-
const audio = await generateSpeech({
|
|
31
|
-
model: lmnt.speech('aurora'),
|
|
32
|
-
text: 'Hola, mundo!',
|
|
33
|
-
language: 'es', // Spanish
|
|
34
|
-
});
|
|
35
|
-
```
|
|
36
|
-
|
|
37
22
|
To access the generated audio:
|
|
38
23
|
|
|
39
24
|
```ts
|
|
@@ -158,8 +143,6 @@ try {
|
|
|
158
143
|
| [ElevenLabs](/providers/ai-sdk-providers/elevenlabs#speech-models) | `eleven_flash_v2` |
|
|
159
144
|
| [ElevenLabs](/providers/ai-sdk-providers/elevenlabs#speech-models) | `eleven_turbo_v2_5` |
|
|
160
145
|
| [ElevenLabs](/providers/ai-sdk-providers/elevenlabs#speech-models) | `eleven_turbo_v2` |
|
|
161
|
-
| [LMNT](/providers/ai-sdk-providers/lmnt#speech-models) | `aurora` |
|
|
162
|
-
| [LMNT](/providers/ai-sdk-providers/lmnt#speech-models) | `blizzard` |
|
|
163
146
|
| [Hume](/providers/ai-sdk-providers/hume#speech-models) | `default` |
|
|
164
147
|
| [Google](/providers/ai-sdk-providers/google#speech-models) | `gemini-2.5-flash-preview-tts` |
|
|
165
148
|
| [Google](/providers/ai-sdk-providers/google#speech-models) | `gemini-2.5-pro-preview-tts` |
|
|
@@ -113,7 +113,8 @@ console.log(images);
|
|
|
113
113
|
name: 'maxRetries',
|
|
114
114
|
type: 'number',
|
|
115
115
|
isOptional: true,
|
|
116
|
-
description:
|
|
116
|
+
description:
|
|
117
|
+
'Maximum number of retries per image model call, including retries after unclassified empty responses. Empty responses marked as not retryable by the provider are not retried. Default: 2.',
|
|
117
118
|
},
|
|
118
119
|
{
|
|
119
120
|
name: 'abortSignal',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.94",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -42,20 +42,20 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ai-sdk/gateway": "4.0.
|
|
46
|
-
"@ai-sdk/provider": "4.0.
|
|
47
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
45
|
+
"@ai-sdk/gateway": "4.0.76",
|
|
46
|
+
"@ai-sdk/provider": "4.0.11",
|
|
47
|
+
"@ai-sdk/provider-utils": "5.0.37"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@ai-sdk/amazon-bedrock": "5.0.
|
|
51
|
-
"@ai-sdk/deepseek": "3.0.
|
|
52
|
-
"@ai-sdk/google": "4.0.
|
|
53
|
-
"@ai-sdk/groq": "4.0.
|
|
54
|
-
"@ai-sdk/huggingface": "2.0.
|
|
55
|
-
"@ai-sdk/moonshotai": "3.0.
|
|
56
|
-
"@ai-sdk/openai": "4.0.
|
|
50
|
+
"@ai-sdk/amazon-bedrock": "5.0.77",
|
|
51
|
+
"@ai-sdk/deepseek": "3.0.40",
|
|
52
|
+
"@ai-sdk/google": "4.0.65",
|
|
53
|
+
"@ai-sdk/groq": "4.0.38",
|
|
54
|
+
"@ai-sdk/huggingface": "2.0.45",
|
|
55
|
+
"@ai-sdk/moonshotai": "3.0.46",
|
|
56
|
+
"@ai-sdk/openai": "4.0.61",
|
|
57
57
|
"@ai-sdk/test-server": "2.0.1",
|
|
58
|
-
"@ai-sdk/xai": "4.0.
|
|
58
|
+
"@ai-sdk/xai": "4.0.55",
|
|
59
59
|
"@edge-runtime/vm": "^5.0.0",
|
|
60
60
|
"@smithy/eventstream-codec": "^4.3.3",
|
|
61
61
|
"@smithy/util-utf8": "^4.3.3",
|
package/src/batch/batch-types.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
Experimental_BatchV4 as BatchV4,
|
|
2
3
|
Experimental_BatchV4Error as BatchV4Error,
|
|
4
|
+
Experimental_BatchV4ModelIds as BatchV4ModelIds,
|
|
3
5
|
Experimental_BatchV4StartResult as BatchV4StartResult,
|
|
4
6
|
Experimental_BatchV4Status as BatchV4Status,
|
|
5
|
-
|
|
7
|
+
ProviderV4,
|
|
6
8
|
} from '@ai-sdk/provider';
|
|
7
9
|
import type {
|
|
8
10
|
InferToolSetContext,
|
|
@@ -13,40 +15,31 @@ import type { ContentPart } from '../generate-text/content-part';
|
|
|
13
15
|
import type { ToolOrder } from '../generate-text/tool-order';
|
|
14
16
|
import type { LanguageModelCallOptions } from '../prompt/language-model-call-options';
|
|
15
17
|
import type { Prompt } from '../prompt/prompt';
|
|
16
|
-
import type {
|
|
17
|
-
FinishReason,
|
|
18
|
-
GlobalProviderModelId,
|
|
19
|
-
ToolChoice,
|
|
20
|
-
} from '../types/language-model';
|
|
18
|
+
import type { FinishReason, ToolChoice } from '../types/language-model';
|
|
21
19
|
import type { ProviderMetadata } from '../types/provider-metadata';
|
|
22
20
|
import type { LanguageModelUsage } from '../types/usage';
|
|
23
21
|
|
|
24
22
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* String model IDs are resolved through the global provider and checked for
|
|
28
|
-
* batch support at runtime.
|
|
23
|
+
* Provider or lower-level batch interface used for batch processing.
|
|
29
24
|
*/
|
|
30
|
-
export type
|
|
25
|
+
export type BatchProvider = ProviderV4 | BatchV4;
|
|
26
|
+
|
|
27
|
+
type InferBatchModelIds<PROVIDER extends BatchProvider> =
|
|
28
|
+
PROVIDER extends BatchV4<infer MODEL_IDS>
|
|
29
|
+
? MODEL_IDS
|
|
30
|
+
: PROVIDER extends { experimental_batch(): BatchV4<infer MODEL_IDS> }
|
|
31
|
+
? MODEL_IDS
|
|
32
|
+
: BatchV4ModelIds;
|
|
31
33
|
|
|
32
34
|
/**
|
|
33
|
-
* The persisted reference for a
|
|
35
|
+
* The persisted reference for a batch.
|
|
34
36
|
*/
|
|
35
|
-
export type
|
|
36
|
-
readonly version:
|
|
37
|
-
readonly type: 'text';
|
|
37
|
+
export type BatchReference = {
|
|
38
|
+
readonly version: 2;
|
|
38
39
|
readonly id: string;
|
|
39
40
|
readonly provider: string;
|
|
40
|
-
readonly modelId: string;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
/**
|
|
44
|
-
* Persisted reference for any supported batch type.
|
|
45
|
-
*
|
|
46
|
-
* Additional modality-specific references can be added to this union.
|
|
47
|
-
*/
|
|
48
|
-
export type BatchReference = TextBatchReference;
|
|
49
|
-
|
|
50
43
|
/**
|
|
51
44
|
* Serializable error information for a batch or batch item.
|
|
52
45
|
*/
|
|
@@ -58,55 +51,55 @@ export type BatchError = BatchV4Error;
|
|
|
58
51
|
export type BatchStatus = BatchV4Status;
|
|
59
52
|
|
|
60
53
|
/**
|
|
61
|
-
* A
|
|
54
|
+
* A batch and its latest normalized lifecycle status.
|
|
62
55
|
*/
|
|
63
|
-
export type
|
|
56
|
+
export type Batch = BatchReference & BatchStatus;
|
|
64
57
|
|
|
65
58
|
/**
|
|
66
59
|
* One text generation request within a batch.
|
|
67
60
|
*/
|
|
68
|
-
export type TextBatchRequest
|
|
61
|
+
export type TextBatchRequest<
|
|
62
|
+
ModelId extends string = string,
|
|
63
|
+
TOOLS extends ToolSet = ToolSet,
|
|
64
|
+
> = Prompt &
|
|
69
65
|
LanguageModelCallOptions & {
|
|
70
66
|
id: string;
|
|
67
|
+
type: 'text';
|
|
68
|
+
model: ModelId;
|
|
69
|
+
tools?: TOOLS;
|
|
70
|
+
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
|
71
|
+
toolOrder?: ToolOrder<TOOLS>;
|
|
72
|
+
toolsContext?: InferToolSetContext<TOOLS>;
|
|
71
73
|
providerOptions?: ProviderOptions;
|
|
72
74
|
};
|
|
73
75
|
|
|
74
|
-
|
|
76
|
+
/**
|
|
77
|
+
* One request within a batch, discriminated by modality.
|
|
78
|
+
*/
|
|
79
|
+
export type BatchRequest<
|
|
80
|
+
ModelIds extends BatchV4ModelIds = BatchV4ModelIds,
|
|
81
|
+
TOOLS extends ToolSet = ToolSet,
|
|
82
|
+
> = TextBatchRequest<ModelIds['text'], TOOLS>;
|
|
83
|
+
|
|
84
|
+
type BatchCallOptions = {
|
|
75
85
|
abortSignal?: AbortSignal;
|
|
76
86
|
headers?: Record<string, string | undefined>;
|
|
77
87
|
timeout?: number | { totalMs?: number };
|
|
78
88
|
};
|
|
79
89
|
|
|
80
90
|
/**
|
|
81
|
-
* Options for starting a
|
|
91
|
+
* Options for starting a batch.
|
|
82
92
|
*/
|
|
83
|
-
export type
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Tools that the model can call for every request in the batch.
|
|
89
|
-
*
|
|
90
|
-
* Tool definitions are sent to the provider, but their `execute` functions
|
|
91
|
-
* are never invoked by batch processing.
|
|
92
|
-
*/
|
|
93
|
-
tools?: TOOLS;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* The tool choice strategy. Default: 'auto'.
|
|
97
|
-
*/
|
|
98
|
-
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
|
99
|
-
|
|
93
|
+
export type StartBatchOptions<
|
|
94
|
+
TOOLS extends ToolSet = ToolSet,
|
|
95
|
+
PROVIDER extends BatchProvider = BatchProvider,
|
|
96
|
+
> = {
|
|
100
97
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
98
|
+
* Provider used to process the batch. Defaults to the global provider, or
|
|
99
|
+
* the Vercel AI Gateway when no global provider is configured.
|
|
103
100
|
*/
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Context used when resolving dynamic tool descriptions.
|
|
108
|
-
*/
|
|
109
|
-
toolsContext?: InferToolSetContext<TOOLS>;
|
|
101
|
+
provider?: PROVIDER;
|
|
102
|
+
requests: ReadonlyArray<BatchRequest<InferBatchModelIds<PROVIDER>, TOOLS>>;
|
|
110
103
|
|
|
111
104
|
providerOptions?: ProviderOptions;
|
|
112
105
|
|
|
@@ -116,33 +109,42 @@ export type StartTextBatchOptions<TOOLS extends ToolSet = ToolSet> = {
|
|
|
116
109
|
* unsupported warning.
|
|
117
110
|
*/
|
|
118
111
|
webhookUrl?: string;
|
|
119
|
-
} &
|
|
112
|
+
} & BatchCallOptions;
|
|
120
113
|
|
|
121
114
|
/**
|
|
122
|
-
* The acknowledged
|
|
115
|
+
* The acknowledged batch and warnings produced while starting it.
|
|
123
116
|
*/
|
|
124
|
-
export type
|
|
117
|
+
export type StartBatchResult = Batch & {
|
|
125
118
|
readonly warnings: BatchV4StartResult['warnings'];
|
|
126
119
|
};
|
|
127
120
|
|
|
128
121
|
/**
|
|
129
|
-
* Options
|
|
122
|
+
* Options for retrieving batch status.
|
|
130
123
|
*/
|
|
131
|
-
export type
|
|
132
|
-
model: BatchLanguageModel;
|
|
133
|
-
batch: BatchReference;
|
|
134
|
-
|
|
124
|
+
export type GetBatchStatusOptions = {
|
|
135
125
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* The definitions are used only to validate and normalize returned tool
|
|
139
|
-
* calls. Their `execute` functions are never invoked.
|
|
126
|
+
* Provider used to access the batch. Defaults to the global provider, or
|
|
127
|
+
* the Vercel AI Gateway when no global provider is configured.
|
|
140
128
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
129
|
+
provider?: BatchProvider;
|
|
130
|
+
batch: BatchReference;
|
|
143
131
|
providerOptions?: ProviderOptions;
|
|
144
132
|
maxRetries?: number;
|
|
145
|
-
} &
|
|
133
|
+
} & BatchCallOptions;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Options for retrieving batch results.
|
|
137
|
+
*/
|
|
138
|
+
export type GetBatchResultsOptions<TOOLS extends ToolSet = ToolSet> =
|
|
139
|
+
GetBatchStatusOptions & {
|
|
140
|
+
/**
|
|
141
|
+
* Definitions for client tools that were provided to `startBatch` requests.
|
|
142
|
+
*
|
|
143
|
+
* The definitions are used only to validate and normalize returned tool
|
|
144
|
+
* calls. Their `execute` functions are never invoked.
|
|
145
|
+
*/
|
|
146
|
+
tools?: TOOLS;
|
|
147
|
+
};
|
|
146
148
|
|
|
147
149
|
/**
|
|
148
150
|
* A normalized result for a successful text batch item.
|
|
@@ -182,3 +184,9 @@ export type TextBatchItemResult<TOOLS extends ToolSet = ToolSet> =
|
|
|
182
184
|
readonly error?: BatchError;
|
|
183
185
|
readonly providerMetadata?: ProviderMetadata;
|
|
184
186
|
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* A complete terminal result for one request in a batch.
|
|
190
|
+
*/
|
|
191
|
+
export type BatchItemResult<TOOLS extends ToolSet = ToolSet> =
|
|
192
|
+
TextBatchItemResult<TOOLS>;
|