@ai-sdk/provider 0.0.0
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/LICENSE +13 -0
- package/README.md +1 -0
- package/dist/index.d.mts +636 -0
- package/dist/index.d.ts +636 -0
- package/dist/index.js +473 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +431 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +55 -0
package/dist/index.d.ts
ADDED
@@ -0,0 +1,636 @@
|
|
1
|
+
import { JSONSchema7 } from 'json-schema';
|
2
|
+
|
3
|
+
declare class APICallError extends Error {
|
4
|
+
readonly url: string;
|
5
|
+
readonly requestBodyValues: unknown;
|
6
|
+
readonly statusCode?: number;
|
7
|
+
readonly responseBody?: string;
|
8
|
+
readonly cause?: unknown;
|
9
|
+
readonly isRetryable: boolean;
|
10
|
+
readonly data?: unknown;
|
11
|
+
constructor({ message, url, requestBodyValues, statusCode, responseBody, cause, isRetryable, // server error
|
12
|
+
data, }: {
|
13
|
+
message: string;
|
14
|
+
url: string;
|
15
|
+
requestBodyValues: unknown;
|
16
|
+
statusCode?: number;
|
17
|
+
responseBody?: string;
|
18
|
+
cause?: unknown;
|
19
|
+
isRetryable?: boolean;
|
20
|
+
data?: unknown;
|
21
|
+
});
|
22
|
+
static isAPICallError(error: unknown): error is APICallError;
|
23
|
+
toJSON(): {
|
24
|
+
name: string;
|
25
|
+
message: string;
|
26
|
+
url: string;
|
27
|
+
requestBodyValues: unknown;
|
28
|
+
statusCode: number | undefined;
|
29
|
+
responseBody: string | undefined;
|
30
|
+
cause: unknown;
|
31
|
+
isRetryable: boolean;
|
32
|
+
data: unknown;
|
33
|
+
};
|
34
|
+
}
|
35
|
+
|
36
|
+
declare class InvalidArgumentError extends Error {
|
37
|
+
readonly parameter: string;
|
38
|
+
readonly value: unknown;
|
39
|
+
constructor({ parameter, value, message, }: {
|
40
|
+
parameter: string;
|
41
|
+
value: unknown;
|
42
|
+
message: string;
|
43
|
+
});
|
44
|
+
static isInvalidArgumentError(error: unknown): error is InvalidArgumentError;
|
45
|
+
toJSON(): {
|
46
|
+
name: string;
|
47
|
+
message: string;
|
48
|
+
stack: string | undefined;
|
49
|
+
parameter: string;
|
50
|
+
value: unknown;
|
51
|
+
};
|
52
|
+
}
|
53
|
+
|
54
|
+
declare class InvalidDataContentError extends Error {
|
55
|
+
readonly content: unknown;
|
56
|
+
constructor({ content, message, }: {
|
57
|
+
content: unknown;
|
58
|
+
message?: string;
|
59
|
+
});
|
60
|
+
static isInvalidDataContentError(error: unknown): error is InvalidDataContentError;
|
61
|
+
toJSON(): {
|
62
|
+
name: string;
|
63
|
+
message: string;
|
64
|
+
stack: string | undefined;
|
65
|
+
content: unknown;
|
66
|
+
};
|
67
|
+
}
|
68
|
+
|
69
|
+
declare class InvalidPromptError extends Error {
|
70
|
+
readonly prompt: unknown;
|
71
|
+
constructor({ prompt, message }: {
|
72
|
+
prompt: unknown;
|
73
|
+
message: string;
|
74
|
+
});
|
75
|
+
static isInvalidPromptError(error: unknown): error is InvalidPromptError;
|
76
|
+
toJSON(): {
|
77
|
+
name: string;
|
78
|
+
message: string;
|
79
|
+
stack: string | undefined;
|
80
|
+
prompt: unknown;
|
81
|
+
};
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
Server returned a response with invalid data content. This should be thrown by providers when they
|
86
|
+
cannot parse the response from the API.
|
87
|
+
*/
|
88
|
+
declare class InvalidResponseDataError extends Error {
|
89
|
+
readonly data: unknown;
|
90
|
+
constructor({ data, message, }: {
|
91
|
+
data: unknown;
|
92
|
+
message?: string;
|
93
|
+
});
|
94
|
+
static isInvalidResponseDataError(error: unknown): error is InvalidResponseDataError;
|
95
|
+
toJSON(): {
|
96
|
+
name: string;
|
97
|
+
message: string;
|
98
|
+
stack: string | undefined;
|
99
|
+
data: unknown;
|
100
|
+
};
|
101
|
+
}
|
102
|
+
|
103
|
+
declare class InvalidToolArgumentsError extends Error {
|
104
|
+
readonly toolName: string;
|
105
|
+
readonly toolArgs: string;
|
106
|
+
readonly cause: unknown;
|
107
|
+
constructor({ toolArgs, toolName, cause, message, }: {
|
108
|
+
message?: string;
|
109
|
+
toolArgs: string;
|
110
|
+
toolName: string;
|
111
|
+
cause: unknown;
|
112
|
+
});
|
113
|
+
static isInvalidToolArgumentsError(error: unknown): error is InvalidToolArgumentsError;
|
114
|
+
toJSON(): {
|
115
|
+
name: string;
|
116
|
+
message: string;
|
117
|
+
cause: unknown;
|
118
|
+
stack: string | undefined;
|
119
|
+
toolName: string;
|
120
|
+
toolArgs: string;
|
121
|
+
};
|
122
|
+
}
|
123
|
+
|
124
|
+
declare class JSONParseError extends Error {
|
125
|
+
readonly text: string;
|
126
|
+
readonly cause: unknown;
|
127
|
+
constructor({ text, cause }: {
|
128
|
+
text: string;
|
129
|
+
cause: unknown;
|
130
|
+
});
|
131
|
+
static isJSONParseError(error: unknown): error is JSONParseError;
|
132
|
+
toJSON(): {
|
133
|
+
name: string;
|
134
|
+
message: string;
|
135
|
+
cause: unknown;
|
136
|
+
stack: string | undefined;
|
137
|
+
valueText: string;
|
138
|
+
};
|
139
|
+
}
|
140
|
+
|
141
|
+
declare class LoadAPIKeyError extends Error {
|
142
|
+
constructor({ message }: {
|
143
|
+
message: string;
|
144
|
+
});
|
145
|
+
static isLoadAPIKeyError(error: unknown): error is LoadAPIKeyError;
|
146
|
+
toJSON(): {
|
147
|
+
name: string;
|
148
|
+
message: string;
|
149
|
+
};
|
150
|
+
}
|
151
|
+
|
152
|
+
declare class NoTextGeneratedError extends Error {
|
153
|
+
readonly cause: unknown;
|
154
|
+
constructor();
|
155
|
+
static isNoTextGeneratedError(error: unknown): error is NoTextGeneratedError;
|
156
|
+
toJSON(): {
|
157
|
+
name: string;
|
158
|
+
cause: unknown;
|
159
|
+
message: string;
|
160
|
+
stack: string | undefined;
|
161
|
+
};
|
162
|
+
}
|
163
|
+
|
164
|
+
declare class NoResponseBodyError extends Error {
|
165
|
+
constructor({ message }?: {
|
166
|
+
message?: string;
|
167
|
+
});
|
168
|
+
static isNoResponseBodyError(error: unknown): error is NoResponseBodyError;
|
169
|
+
toJSON(): {
|
170
|
+
name: string;
|
171
|
+
message: string;
|
172
|
+
stack: string | undefined;
|
173
|
+
};
|
174
|
+
}
|
175
|
+
|
176
|
+
declare class NoSuchToolError extends Error {
|
177
|
+
readonly toolName: string;
|
178
|
+
readonly availableTools: string[] | undefined;
|
179
|
+
constructor({ toolName, availableTools, message, }: {
|
180
|
+
toolName: string;
|
181
|
+
availableTools?: string[] | undefined;
|
182
|
+
message?: string;
|
183
|
+
});
|
184
|
+
static isNoSuchToolError(error: unknown): error is NoSuchToolError;
|
185
|
+
toJSON(): {
|
186
|
+
name: string;
|
187
|
+
message: string;
|
188
|
+
stack: string | undefined;
|
189
|
+
toolName: string;
|
190
|
+
availableTools: string[] | undefined;
|
191
|
+
};
|
192
|
+
}
|
193
|
+
|
194
|
+
type RetryErrorReason = 'maxRetriesExceeded' | 'errorNotRetryable' | 'abort';
|
195
|
+
declare class RetryError extends Error {
|
196
|
+
readonly reason: RetryErrorReason;
|
197
|
+
readonly lastError: unknown;
|
198
|
+
readonly errors: Array<unknown>;
|
199
|
+
constructor({ message, reason, errors, }: {
|
200
|
+
message: string;
|
201
|
+
reason: RetryErrorReason;
|
202
|
+
errors: Array<unknown>;
|
203
|
+
});
|
204
|
+
static isRetryError(error: unknown): error is RetryError;
|
205
|
+
toJSON(): {
|
206
|
+
name: string;
|
207
|
+
message: string;
|
208
|
+
reason: RetryErrorReason;
|
209
|
+
lastError: unknown;
|
210
|
+
errors: unknown[];
|
211
|
+
};
|
212
|
+
}
|
213
|
+
|
214
|
+
/**
|
215
|
+
A tool has a name, a description, and a set of parameters.
|
216
|
+
|
217
|
+
Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
218
|
+
map the user-facing tool definitions to this format.
|
219
|
+
*/
|
220
|
+
type LanguageModelV1FunctionTool = {
|
221
|
+
/**
|
222
|
+
The type of the tool. Only functions for now, but this gives us room to
|
223
|
+
add more specific tool types in the future and use a discriminated union.
|
224
|
+
*/
|
225
|
+
type: 'function';
|
226
|
+
/**
|
227
|
+
The name of the tool. Unique within this model call.
|
228
|
+
*/
|
229
|
+
name: string;
|
230
|
+
description?: string;
|
231
|
+
parameters: JSONSchema7;
|
232
|
+
};
|
233
|
+
|
234
|
+
declare class ToolCallParseError extends Error {
|
235
|
+
readonly cause: unknown;
|
236
|
+
readonly text: string;
|
237
|
+
readonly tools: LanguageModelV1FunctionTool[];
|
238
|
+
constructor({ cause, text, tools, message, }: {
|
239
|
+
cause: unknown;
|
240
|
+
text: string;
|
241
|
+
tools: LanguageModelV1FunctionTool[];
|
242
|
+
message?: string;
|
243
|
+
});
|
244
|
+
static isToolCallParseError(error: unknown): error is ToolCallParseError;
|
245
|
+
toJSON(): {
|
246
|
+
name: string;
|
247
|
+
message: string;
|
248
|
+
stack: string | undefined;
|
249
|
+
cause: unknown;
|
250
|
+
text: string;
|
251
|
+
tools: LanguageModelV1FunctionTool[];
|
252
|
+
};
|
253
|
+
}
|
254
|
+
|
255
|
+
declare class TypeValidationError extends Error {
|
256
|
+
readonly value: unknown;
|
257
|
+
readonly cause: unknown;
|
258
|
+
constructor({ value, cause }: {
|
259
|
+
value: unknown;
|
260
|
+
cause: unknown;
|
261
|
+
});
|
262
|
+
static isTypeValidationError(error: unknown): error is TypeValidationError;
|
263
|
+
toJSON(): {
|
264
|
+
name: string;
|
265
|
+
message: string;
|
266
|
+
cause: unknown;
|
267
|
+
stack: string | undefined;
|
268
|
+
value: unknown;
|
269
|
+
};
|
270
|
+
}
|
271
|
+
|
272
|
+
declare class UnsupportedFunctionalityError extends Error {
|
273
|
+
readonly functionality: string;
|
274
|
+
constructor({ functionality }: {
|
275
|
+
functionality: string;
|
276
|
+
});
|
277
|
+
static isUnsupportedFunctionalityError(error: unknown): error is UnsupportedFunctionalityError;
|
278
|
+
toJSON(): {
|
279
|
+
name: string;
|
280
|
+
message: string;
|
281
|
+
stack: string | undefined;
|
282
|
+
functionality: string;
|
283
|
+
};
|
284
|
+
}
|
285
|
+
|
286
|
+
declare class UnsupportedJSONSchemaError extends Error {
|
287
|
+
readonly reason: string;
|
288
|
+
readonly schema: unknown;
|
289
|
+
constructor({ schema, reason, message, }: {
|
290
|
+
schema: unknown;
|
291
|
+
reason: string;
|
292
|
+
message?: string;
|
293
|
+
});
|
294
|
+
static isUnsupportedJSONSchemaError(error: unknown): error is UnsupportedJSONSchemaError;
|
295
|
+
toJSON(): {
|
296
|
+
name: string;
|
297
|
+
message: string;
|
298
|
+
stack: string | undefined;
|
299
|
+
reason: string;
|
300
|
+
schema: unknown;
|
301
|
+
};
|
302
|
+
}
|
303
|
+
|
304
|
+
type LanguageModelV1CallSettings = {
|
305
|
+
/**
|
306
|
+
* Maximum number of tokens to generate.
|
307
|
+
*/
|
308
|
+
maxTokens?: number;
|
309
|
+
/**
|
310
|
+
* Temperature setting. This is a number between 0 (almost no randomness) and
|
311
|
+
* 1 (very random).
|
312
|
+
*
|
313
|
+
* Different LLM providers have different temperature
|
314
|
+
* scales, so they'd need to map it (without mapping, the same temperature has
|
315
|
+
* different effects on different models). The provider can also chose to map
|
316
|
+
* this to topP, potentially even using a custom setting on their model.
|
317
|
+
*
|
318
|
+
* Note: This is an example of a setting that requires a clear specification of
|
319
|
+
* the semantics.
|
320
|
+
*/
|
321
|
+
temperature?: number;
|
322
|
+
/**
|
323
|
+
* Nucleus sampling. This is a number between 0 and 1.
|
324
|
+
*
|
325
|
+
* E.g. 0.1 would mean that only tokens with the top 10% probability mass
|
326
|
+
* are considered.
|
327
|
+
*
|
328
|
+
* It is recommended to set either `temperature` or `topP`, but not both.
|
329
|
+
*/
|
330
|
+
topP?: number;
|
331
|
+
/**
|
332
|
+
* Presence penalty setting. It affects the likelihood of the model to
|
333
|
+
* repeat information that is already in the prompt.
|
334
|
+
*
|
335
|
+
* The presence penalty is a number between -1 (increase repetition)
|
336
|
+
* and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
337
|
+
*/
|
338
|
+
presencePenalty?: number;
|
339
|
+
/**
|
340
|
+
* Frequency penalty setting. It affects the likelihood of the model
|
341
|
+
* to repeatedly use the same words or phrases.
|
342
|
+
*
|
343
|
+
* The frequency penalty is a number between -1 (increase repetition)
|
344
|
+
* and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
345
|
+
*/
|
346
|
+
frequencyPenalty?: number;
|
347
|
+
/**
|
348
|
+
* The seed (integer) to use for random sampling. If set and supported
|
349
|
+
* by the model, calls will generate deterministic results.
|
350
|
+
*/
|
351
|
+
seed?: number;
|
352
|
+
/**
|
353
|
+
* Abort signal for cancelling the operation.
|
354
|
+
*/
|
355
|
+
abortSignal?: AbortSignal;
|
356
|
+
};
|
357
|
+
|
358
|
+
/**
|
359
|
+
A prompt is a list of messages.
|
360
|
+
|
361
|
+
Note: Not all models and prompt formats support multi-modal inputs and
|
362
|
+
tool calls. The validation happens at runtime.
|
363
|
+
|
364
|
+
Note: This is not a user-facing prompt. The AI SDK methods will map the
|
365
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
366
|
+
*/
|
367
|
+
type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
|
368
|
+
type LanguageModelV1Message = {
|
369
|
+
role: 'system';
|
370
|
+
content: string;
|
371
|
+
} | {
|
372
|
+
role: 'user';
|
373
|
+
content: Array<LanguageModelV1TextPart | LanguageModelV1ImagePart>;
|
374
|
+
} | {
|
375
|
+
role: 'assistant';
|
376
|
+
content: Array<LanguageModelV1TextPart | LanguageModelV1ToolCallPart>;
|
377
|
+
} | {
|
378
|
+
role: 'tool';
|
379
|
+
content: Array<LanguageModelV1ToolResultPart>;
|
380
|
+
};
|
381
|
+
/**
|
382
|
+
Text content part of a prompt. It contains a string of text.
|
383
|
+
*/
|
384
|
+
interface LanguageModelV1TextPart {
|
385
|
+
type: 'text';
|
386
|
+
/**
|
387
|
+
The text content.
|
388
|
+
*/
|
389
|
+
text: string;
|
390
|
+
}
|
391
|
+
/**
|
392
|
+
Image content part of a prompt. It contains an image.
|
393
|
+
*/
|
394
|
+
interface LanguageModelV1ImagePart {
|
395
|
+
type: 'image';
|
396
|
+
/**
|
397
|
+
Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
|
398
|
+
*/
|
399
|
+
image: Uint8Array | URL;
|
400
|
+
/**
|
401
|
+
Optional mime type of the image.
|
402
|
+
*/
|
403
|
+
mimeType?: string;
|
404
|
+
}
|
405
|
+
/**
|
406
|
+
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
407
|
+
*/
|
408
|
+
interface LanguageModelV1ToolCallPart {
|
409
|
+
type: 'tool-call';
|
410
|
+
/**
|
411
|
+
ID of the tool call. This ID is used to match the tool call with the tool result.
|
412
|
+
*/
|
413
|
+
toolCallId: string;
|
414
|
+
/**
|
415
|
+
Name of the tool that is being called.
|
416
|
+
*/
|
417
|
+
toolName: string;
|
418
|
+
/**
|
419
|
+
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
420
|
+
*/
|
421
|
+
args: unknown;
|
422
|
+
}
|
423
|
+
/**
|
424
|
+
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
425
|
+
*/
|
426
|
+
interface LanguageModelV1ToolResultPart {
|
427
|
+
type: 'tool-result';
|
428
|
+
/**
|
429
|
+
ID of the tool call that this result is associated with.
|
430
|
+
*/
|
431
|
+
toolCallId: string;
|
432
|
+
/**
|
433
|
+
Name of the tool that generated this result.
|
434
|
+
*/
|
435
|
+
toolName: string;
|
436
|
+
/**
|
437
|
+
Result of the tool call. This is a JSON-serializable object.
|
438
|
+
*/
|
439
|
+
result: unknown;
|
440
|
+
/**
|
441
|
+
Optional flag if the result is an error or an error message.
|
442
|
+
*/
|
443
|
+
isError?: boolean;
|
444
|
+
}
|
445
|
+
|
446
|
+
type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
|
447
|
+
/**
|
448
|
+
* Whether the user provided the input as messages or as
|
449
|
+
* a prompt. This can help guide non-chat models in the
|
450
|
+
* expansion, bc different expansions can be needed for
|
451
|
+
* chat/non-chat use cases.
|
452
|
+
*/
|
453
|
+
inputFormat: 'messages' | 'prompt';
|
454
|
+
/**
|
455
|
+
* The mode affects the behavior of the language model. It is required to
|
456
|
+
* support provider-independent streaming and generation of structured objects.
|
457
|
+
* The model can take this information and e.g. configure json mode, the correct
|
458
|
+
* low level grammar, etc. It can also be used to optimize the efficiency of the
|
459
|
+
* streaming, e.g. tool-delta stream parts are only needed in the
|
460
|
+
* object-tool mode.
|
461
|
+
*/
|
462
|
+
mode: {
|
463
|
+
type: 'regular';
|
464
|
+
tools?: Array<LanguageModelV1FunctionTool>;
|
465
|
+
} | {
|
466
|
+
type: 'object-json';
|
467
|
+
} | {
|
468
|
+
type: 'object-grammar';
|
469
|
+
schema: JSONSchema7;
|
470
|
+
} | {
|
471
|
+
type: 'object-tool';
|
472
|
+
tool: LanguageModelV1FunctionTool;
|
473
|
+
};
|
474
|
+
/**
|
475
|
+
* A language mode prompt is a standardized prompt type.
|
476
|
+
*
|
477
|
+
* Note: This is **not** the user-facing prompt. The AI SDK methods will map the
|
478
|
+
* user-facing prompt types such as chat or instruction prompts to this format.
|
479
|
+
* That approach allows us to evolve the user facing prompts without breaking
|
480
|
+
* the language model interface.
|
481
|
+
*/
|
482
|
+
prompt: LanguageModelV1Prompt;
|
483
|
+
};
|
484
|
+
|
485
|
+
/**
|
486
|
+
* Warning from the model provider for this call. The call will proceed, but e.g.
|
487
|
+
* some settings might not be supported, which can lead to suboptimal results.
|
488
|
+
*/
|
489
|
+
type LanguageModelV1CallWarning = {
|
490
|
+
type: 'unsupported-setting';
|
491
|
+
setting: keyof LanguageModelV1CallSettings;
|
492
|
+
} | {
|
493
|
+
type: 'other';
|
494
|
+
message: string;
|
495
|
+
};
|
496
|
+
|
497
|
+
type LanguageModelV1FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other';
|
498
|
+
|
499
|
+
type LanguageModelV1FunctionToolCall = {
|
500
|
+
toolCallType: 'function';
|
501
|
+
toolCallId: string;
|
502
|
+
toolName: string;
|
503
|
+
/**
|
504
|
+
* Stringified JSON object with the tool call arguments. Must match the
|
505
|
+
* parameters schema of the tool.
|
506
|
+
*/
|
507
|
+
args: string;
|
508
|
+
};
|
509
|
+
|
510
|
+
/**
|
511
|
+
* Experimental: Specification for a language model that implements the language model
|
512
|
+
* interface version 1.
|
513
|
+
*/
|
514
|
+
type LanguageModelV1 = {
|
515
|
+
/**
|
516
|
+
* The language model must specify which language model interface
|
517
|
+
* version it implements. This will allow us to evolve the language
|
518
|
+
* model interface and retain backwards compatibility. The different
|
519
|
+
* implementation versions can be handled as a discriminated union
|
520
|
+
* on our side.
|
521
|
+
*/
|
522
|
+
readonly specificationVersion: 'v1';
|
523
|
+
/**
|
524
|
+
* Name of the provider for logging purposes.
|
525
|
+
*/
|
526
|
+
readonly provider: string;
|
527
|
+
/**
|
528
|
+
* Provider-specific model ID for logging purposes.
|
529
|
+
*/
|
530
|
+
readonly modelId: string;
|
531
|
+
/**
|
532
|
+
* Default object generation mode that should be used with this model when
|
533
|
+
* no mode is specified. Should be the mode with the best results for this
|
534
|
+
* model. `undefined` can be returned if object generation is not supported.
|
535
|
+
*
|
536
|
+
* This is needed to generate the best objects possible w/o requiring the
|
537
|
+
* user to explicitly specify the object generation mode.
|
538
|
+
*/
|
539
|
+
readonly defaultObjectGenerationMode: 'json' | 'tool' | 'grammar' | undefined;
|
540
|
+
/**
|
541
|
+
* Generates a language model output (non-streaming).
|
542
|
+
*
|
543
|
+
* Naming: "do" prefix to prevent accidental direct usage of the method
|
544
|
+
* by the user.
|
545
|
+
*/
|
546
|
+
doGenerate(options: LanguageModelV1CallOptions): PromiseLike<{
|
547
|
+
/**
|
548
|
+
* Text that the model has generated. Can be undefined if the model
|
549
|
+
* has only generated tool calls.
|
550
|
+
*/
|
551
|
+
text?: string;
|
552
|
+
/**
|
553
|
+
* Tool calls that the model has generated. Can be undefined if the
|
554
|
+
* model has only generated text.
|
555
|
+
*/
|
556
|
+
toolCalls?: Array<LanguageModelV1FunctionToolCall>;
|
557
|
+
/**
|
558
|
+
* Finish reason.
|
559
|
+
*/
|
560
|
+
finishReason: LanguageModelV1FinishReason;
|
561
|
+
/**
|
562
|
+
* Usage information.
|
563
|
+
*/
|
564
|
+
usage: {
|
565
|
+
promptTokens: number;
|
566
|
+
completionTokens: number;
|
567
|
+
};
|
568
|
+
/**
|
569
|
+
* Raw prompt and setting information for observability provider integration.
|
570
|
+
*/
|
571
|
+
rawCall: {
|
572
|
+
/**
|
573
|
+
* Raw prompt after expansion and conversion to the format that the
|
574
|
+
* provider uses to send the information to their API.
|
575
|
+
*/
|
576
|
+
rawPrompt: unknown;
|
577
|
+
/**
|
578
|
+
* Raw settings that are used for the API call. Includes provider-specific
|
579
|
+
* settings.
|
580
|
+
*/
|
581
|
+
rawSettings: Record<string, unknown>;
|
582
|
+
};
|
583
|
+
warnings?: LanguageModelV1CallWarning[];
|
584
|
+
}>;
|
585
|
+
/**
|
586
|
+
* Generates a language model output (streaming).
|
587
|
+
*
|
588
|
+
* Naming: "do" prefix to prevent accidental direct usage of the method
|
589
|
+
* by the user.
|
590
|
+
*
|
591
|
+
* @return A stream of higher-level language model output parts.
|
592
|
+
*/
|
593
|
+
doStream(options: LanguageModelV1CallOptions): PromiseLike<{
|
594
|
+
stream: ReadableStream<LanguageModelV1StreamPart>;
|
595
|
+
/**
|
596
|
+
* Raw prompt and setting information for observability provider integration.
|
597
|
+
*/
|
598
|
+
rawCall: {
|
599
|
+
/**
|
600
|
+
* Raw prompt after expansion and conversion to the format that the
|
601
|
+
* provider uses to send the information to their API.
|
602
|
+
*/
|
603
|
+
rawPrompt: unknown;
|
604
|
+
/**
|
605
|
+
* Raw settings that are used for the API call. Includes provider-specific
|
606
|
+
* settings.
|
607
|
+
*/
|
608
|
+
rawSettings: Record<string, unknown>;
|
609
|
+
};
|
610
|
+
warnings?: LanguageModelV1CallWarning[];
|
611
|
+
}>;
|
612
|
+
};
|
613
|
+
type LanguageModelV1StreamPart = {
|
614
|
+
type: 'text-delta';
|
615
|
+
textDelta: string;
|
616
|
+
} | ({
|
617
|
+
type: 'tool-call';
|
618
|
+
} & LanguageModelV1FunctionToolCall) | {
|
619
|
+
type: 'tool-call-delta';
|
620
|
+
toolCallType: 'function';
|
621
|
+
toolCallId: string;
|
622
|
+
toolName: string;
|
623
|
+
argsTextDelta: string;
|
624
|
+
} | {
|
625
|
+
type: 'finish';
|
626
|
+
finishReason: LanguageModelV1FinishReason;
|
627
|
+
usage: {
|
628
|
+
promptTokens: number;
|
629
|
+
completionTokens: number;
|
630
|
+
};
|
631
|
+
} | {
|
632
|
+
type: 'error';
|
633
|
+
error: unknown;
|
634
|
+
};
|
635
|
+
|
636
|
+
export { APICallError, InvalidArgumentError, InvalidDataContentError, InvalidPromptError, InvalidResponseDataError, InvalidToolArgumentsError, JSONParseError, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1Message, type LanguageModelV1Prompt, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolResultPart, LoadAPIKeyError, NoResponseBodyError, NoSuchToolError, NoTextGeneratedError, RetryError, type RetryErrorReason, ToolCallParseError, TypeValidationError, UnsupportedFunctionalityError, UnsupportedJSONSchemaError };
|