@ai-sdk/openai 2.0.0-canary.11 → 2.0.0-canary.13
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 +28 -0
- package/dist/index.d.mts +15 -63
- package/dist/index.d.ts +15 -63
- package/dist/index.js +299 -240
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +304 -244
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +51 -57
- package/dist/internal/index.d.ts +51 -57
- package/dist/internal/index.js +295 -227
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +297 -231
- package/dist/internal/index.mjs.map +1 -1
- package/internal.d.ts +1 -0
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -266,7 +266,13 @@ var openaiProviderOptions = import_zod.z.object({
|
|
|
266
266
|
/**
|
|
267
267
|
* Parameters for prediction mode.
|
|
268
268
|
*/
|
|
269
|
-
prediction: import_zod.z.record(import_zod.z.any()).optional()
|
|
269
|
+
prediction: import_zod.z.record(import_zod.z.any()).optional(),
|
|
270
|
+
/**
|
|
271
|
+
* Whether to use structured outputs.
|
|
272
|
+
*
|
|
273
|
+
* @default true
|
|
274
|
+
*/
|
|
275
|
+
structuredOutputs: import_zod.z.boolean().optional()
|
|
270
276
|
});
|
|
271
277
|
|
|
272
278
|
// src/openai-error.ts
|
|
@@ -347,10 +353,9 @@ function prepareTools({
|
|
|
347
353
|
|
|
348
354
|
// src/openai-chat-language-model.ts
|
|
349
355
|
var OpenAIChatLanguageModel = class {
|
|
350
|
-
constructor(modelId,
|
|
356
|
+
constructor(modelId, config) {
|
|
351
357
|
this.specificationVersion = "v2";
|
|
352
358
|
this.modelId = modelId;
|
|
353
|
-
this.settings = settings;
|
|
354
359
|
this.config = config;
|
|
355
360
|
}
|
|
356
361
|
get provider() {
|
|
@@ -361,7 +366,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
361
366
|
"image/*": [/^https?:\/\/.*$/]
|
|
362
367
|
};
|
|
363
368
|
}
|
|
364
|
-
getArgs({
|
|
369
|
+
async getArgs({
|
|
365
370
|
prompt,
|
|
366
371
|
maxOutputTokens,
|
|
367
372
|
temperature,
|
|
@@ -378,18 +383,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
378
383
|
}) {
|
|
379
384
|
var _a, _b, _c;
|
|
380
385
|
const warnings = [];
|
|
381
|
-
const openaiOptions = (_a = (0, import_provider_utils3.parseProviderOptions)({
|
|
386
|
+
const openaiOptions = (_a = await (0, import_provider_utils3.parseProviderOptions)({
|
|
382
387
|
provider: "openai",
|
|
383
388
|
providerOptions,
|
|
384
389
|
schema: openaiProviderOptions
|
|
385
390
|
})) != null ? _a : {};
|
|
391
|
+
const structuredOutputs = (_b = openaiOptions.structuredOutputs) != null ? _b : true;
|
|
386
392
|
if (topK != null) {
|
|
387
393
|
warnings.push({
|
|
388
394
|
type: "unsupported-setting",
|
|
389
395
|
setting: "topK"
|
|
390
396
|
});
|
|
391
397
|
}
|
|
392
|
-
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !
|
|
398
|
+
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !structuredOutputs) {
|
|
393
399
|
warnings.push({
|
|
394
400
|
type: "unsupported-setting",
|
|
395
401
|
setting: "responseFormat",
|
|
@@ -418,12 +424,12 @@ var OpenAIChatLanguageModel = class {
|
|
|
418
424
|
presence_penalty: presencePenalty,
|
|
419
425
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? (
|
|
420
426
|
// TODO convert into provider option
|
|
421
|
-
|
|
427
|
+
structuredOutputs && responseFormat.schema != null ? {
|
|
422
428
|
type: "json_schema",
|
|
423
429
|
json_schema: {
|
|
424
430
|
schema: responseFormat.schema,
|
|
425
431
|
strict: true,
|
|
426
|
-
name: (
|
|
432
|
+
name: (_c = responseFormat.name) != null ? _c : "response",
|
|
427
433
|
description: responseFormat.description
|
|
428
434
|
}
|
|
429
435
|
} : { type: "json_object" }
|
|
@@ -503,7 +509,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
503
509
|
} = prepareTools({
|
|
504
510
|
tools,
|
|
505
511
|
toolChoice,
|
|
506
|
-
structuredOutputs
|
|
512
|
+
structuredOutputs
|
|
507
513
|
});
|
|
508
514
|
return {
|
|
509
515
|
args: {
|
|
@@ -516,7 +522,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
516
522
|
}
|
|
517
523
|
async doGenerate(options) {
|
|
518
524
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
519
|
-
const { args: body, warnings } = this.getArgs(options);
|
|
525
|
+
const { args: body, warnings } = await this.getArgs(options);
|
|
520
526
|
const {
|
|
521
527
|
responseHeaders,
|
|
522
528
|
value: response,
|
|
@@ -583,7 +589,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
583
589
|
};
|
|
584
590
|
}
|
|
585
591
|
async doStream(options) {
|
|
586
|
-
const { args, warnings } = this.getArgs(options);
|
|
592
|
+
const { args, warnings } = await this.getArgs(options);
|
|
587
593
|
const body = {
|
|
588
594
|
...args,
|
|
589
595
|
stream: true,
|
|
@@ -873,19 +879,15 @@ var reasoningModels = {
|
|
|
873
879
|
|
|
874
880
|
// src/openai-completion-language-model.ts
|
|
875
881
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
876
|
-
var
|
|
882
|
+
var import_zod5 = require("zod");
|
|
877
883
|
|
|
878
884
|
// src/convert-to-openai-completion-prompt.ts
|
|
879
885
|
var import_provider4 = require("@ai-sdk/provider");
|
|
880
886
|
function convertToOpenAICompletionPrompt({
|
|
881
887
|
prompt,
|
|
882
|
-
inputFormat,
|
|
883
888
|
user = "user",
|
|
884
889
|
assistant = "assistant"
|
|
885
890
|
}) {
|
|
886
|
-
if (inputFormat === "prompt" && prompt.length === 1 && prompt[0].role === "user" && prompt[0].content.length === 1 && prompt[0].content[0].type === "text") {
|
|
887
|
-
return { prompt: prompt[0].content[0].text };
|
|
888
|
-
}
|
|
889
891
|
let text = "";
|
|
890
892
|
if (prompt[0].role === "system") {
|
|
891
893
|
text += `${prompt[0].content}
|
|
@@ -954,14 +956,49 @@ ${user}:`]
|
|
|
954
956
|
};
|
|
955
957
|
}
|
|
956
958
|
|
|
959
|
+
// src/openai-completion-options.ts
|
|
960
|
+
var import_zod4 = require("zod");
|
|
961
|
+
var openaiCompletionProviderOptions = import_zod4.z.object({
|
|
962
|
+
/**
|
|
963
|
+
Echo back the prompt in addition to the completion.
|
|
964
|
+
*/
|
|
965
|
+
echo: import_zod4.z.boolean().optional(),
|
|
966
|
+
/**
|
|
967
|
+
Modify the likelihood of specified tokens appearing in the completion.
|
|
968
|
+
|
|
969
|
+
Accepts a JSON object that maps tokens (specified by their token ID in
|
|
970
|
+
the GPT tokenizer) to an associated bias value from -100 to 100. You
|
|
971
|
+
can use this tokenizer tool to convert text to token IDs. Mathematically,
|
|
972
|
+
the bias is added to the logits generated by the model prior to sampling.
|
|
973
|
+
The exact effect will vary per model, but values between -1 and 1 should
|
|
974
|
+
decrease or increase likelihood of selection; values like -100 or 100
|
|
975
|
+
should result in a ban or exclusive selection of the relevant token.
|
|
976
|
+
|
|
977
|
+
As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
|
|
978
|
+
token from being generated.
|
|
979
|
+
*/
|
|
980
|
+
logitBias: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.number()).optional(),
|
|
981
|
+
/**
|
|
982
|
+
The suffix that comes after a completion of inserted text.
|
|
983
|
+
*/
|
|
984
|
+
suffix: import_zod4.z.string().optional(),
|
|
985
|
+
/**
|
|
986
|
+
A unique identifier representing your end-user, which can help OpenAI to
|
|
987
|
+
monitor and detect abuse. Learn more.
|
|
988
|
+
*/
|
|
989
|
+
user: import_zod4.z.string().optional()
|
|
990
|
+
});
|
|
991
|
+
|
|
957
992
|
// src/openai-completion-language-model.ts
|
|
958
993
|
var OpenAICompletionLanguageModel = class {
|
|
959
|
-
constructor(modelId,
|
|
994
|
+
constructor(modelId, config) {
|
|
960
995
|
this.specificationVersion = "v2";
|
|
961
996
|
this.modelId = modelId;
|
|
962
|
-
this.settings = settings;
|
|
963
997
|
this.config = config;
|
|
964
998
|
}
|
|
999
|
+
get providerOptionsName() {
|
|
1000
|
+
return this.config.provider.split(".")[0].trim();
|
|
1001
|
+
}
|
|
965
1002
|
get provider() {
|
|
966
1003
|
return this.config.provider;
|
|
967
1004
|
}
|
|
@@ -970,8 +1007,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
970
1007
|
// no supported urls for completion models
|
|
971
1008
|
};
|
|
972
1009
|
}
|
|
973
|
-
getArgs({
|
|
974
|
-
inputFormat,
|
|
1010
|
+
async getArgs({
|
|
975
1011
|
prompt,
|
|
976
1012
|
maxOutputTokens,
|
|
977
1013
|
temperature,
|
|
@@ -983,9 +1019,22 @@ var OpenAICompletionLanguageModel = class {
|
|
|
983
1019
|
responseFormat,
|
|
984
1020
|
tools,
|
|
985
1021
|
toolChoice,
|
|
986
|
-
seed
|
|
1022
|
+
seed,
|
|
1023
|
+
providerOptions
|
|
987
1024
|
}) {
|
|
988
1025
|
const warnings = [];
|
|
1026
|
+
const openaiOptions = {
|
|
1027
|
+
...await (0, import_provider_utils4.parseProviderOptions)({
|
|
1028
|
+
provider: "openai",
|
|
1029
|
+
providerOptions,
|
|
1030
|
+
schema: openaiCompletionProviderOptions
|
|
1031
|
+
}),
|
|
1032
|
+
...await (0, import_provider_utils4.parseProviderOptions)({
|
|
1033
|
+
provider: this.providerOptionsName,
|
|
1034
|
+
providerOptions,
|
|
1035
|
+
schema: openaiCompletionProviderOptions
|
|
1036
|
+
})
|
|
1037
|
+
};
|
|
989
1038
|
if (topK != null) {
|
|
990
1039
|
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
991
1040
|
}
|
|
@@ -1002,17 +1051,17 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1002
1051
|
details: "JSON response format is not supported."
|
|
1003
1052
|
});
|
|
1004
1053
|
}
|
|
1005
|
-
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt
|
|
1054
|
+
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt });
|
|
1006
1055
|
const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
|
|
1007
1056
|
return {
|
|
1008
1057
|
args: {
|
|
1009
1058
|
// model id:
|
|
1010
1059
|
model: this.modelId,
|
|
1011
1060
|
// model specific settings:
|
|
1012
|
-
echo:
|
|
1013
|
-
logit_bias:
|
|
1014
|
-
suffix:
|
|
1015
|
-
user:
|
|
1061
|
+
echo: openaiOptions.echo,
|
|
1062
|
+
logit_bias: openaiOptions.logitBias,
|
|
1063
|
+
suffix: openaiOptions.suffix,
|
|
1064
|
+
user: openaiOptions.user,
|
|
1016
1065
|
// standardized settings:
|
|
1017
1066
|
max_tokens: maxOutputTokens,
|
|
1018
1067
|
temperature,
|
|
@@ -1029,7 +1078,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1029
1078
|
};
|
|
1030
1079
|
}
|
|
1031
1080
|
async doGenerate(options) {
|
|
1032
|
-
const { args, warnings } = this.getArgs(options);
|
|
1081
|
+
const { args, warnings } = await this.getArgs(options);
|
|
1033
1082
|
const {
|
|
1034
1083
|
responseHeaders,
|
|
1035
1084
|
value: response,
|
|
@@ -1066,7 +1115,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1066
1115
|
};
|
|
1067
1116
|
}
|
|
1068
1117
|
async doStream(options) {
|
|
1069
|
-
const { args, warnings } = this.getArgs(options);
|
|
1118
|
+
const { args, warnings } = await this.getArgs(options);
|
|
1070
1119
|
const body = {
|
|
1071
1120
|
...args,
|
|
1072
1121
|
stream: true,
|
|
@@ -1147,36 +1196,36 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1147
1196
|
};
|
|
1148
1197
|
}
|
|
1149
1198
|
};
|
|
1150
|
-
var openaiCompletionResponseSchema =
|
|
1151
|
-
id:
|
|
1152
|
-
created:
|
|
1153
|
-
model:
|
|
1154
|
-
choices:
|
|
1155
|
-
|
|
1156
|
-
text:
|
|
1157
|
-
finish_reason:
|
|
1199
|
+
var openaiCompletionResponseSchema = import_zod5.z.object({
|
|
1200
|
+
id: import_zod5.z.string().nullish(),
|
|
1201
|
+
created: import_zod5.z.number().nullish(),
|
|
1202
|
+
model: import_zod5.z.string().nullish(),
|
|
1203
|
+
choices: import_zod5.z.array(
|
|
1204
|
+
import_zod5.z.object({
|
|
1205
|
+
text: import_zod5.z.string(),
|
|
1206
|
+
finish_reason: import_zod5.z.string()
|
|
1158
1207
|
})
|
|
1159
1208
|
),
|
|
1160
|
-
usage:
|
|
1161
|
-
prompt_tokens:
|
|
1162
|
-
completion_tokens:
|
|
1209
|
+
usage: import_zod5.z.object({
|
|
1210
|
+
prompt_tokens: import_zod5.z.number(),
|
|
1211
|
+
completion_tokens: import_zod5.z.number()
|
|
1163
1212
|
})
|
|
1164
1213
|
});
|
|
1165
|
-
var openaiCompletionChunkSchema =
|
|
1166
|
-
|
|
1167
|
-
id:
|
|
1168
|
-
created:
|
|
1169
|
-
model:
|
|
1170
|
-
choices:
|
|
1171
|
-
|
|
1172
|
-
text:
|
|
1173
|
-
finish_reason:
|
|
1174
|
-
index:
|
|
1214
|
+
var openaiCompletionChunkSchema = import_zod5.z.union([
|
|
1215
|
+
import_zod5.z.object({
|
|
1216
|
+
id: import_zod5.z.string().nullish(),
|
|
1217
|
+
created: import_zod5.z.number().nullish(),
|
|
1218
|
+
model: import_zod5.z.string().nullish(),
|
|
1219
|
+
choices: import_zod5.z.array(
|
|
1220
|
+
import_zod5.z.object({
|
|
1221
|
+
text: import_zod5.z.string(),
|
|
1222
|
+
finish_reason: import_zod5.z.string().nullish(),
|
|
1223
|
+
index: import_zod5.z.number()
|
|
1175
1224
|
})
|
|
1176
1225
|
),
|
|
1177
|
-
usage:
|
|
1178
|
-
prompt_tokens:
|
|
1179
|
-
completion_tokens:
|
|
1226
|
+
usage: import_zod5.z.object({
|
|
1227
|
+
prompt_tokens: import_zod5.z.number(),
|
|
1228
|
+
completion_tokens: import_zod5.z.number()
|
|
1180
1229
|
}).nullish()
|
|
1181
1230
|
}),
|
|
1182
1231
|
openaiErrorDataSchema
|
|
@@ -1185,42 +1234,35 @@ var openaiCompletionChunkSchema = import_zod4.z.union([
|
|
|
1185
1234
|
// src/openai-embedding-model.ts
|
|
1186
1235
|
var import_provider5 = require("@ai-sdk/provider");
|
|
1187
1236
|
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
1188
|
-
var
|
|
1237
|
+
var import_zod7 = require("zod");
|
|
1189
1238
|
|
|
1190
1239
|
// src/openai-embedding-options.ts
|
|
1191
|
-
var
|
|
1192
|
-
var openaiEmbeddingProviderOptions =
|
|
1240
|
+
var import_zod6 = require("zod");
|
|
1241
|
+
var openaiEmbeddingProviderOptions = import_zod6.z.object({
|
|
1193
1242
|
/**
|
|
1194
1243
|
The number of dimensions the resulting output embeddings should have.
|
|
1195
1244
|
Only supported in text-embedding-3 and later models.
|
|
1196
1245
|
*/
|
|
1197
|
-
dimensions:
|
|
1246
|
+
dimensions: import_zod6.z.number().optional(),
|
|
1198
1247
|
/**
|
|
1199
1248
|
A unique identifier representing your end-user, which can help OpenAI to
|
|
1200
1249
|
monitor and detect abuse. Learn more.
|
|
1201
1250
|
*/
|
|
1202
|
-
user:
|
|
1251
|
+
user: import_zod6.z.string().optional()
|
|
1203
1252
|
});
|
|
1204
1253
|
|
|
1205
1254
|
// src/openai-embedding-model.ts
|
|
1206
1255
|
var OpenAIEmbeddingModel = class {
|
|
1207
|
-
constructor(modelId,
|
|
1256
|
+
constructor(modelId, config) {
|
|
1208
1257
|
this.specificationVersion = "v2";
|
|
1258
|
+
this.maxEmbeddingsPerCall = 2048;
|
|
1259
|
+
this.supportsParallelCalls = true;
|
|
1209
1260
|
this.modelId = modelId;
|
|
1210
|
-
this.settings = settings;
|
|
1211
1261
|
this.config = config;
|
|
1212
1262
|
}
|
|
1213
1263
|
get provider() {
|
|
1214
1264
|
return this.config.provider;
|
|
1215
1265
|
}
|
|
1216
|
-
get maxEmbeddingsPerCall() {
|
|
1217
|
-
var _a;
|
|
1218
|
-
return (_a = this.settings.maxEmbeddingsPerCall) != null ? _a : 2048;
|
|
1219
|
-
}
|
|
1220
|
-
get supportsParallelCalls() {
|
|
1221
|
-
var _a;
|
|
1222
|
-
return (_a = this.settings.supportsParallelCalls) != null ? _a : true;
|
|
1223
|
-
}
|
|
1224
1266
|
async doEmbed({
|
|
1225
1267
|
values,
|
|
1226
1268
|
headers,
|
|
@@ -1236,7 +1278,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1236
1278
|
values
|
|
1237
1279
|
});
|
|
1238
1280
|
}
|
|
1239
|
-
const openaiOptions = (_a = (0, import_provider_utils5.parseProviderOptions)({
|
|
1281
|
+
const openaiOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
|
|
1240
1282
|
provider: "openai",
|
|
1241
1283
|
providerOptions,
|
|
1242
1284
|
schema: openaiEmbeddingProviderOptions
|
|
@@ -1272,20 +1314,22 @@ var OpenAIEmbeddingModel = class {
|
|
|
1272
1314
|
};
|
|
1273
1315
|
}
|
|
1274
1316
|
};
|
|
1275
|
-
var openaiTextEmbeddingResponseSchema =
|
|
1276
|
-
data:
|
|
1277
|
-
usage:
|
|
1317
|
+
var openaiTextEmbeddingResponseSchema = import_zod7.z.object({
|
|
1318
|
+
data: import_zod7.z.array(import_zod7.z.object({ embedding: import_zod7.z.array(import_zod7.z.number()) })),
|
|
1319
|
+
usage: import_zod7.z.object({ prompt_tokens: import_zod7.z.number() }).nullish()
|
|
1278
1320
|
});
|
|
1279
1321
|
|
|
1280
1322
|
// src/openai-image-model.ts
|
|
1281
1323
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1282
|
-
var
|
|
1324
|
+
var import_zod8 = require("zod");
|
|
1283
1325
|
|
|
1284
1326
|
// src/openai-image-settings.ts
|
|
1285
1327
|
var modelMaxImagesPerCall = {
|
|
1286
1328
|
"dall-e-3": 1,
|
|
1287
|
-
"dall-e-2": 10
|
|
1329
|
+
"dall-e-2": 10,
|
|
1330
|
+
"gpt-image-1": 10
|
|
1288
1331
|
};
|
|
1332
|
+
var hasDefaultResponseFormat = /* @__PURE__ */ new Set(["gpt-image-1"]);
|
|
1289
1333
|
|
|
1290
1334
|
// src/openai-image-model.ts
|
|
1291
1335
|
var OpenAIImageModel = class {
|
|
@@ -1337,7 +1381,7 @@ var OpenAIImageModel = class {
|
|
|
1337
1381
|
n,
|
|
1338
1382
|
size,
|
|
1339
1383
|
...(_d = providerOptions.openai) != null ? _d : {},
|
|
1340
|
-
response_format: "b64_json"
|
|
1384
|
+
...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
|
|
1341
1385
|
},
|
|
1342
1386
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1343
1387
|
successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
|
|
@@ -1357,13 +1401,13 @@ var OpenAIImageModel = class {
|
|
|
1357
1401
|
};
|
|
1358
1402
|
}
|
|
1359
1403
|
};
|
|
1360
|
-
var openaiImageResponseSchema =
|
|
1361
|
-
data:
|
|
1404
|
+
var openaiImageResponseSchema = import_zod8.z.object({
|
|
1405
|
+
data: import_zod8.z.array(import_zod8.z.object({ b64_json: import_zod8.z.string() }))
|
|
1362
1406
|
});
|
|
1363
1407
|
|
|
1364
1408
|
// src/openai-tools.ts
|
|
1365
|
-
var
|
|
1366
|
-
var WebSearchPreviewParameters =
|
|
1409
|
+
var import_zod9 = require("zod");
|
|
1410
|
+
var WebSearchPreviewParameters = import_zod9.z.object({});
|
|
1367
1411
|
function webSearchPreviewTool({
|
|
1368
1412
|
searchContextSize,
|
|
1369
1413
|
userLocation
|
|
@@ -1384,14 +1428,36 @@ var openaiTools = {
|
|
|
1384
1428
|
|
|
1385
1429
|
// src/openai-transcription-model.ts
|
|
1386
1430
|
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1387
|
-
var
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1431
|
+
var import_zod11 = require("zod");
|
|
1432
|
+
|
|
1433
|
+
// src/openai-transcription-options.ts
|
|
1434
|
+
var import_zod10 = require("zod");
|
|
1435
|
+
var openAITranscriptionProviderOptions = import_zod10.z.object({
|
|
1436
|
+
/**
|
|
1437
|
+
* Additional information to include in the transcription response.
|
|
1438
|
+
*/
|
|
1439
|
+
include: import_zod10.z.array(import_zod10.z.string()).nullish(),
|
|
1440
|
+
/**
|
|
1441
|
+
* The language of the input audio in ISO-639-1 format.
|
|
1442
|
+
*/
|
|
1443
|
+
language: import_zod10.z.string().nullish(),
|
|
1444
|
+
/**
|
|
1445
|
+
* An optional text to guide the model's style or continue a previous audio segment.
|
|
1446
|
+
*/
|
|
1447
|
+
prompt: import_zod10.z.string().nullish(),
|
|
1448
|
+
/**
|
|
1449
|
+
* The sampling temperature, between 0 and 1.
|
|
1450
|
+
* @default 0
|
|
1451
|
+
*/
|
|
1452
|
+
temperature: import_zod10.z.number().min(0).max(1).default(0).nullish(),
|
|
1453
|
+
/**
|
|
1454
|
+
* The timestamp granularities to populate for this transcription.
|
|
1455
|
+
* @default ['segment']
|
|
1456
|
+
*/
|
|
1457
|
+
timestampGranularities: import_zod10.z.array(import_zod10.z.enum(["word", "segment"])).default(["segment"]).nullish()
|
|
1394
1458
|
});
|
|
1459
|
+
|
|
1460
|
+
// src/openai-transcription-model.ts
|
|
1395
1461
|
var languageMap = {
|
|
1396
1462
|
afrikaans: "af",
|
|
1397
1463
|
arabic: "ar",
|
|
@@ -1460,17 +1526,16 @@ var OpenAITranscriptionModel = class {
|
|
|
1460
1526
|
get provider() {
|
|
1461
1527
|
return this.config.provider;
|
|
1462
1528
|
}
|
|
1463
|
-
getArgs({
|
|
1529
|
+
async getArgs({
|
|
1464
1530
|
audio,
|
|
1465
1531
|
mediaType,
|
|
1466
1532
|
providerOptions
|
|
1467
1533
|
}) {
|
|
1468
|
-
var _a, _b, _c, _d, _e;
|
|
1469
1534
|
const warnings = [];
|
|
1470
|
-
const openAIOptions = (0, import_provider_utils7.parseProviderOptions)({
|
|
1535
|
+
const openAIOptions = await (0, import_provider_utils7.parseProviderOptions)({
|
|
1471
1536
|
provider: "openai",
|
|
1472
1537
|
providerOptions,
|
|
1473
|
-
schema:
|
|
1538
|
+
schema: openAITranscriptionProviderOptions
|
|
1474
1539
|
});
|
|
1475
1540
|
const formData = new FormData();
|
|
1476
1541
|
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils7.convertBase64ToUint8Array)(audio)]);
|
|
@@ -1478,15 +1543,14 @@ var OpenAITranscriptionModel = class {
|
|
|
1478
1543
|
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
1479
1544
|
if (openAIOptions) {
|
|
1480
1545
|
const transcriptionModelOptions = {
|
|
1481
|
-
include:
|
|
1482
|
-
language:
|
|
1483
|
-
prompt:
|
|
1484
|
-
temperature:
|
|
1485
|
-
timestamp_granularities:
|
|
1546
|
+
include: openAIOptions.include,
|
|
1547
|
+
language: openAIOptions.language,
|
|
1548
|
+
prompt: openAIOptions.prompt,
|
|
1549
|
+
temperature: openAIOptions.temperature,
|
|
1550
|
+
timestamp_granularities: openAIOptions.timestampGranularities
|
|
1486
1551
|
};
|
|
1487
|
-
for (const key
|
|
1488
|
-
|
|
1489
|
-
if (value !== void 0) {
|
|
1552
|
+
for (const [key, value] of Object.entries(transcriptionModelOptions)) {
|
|
1553
|
+
if (value != null) {
|
|
1490
1554
|
formData.append(key, String(value));
|
|
1491
1555
|
}
|
|
1492
1556
|
}
|
|
@@ -1499,7 +1563,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1499
1563
|
async doGenerate(options) {
|
|
1500
1564
|
var _a, _b, _c, _d, _e, _f;
|
|
1501
1565
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1502
|
-
const { formData, warnings } = this.getArgs(options);
|
|
1566
|
+
const { formData, warnings } = await this.getArgs(options);
|
|
1503
1567
|
const {
|
|
1504
1568
|
value: response,
|
|
1505
1569
|
responseHeaders,
|
|
@@ -1538,22 +1602,22 @@ var OpenAITranscriptionModel = class {
|
|
|
1538
1602
|
};
|
|
1539
1603
|
}
|
|
1540
1604
|
};
|
|
1541
|
-
var openaiTranscriptionResponseSchema =
|
|
1542
|
-
text:
|
|
1543
|
-
language:
|
|
1544
|
-
duration:
|
|
1545
|
-
words:
|
|
1546
|
-
|
|
1547
|
-
word:
|
|
1548
|
-
start:
|
|
1549
|
-
end:
|
|
1605
|
+
var openaiTranscriptionResponseSchema = import_zod11.z.object({
|
|
1606
|
+
text: import_zod11.z.string(),
|
|
1607
|
+
language: import_zod11.z.string().nullish(),
|
|
1608
|
+
duration: import_zod11.z.number().nullish(),
|
|
1609
|
+
words: import_zod11.z.array(
|
|
1610
|
+
import_zod11.z.object({
|
|
1611
|
+
word: import_zod11.z.string(),
|
|
1612
|
+
start: import_zod11.z.number(),
|
|
1613
|
+
end: import_zod11.z.number()
|
|
1550
1614
|
})
|
|
1551
1615
|
).nullish()
|
|
1552
1616
|
});
|
|
1553
1617
|
|
|
1554
1618
|
// src/responses/openai-responses-language-model.ts
|
|
1555
1619
|
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1556
|
-
var
|
|
1620
|
+
var import_zod12 = require("zod");
|
|
1557
1621
|
|
|
1558
1622
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1559
1623
|
var import_provider6 = require("@ai-sdk/provider");
|
|
@@ -1773,7 +1837,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1773
1837
|
get provider() {
|
|
1774
1838
|
return this.config.provider;
|
|
1775
1839
|
}
|
|
1776
|
-
getArgs({
|
|
1840
|
+
async getArgs({
|
|
1777
1841
|
maxOutputTokens,
|
|
1778
1842
|
temperature,
|
|
1779
1843
|
stopSequences,
|
|
@@ -1817,7 +1881,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1817
1881
|
systemMessageMode: modelConfig.systemMessageMode
|
|
1818
1882
|
});
|
|
1819
1883
|
warnings.push(...messageWarnings);
|
|
1820
|
-
const openaiOptions = (0, import_provider_utils8.parseProviderOptions)({
|
|
1884
|
+
const openaiOptions = await (0, import_provider_utils8.parseProviderOptions)({
|
|
1821
1885
|
provider: "openai",
|
|
1822
1886
|
providerOptions,
|
|
1823
1887
|
schema: openaiResponsesProviderOptionsSchema
|
|
@@ -1900,7 +1964,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1900
1964
|
}
|
|
1901
1965
|
async doGenerate(options) {
|
|
1902
1966
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1903
|
-
const { args: body, warnings } = this.getArgs(options);
|
|
1967
|
+
const { args: body, warnings } = await this.getArgs(options);
|
|
1904
1968
|
const {
|
|
1905
1969
|
responseHeaders,
|
|
1906
1970
|
value: response,
|
|
@@ -1914,55 +1978,55 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1914
1978
|
body,
|
|
1915
1979
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1916
1980
|
successfulResponseHandler: (0, import_provider_utils8.createJsonResponseHandler)(
|
|
1917
|
-
|
|
1918
|
-
id:
|
|
1919
|
-
created_at:
|
|
1920
|
-
model:
|
|
1921
|
-
output:
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
type:
|
|
1925
|
-
role:
|
|
1926
|
-
content:
|
|
1927
|
-
|
|
1928
|
-
type:
|
|
1929
|
-
text:
|
|
1930
|
-
annotations:
|
|
1931
|
-
|
|
1932
|
-
type:
|
|
1933
|
-
start_index:
|
|
1934
|
-
end_index:
|
|
1935
|
-
url:
|
|
1936
|
-
title:
|
|
1981
|
+
import_zod12.z.object({
|
|
1982
|
+
id: import_zod12.z.string(),
|
|
1983
|
+
created_at: import_zod12.z.number(),
|
|
1984
|
+
model: import_zod12.z.string(),
|
|
1985
|
+
output: import_zod12.z.array(
|
|
1986
|
+
import_zod12.z.discriminatedUnion("type", [
|
|
1987
|
+
import_zod12.z.object({
|
|
1988
|
+
type: import_zod12.z.literal("message"),
|
|
1989
|
+
role: import_zod12.z.literal("assistant"),
|
|
1990
|
+
content: import_zod12.z.array(
|
|
1991
|
+
import_zod12.z.object({
|
|
1992
|
+
type: import_zod12.z.literal("output_text"),
|
|
1993
|
+
text: import_zod12.z.string(),
|
|
1994
|
+
annotations: import_zod12.z.array(
|
|
1995
|
+
import_zod12.z.object({
|
|
1996
|
+
type: import_zod12.z.literal("url_citation"),
|
|
1997
|
+
start_index: import_zod12.z.number(),
|
|
1998
|
+
end_index: import_zod12.z.number(),
|
|
1999
|
+
url: import_zod12.z.string(),
|
|
2000
|
+
title: import_zod12.z.string()
|
|
1937
2001
|
})
|
|
1938
2002
|
)
|
|
1939
2003
|
})
|
|
1940
2004
|
)
|
|
1941
2005
|
}),
|
|
1942
|
-
|
|
1943
|
-
type:
|
|
1944
|
-
call_id:
|
|
1945
|
-
name:
|
|
1946
|
-
arguments:
|
|
2006
|
+
import_zod12.z.object({
|
|
2007
|
+
type: import_zod12.z.literal("function_call"),
|
|
2008
|
+
call_id: import_zod12.z.string(),
|
|
2009
|
+
name: import_zod12.z.string(),
|
|
2010
|
+
arguments: import_zod12.z.string()
|
|
1947
2011
|
}),
|
|
1948
|
-
|
|
1949
|
-
type:
|
|
2012
|
+
import_zod12.z.object({
|
|
2013
|
+
type: import_zod12.z.literal("web_search_call")
|
|
1950
2014
|
}),
|
|
1951
|
-
|
|
1952
|
-
type:
|
|
2015
|
+
import_zod12.z.object({
|
|
2016
|
+
type: import_zod12.z.literal("computer_call")
|
|
1953
2017
|
}),
|
|
1954
|
-
|
|
1955
|
-
type:
|
|
1956
|
-
summary:
|
|
1957
|
-
|
|
1958
|
-
type:
|
|
1959
|
-
text:
|
|
2018
|
+
import_zod12.z.object({
|
|
2019
|
+
type: import_zod12.z.literal("reasoning"),
|
|
2020
|
+
summary: import_zod12.z.array(
|
|
2021
|
+
import_zod12.z.object({
|
|
2022
|
+
type: import_zod12.z.literal("summary_text"),
|
|
2023
|
+
text: import_zod12.z.string()
|
|
1960
2024
|
})
|
|
1961
2025
|
)
|
|
1962
2026
|
})
|
|
1963
2027
|
])
|
|
1964
2028
|
),
|
|
1965
|
-
incomplete_details:
|
|
2029
|
+
incomplete_details: import_zod12.z.object({ reason: import_zod12.z.string() }).nullable(),
|
|
1966
2030
|
usage: usageSchema
|
|
1967
2031
|
})
|
|
1968
2032
|
),
|
|
@@ -1975,7 +2039,6 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1975
2039
|
case "reasoning": {
|
|
1976
2040
|
content.push({
|
|
1977
2041
|
type: "reasoning",
|
|
1978
|
-
reasoningType: "text",
|
|
1979
2042
|
text: part.summary.map((summary) => summary.text).join()
|
|
1980
2043
|
});
|
|
1981
2044
|
break;
|
|
@@ -2039,7 +2102,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2039
2102
|
};
|
|
2040
2103
|
}
|
|
2041
2104
|
async doStream(options) {
|
|
2042
|
-
const { args: body, warnings } = this.getArgs(options);
|
|
2105
|
+
const { args: body, warnings } = await this.getArgs(options);
|
|
2043
2106
|
const { responseHeaders, value: response } = await (0, import_provider_utils8.postJsonToApi)({
|
|
2044
2107
|
url: this.config.url({
|
|
2045
2108
|
path: "/responses",
|
|
@@ -2123,7 +2186,6 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2123
2186
|
} else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
|
|
2124
2187
|
controller.enqueue({
|
|
2125
2188
|
type: "reasoning",
|
|
2126
|
-
reasoningType: "text",
|
|
2127
2189
|
text: value.delta
|
|
2128
2190
|
});
|
|
2129
2191
|
} else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
|
|
@@ -2178,86 +2240,86 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2178
2240
|
};
|
|
2179
2241
|
}
|
|
2180
2242
|
};
|
|
2181
|
-
var usageSchema =
|
|
2182
|
-
input_tokens:
|
|
2183
|
-
input_tokens_details:
|
|
2184
|
-
output_tokens:
|
|
2185
|
-
output_tokens_details:
|
|
2243
|
+
var usageSchema = import_zod12.z.object({
|
|
2244
|
+
input_tokens: import_zod12.z.number(),
|
|
2245
|
+
input_tokens_details: import_zod12.z.object({ cached_tokens: import_zod12.z.number().nullish() }).nullish(),
|
|
2246
|
+
output_tokens: import_zod12.z.number(),
|
|
2247
|
+
output_tokens_details: import_zod12.z.object({ reasoning_tokens: import_zod12.z.number().nullish() }).nullish()
|
|
2186
2248
|
});
|
|
2187
|
-
var textDeltaChunkSchema =
|
|
2188
|
-
type:
|
|
2189
|
-
delta:
|
|
2249
|
+
var textDeltaChunkSchema = import_zod12.z.object({
|
|
2250
|
+
type: import_zod12.z.literal("response.output_text.delta"),
|
|
2251
|
+
delta: import_zod12.z.string()
|
|
2190
2252
|
});
|
|
2191
|
-
var responseFinishedChunkSchema =
|
|
2192
|
-
type:
|
|
2193
|
-
response:
|
|
2194
|
-
incomplete_details:
|
|
2253
|
+
var responseFinishedChunkSchema = import_zod12.z.object({
|
|
2254
|
+
type: import_zod12.z.enum(["response.completed", "response.incomplete"]),
|
|
2255
|
+
response: import_zod12.z.object({
|
|
2256
|
+
incomplete_details: import_zod12.z.object({ reason: import_zod12.z.string() }).nullish(),
|
|
2195
2257
|
usage: usageSchema
|
|
2196
2258
|
})
|
|
2197
2259
|
});
|
|
2198
|
-
var responseCreatedChunkSchema =
|
|
2199
|
-
type:
|
|
2200
|
-
response:
|
|
2201
|
-
id:
|
|
2202
|
-
created_at:
|
|
2203
|
-
model:
|
|
2260
|
+
var responseCreatedChunkSchema = import_zod12.z.object({
|
|
2261
|
+
type: import_zod12.z.literal("response.created"),
|
|
2262
|
+
response: import_zod12.z.object({
|
|
2263
|
+
id: import_zod12.z.string(),
|
|
2264
|
+
created_at: import_zod12.z.number(),
|
|
2265
|
+
model: import_zod12.z.string()
|
|
2204
2266
|
})
|
|
2205
2267
|
});
|
|
2206
|
-
var responseOutputItemDoneSchema =
|
|
2207
|
-
type:
|
|
2208
|
-
output_index:
|
|
2209
|
-
item:
|
|
2210
|
-
|
|
2211
|
-
type:
|
|
2268
|
+
var responseOutputItemDoneSchema = import_zod12.z.object({
|
|
2269
|
+
type: import_zod12.z.literal("response.output_item.done"),
|
|
2270
|
+
output_index: import_zod12.z.number(),
|
|
2271
|
+
item: import_zod12.z.discriminatedUnion("type", [
|
|
2272
|
+
import_zod12.z.object({
|
|
2273
|
+
type: import_zod12.z.literal("message")
|
|
2212
2274
|
}),
|
|
2213
|
-
|
|
2214
|
-
type:
|
|
2215
|
-
id:
|
|
2216
|
-
call_id:
|
|
2217
|
-
name:
|
|
2218
|
-
arguments:
|
|
2219
|
-
status:
|
|
2275
|
+
import_zod12.z.object({
|
|
2276
|
+
type: import_zod12.z.literal("function_call"),
|
|
2277
|
+
id: import_zod12.z.string(),
|
|
2278
|
+
call_id: import_zod12.z.string(),
|
|
2279
|
+
name: import_zod12.z.string(),
|
|
2280
|
+
arguments: import_zod12.z.string(),
|
|
2281
|
+
status: import_zod12.z.literal("completed")
|
|
2220
2282
|
})
|
|
2221
2283
|
])
|
|
2222
2284
|
});
|
|
2223
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2224
|
-
type:
|
|
2225
|
-
item_id:
|
|
2226
|
-
output_index:
|
|
2227
|
-
delta:
|
|
2285
|
+
var responseFunctionCallArgumentsDeltaSchema = import_zod12.z.object({
|
|
2286
|
+
type: import_zod12.z.literal("response.function_call_arguments.delta"),
|
|
2287
|
+
item_id: import_zod12.z.string(),
|
|
2288
|
+
output_index: import_zod12.z.number(),
|
|
2289
|
+
delta: import_zod12.z.string()
|
|
2228
2290
|
});
|
|
2229
|
-
var responseOutputItemAddedSchema =
|
|
2230
|
-
type:
|
|
2231
|
-
output_index:
|
|
2232
|
-
item:
|
|
2233
|
-
|
|
2234
|
-
type:
|
|
2291
|
+
var responseOutputItemAddedSchema = import_zod12.z.object({
|
|
2292
|
+
type: import_zod12.z.literal("response.output_item.added"),
|
|
2293
|
+
output_index: import_zod12.z.number(),
|
|
2294
|
+
item: import_zod12.z.discriminatedUnion("type", [
|
|
2295
|
+
import_zod12.z.object({
|
|
2296
|
+
type: import_zod12.z.literal("message")
|
|
2235
2297
|
}),
|
|
2236
|
-
|
|
2237
|
-
type:
|
|
2238
|
-
id:
|
|
2239
|
-
call_id:
|
|
2240
|
-
name:
|
|
2241
|
-
arguments:
|
|
2298
|
+
import_zod12.z.object({
|
|
2299
|
+
type: import_zod12.z.literal("function_call"),
|
|
2300
|
+
id: import_zod12.z.string(),
|
|
2301
|
+
call_id: import_zod12.z.string(),
|
|
2302
|
+
name: import_zod12.z.string(),
|
|
2303
|
+
arguments: import_zod12.z.string()
|
|
2242
2304
|
})
|
|
2243
2305
|
])
|
|
2244
2306
|
});
|
|
2245
|
-
var responseAnnotationAddedSchema =
|
|
2246
|
-
type:
|
|
2247
|
-
annotation:
|
|
2248
|
-
type:
|
|
2249
|
-
url:
|
|
2250
|
-
title:
|
|
2307
|
+
var responseAnnotationAddedSchema = import_zod12.z.object({
|
|
2308
|
+
type: import_zod12.z.literal("response.output_text.annotation.added"),
|
|
2309
|
+
annotation: import_zod12.z.object({
|
|
2310
|
+
type: import_zod12.z.literal("url_citation"),
|
|
2311
|
+
url: import_zod12.z.string(),
|
|
2312
|
+
title: import_zod12.z.string()
|
|
2251
2313
|
})
|
|
2252
2314
|
});
|
|
2253
|
-
var responseReasoningSummaryTextDeltaSchema =
|
|
2254
|
-
type:
|
|
2255
|
-
item_id:
|
|
2256
|
-
output_index:
|
|
2257
|
-
summary_index:
|
|
2258
|
-
delta:
|
|
2315
|
+
var responseReasoningSummaryTextDeltaSchema = import_zod12.z.object({
|
|
2316
|
+
type: import_zod12.z.literal("response.reasoning_summary_text.delta"),
|
|
2317
|
+
item_id: import_zod12.z.string(),
|
|
2318
|
+
output_index: import_zod12.z.number(),
|
|
2319
|
+
summary_index: import_zod12.z.number(),
|
|
2320
|
+
delta: import_zod12.z.string()
|
|
2259
2321
|
});
|
|
2260
|
-
var openaiResponsesChunkSchema =
|
|
2322
|
+
var openaiResponsesChunkSchema = import_zod12.z.union([
|
|
2261
2323
|
textDeltaChunkSchema,
|
|
2262
2324
|
responseFinishedChunkSchema,
|
|
2263
2325
|
responseCreatedChunkSchema,
|
|
@@ -2266,7 +2328,7 @@ var openaiResponsesChunkSchema = import_zod10.z.union([
|
|
|
2266
2328
|
responseOutputItemAddedSchema,
|
|
2267
2329
|
responseAnnotationAddedSchema,
|
|
2268
2330
|
responseReasoningSummaryTextDeltaSchema,
|
|
2269
|
-
|
|
2331
|
+
import_zod12.z.object({ type: import_zod12.z.string() }).passthrough()
|
|
2270
2332
|
// fallback for unknown chunks
|
|
2271
2333
|
]);
|
|
2272
2334
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2314,24 +2376,24 @@ function getResponsesModelConfig(modelId) {
|
|
|
2314
2376
|
requiredAutoTruncation: false
|
|
2315
2377
|
};
|
|
2316
2378
|
}
|
|
2317
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2318
|
-
metadata:
|
|
2319
|
-
parallelToolCalls:
|
|
2320
|
-
previousResponseId:
|
|
2321
|
-
store:
|
|
2322
|
-
user:
|
|
2323
|
-
reasoningEffort:
|
|
2324
|
-
strictSchemas:
|
|
2325
|
-
instructions:
|
|
2326
|
-
reasoningSummary:
|
|
2379
|
+
var openaiResponsesProviderOptionsSchema = import_zod12.z.object({
|
|
2380
|
+
metadata: import_zod12.z.any().nullish(),
|
|
2381
|
+
parallelToolCalls: import_zod12.z.boolean().nullish(),
|
|
2382
|
+
previousResponseId: import_zod12.z.string().nullish(),
|
|
2383
|
+
store: import_zod12.z.boolean().nullish(),
|
|
2384
|
+
user: import_zod12.z.string().nullish(),
|
|
2385
|
+
reasoningEffort: import_zod12.z.string().nullish(),
|
|
2386
|
+
strictSchemas: import_zod12.z.boolean().nullish(),
|
|
2387
|
+
instructions: import_zod12.z.string().nullish(),
|
|
2388
|
+
reasoningSummary: import_zod12.z.string().nullish()
|
|
2327
2389
|
});
|
|
2328
2390
|
|
|
2329
2391
|
// src/openai-speech-model.ts
|
|
2330
2392
|
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
2331
|
-
var
|
|
2332
|
-
var OpenAIProviderOptionsSchema =
|
|
2333
|
-
instructions:
|
|
2334
|
-
speed:
|
|
2393
|
+
var import_zod13 = require("zod");
|
|
2394
|
+
var OpenAIProviderOptionsSchema = import_zod13.z.object({
|
|
2395
|
+
instructions: import_zod13.z.string().nullish(),
|
|
2396
|
+
speed: import_zod13.z.number().min(0.25).max(4).default(1).nullish()
|
|
2335
2397
|
});
|
|
2336
2398
|
var OpenAISpeechModel = class {
|
|
2337
2399
|
constructor(modelId, config) {
|
|
@@ -2342,7 +2404,7 @@ var OpenAISpeechModel = class {
|
|
|
2342
2404
|
get provider() {
|
|
2343
2405
|
return this.config.provider;
|
|
2344
2406
|
}
|
|
2345
|
-
getArgs({
|
|
2407
|
+
async getArgs({
|
|
2346
2408
|
text,
|
|
2347
2409
|
voice = "alloy",
|
|
2348
2410
|
outputFormat = "mp3",
|
|
@@ -2351,7 +2413,7 @@ var OpenAISpeechModel = class {
|
|
|
2351
2413
|
providerOptions
|
|
2352
2414
|
}) {
|
|
2353
2415
|
const warnings = [];
|
|
2354
|
-
const openAIOptions = (0, import_provider_utils9.parseProviderOptions)({
|
|
2416
|
+
const openAIOptions = await (0, import_provider_utils9.parseProviderOptions)({
|
|
2355
2417
|
provider: "openai",
|
|
2356
2418
|
providerOptions,
|
|
2357
2419
|
schema: OpenAIProviderOptionsSchema
|
|
@@ -2392,7 +2454,7 @@ var OpenAISpeechModel = class {
|
|
|
2392
2454
|
async doGenerate(options) {
|
|
2393
2455
|
var _a, _b, _c;
|
|
2394
2456
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2395
|
-
const { requestBody, warnings } = this.getArgs(options);
|
|
2457
|
+
const { requestBody, warnings } = await this.getArgs(options);
|
|
2396
2458
|
const {
|
|
2397
2459
|
value: audio,
|
|
2398
2460
|
responseHeaders,
|
|
@@ -2441,21 +2503,21 @@ function createOpenAI(options = {}) {
|
|
|
2441
2503
|
"OpenAI-Project": options.project,
|
|
2442
2504
|
...options.headers
|
|
2443
2505
|
});
|
|
2444
|
-
const createChatModel = (modelId
|
|
2506
|
+
const createChatModel = (modelId) => new OpenAIChatLanguageModel(modelId, {
|
|
2445
2507
|
provider: `${providerName}.chat`,
|
|
2446
2508
|
url: ({ path }) => `${baseURL}${path}`,
|
|
2447
2509
|
headers: getHeaders,
|
|
2448
2510
|
compatibility,
|
|
2449
2511
|
fetch: options.fetch
|
|
2450
2512
|
});
|
|
2451
|
-
const createCompletionModel = (modelId
|
|
2513
|
+
const createCompletionModel = (modelId) => new OpenAICompletionLanguageModel(modelId, {
|
|
2452
2514
|
provider: `${providerName}.completion`,
|
|
2453
2515
|
url: ({ path }) => `${baseURL}${path}`,
|
|
2454
2516
|
headers: getHeaders,
|
|
2455
2517
|
compatibility,
|
|
2456
2518
|
fetch: options.fetch
|
|
2457
2519
|
});
|
|
2458
|
-
const createEmbeddingModel = (modelId
|
|
2520
|
+
const createEmbeddingModel = (modelId) => new OpenAIEmbeddingModel(modelId, {
|
|
2459
2521
|
provider: `${providerName}.embedding`,
|
|
2460
2522
|
url: ({ path }) => `${baseURL}${path}`,
|
|
2461
2523
|
headers: getHeaders,
|
|
@@ -2479,19 +2541,16 @@ function createOpenAI(options = {}) {
|
|
|
2479
2541
|
headers: getHeaders,
|
|
2480
2542
|
fetch: options.fetch
|
|
2481
2543
|
});
|
|
2482
|
-
const createLanguageModel = (modelId
|
|
2544
|
+
const createLanguageModel = (modelId) => {
|
|
2483
2545
|
if (new.target) {
|
|
2484
2546
|
throw new Error(
|
|
2485
2547
|
"The OpenAI model function cannot be called with the new keyword."
|
|
2486
2548
|
);
|
|
2487
2549
|
}
|
|
2488
2550
|
if (modelId === "gpt-3.5-turbo-instruct") {
|
|
2489
|
-
return createCompletionModel(
|
|
2490
|
-
modelId,
|
|
2491
|
-
settings
|
|
2492
|
-
);
|
|
2551
|
+
return createCompletionModel(modelId);
|
|
2493
2552
|
}
|
|
2494
|
-
return createChatModel(modelId
|
|
2553
|
+
return createChatModel(modelId);
|
|
2495
2554
|
};
|
|
2496
2555
|
const createResponsesModel = (modelId) => {
|
|
2497
2556
|
return new OpenAIResponsesLanguageModel(modelId, {
|
|
@@ -2501,8 +2560,8 @@ function createOpenAI(options = {}) {
|
|
|
2501
2560
|
fetch: options.fetch
|
|
2502
2561
|
});
|
|
2503
2562
|
};
|
|
2504
|
-
const provider = function(modelId
|
|
2505
|
-
return createLanguageModel(modelId
|
|
2563
|
+
const provider = function(modelId) {
|
|
2564
|
+
return createLanguageModel(modelId);
|
|
2506
2565
|
};
|
|
2507
2566
|
provider.languageModel = createLanguageModel;
|
|
2508
2567
|
provider.chat = createChatModel;
|