@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.mjs
CHANGED
|
@@ -254,7 +254,13 @@ var openaiProviderOptions = z.object({
|
|
|
254
254
|
/**
|
|
255
255
|
* Parameters for prediction mode.
|
|
256
256
|
*/
|
|
257
|
-
prediction: z.record(z.any()).optional()
|
|
257
|
+
prediction: z.record(z.any()).optional(),
|
|
258
|
+
/**
|
|
259
|
+
* Whether to use structured outputs.
|
|
260
|
+
*
|
|
261
|
+
* @default true
|
|
262
|
+
*/
|
|
263
|
+
structuredOutputs: z.boolean().optional()
|
|
258
264
|
});
|
|
259
265
|
|
|
260
266
|
// src/openai-error.ts
|
|
@@ -337,10 +343,9 @@ function prepareTools({
|
|
|
337
343
|
|
|
338
344
|
// src/openai-chat-language-model.ts
|
|
339
345
|
var OpenAIChatLanguageModel = class {
|
|
340
|
-
constructor(modelId,
|
|
346
|
+
constructor(modelId, config) {
|
|
341
347
|
this.specificationVersion = "v2";
|
|
342
348
|
this.modelId = modelId;
|
|
343
|
-
this.settings = settings;
|
|
344
349
|
this.config = config;
|
|
345
350
|
}
|
|
346
351
|
get provider() {
|
|
@@ -351,7 +356,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
351
356
|
"image/*": [/^https?:\/\/.*$/]
|
|
352
357
|
};
|
|
353
358
|
}
|
|
354
|
-
getArgs({
|
|
359
|
+
async getArgs({
|
|
355
360
|
prompt,
|
|
356
361
|
maxOutputTokens,
|
|
357
362
|
temperature,
|
|
@@ -368,18 +373,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
368
373
|
}) {
|
|
369
374
|
var _a, _b, _c;
|
|
370
375
|
const warnings = [];
|
|
371
|
-
const openaiOptions = (_a = parseProviderOptions({
|
|
376
|
+
const openaiOptions = (_a = await parseProviderOptions({
|
|
372
377
|
provider: "openai",
|
|
373
378
|
providerOptions,
|
|
374
379
|
schema: openaiProviderOptions
|
|
375
380
|
})) != null ? _a : {};
|
|
381
|
+
const structuredOutputs = (_b = openaiOptions.structuredOutputs) != null ? _b : true;
|
|
376
382
|
if (topK != null) {
|
|
377
383
|
warnings.push({
|
|
378
384
|
type: "unsupported-setting",
|
|
379
385
|
setting: "topK"
|
|
380
386
|
});
|
|
381
387
|
}
|
|
382
|
-
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !
|
|
388
|
+
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !structuredOutputs) {
|
|
383
389
|
warnings.push({
|
|
384
390
|
type: "unsupported-setting",
|
|
385
391
|
setting: "responseFormat",
|
|
@@ -408,12 +414,12 @@ var OpenAIChatLanguageModel = class {
|
|
|
408
414
|
presence_penalty: presencePenalty,
|
|
409
415
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? (
|
|
410
416
|
// TODO convert into provider option
|
|
411
|
-
|
|
417
|
+
structuredOutputs && responseFormat.schema != null ? {
|
|
412
418
|
type: "json_schema",
|
|
413
419
|
json_schema: {
|
|
414
420
|
schema: responseFormat.schema,
|
|
415
421
|
strict: true,
|
|
416
|
-
name: (
|
|
422
|
+
name: (_c = responseFormat.name) != null ? _c : "response",
|
|
417
423
|
description: responseFormat.description
|
|
418
424
|
}
|
|
419
425
|
} : { type: "json_object" }
|
|
@@ -493,7 +499,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
493
499
|
} = prepareTools({
|
|
494
500
|
tools,
|
|
495
501
|
toolChoice,
|
|
496
|
-
structuredOutputs
|
|
502
|
+
structuredOutputs
|
|
497
503
|
});
|
|
498
504
|
return {
|
|
499
505
|
args: {
|
|
@@ -506,7 +512,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
506
512
|
}
|
|
507
513
|
async doGenerate(options) {
|
|
508
514
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
509
|
-
const { args: body, warnings } = this.getArgs(options);
|
|
515
|
+
const { args: body, warnings } = await this.getArgs(options);
|
|
510
516
|
const {
|
|
511
517
|
responseHeaders,
|
|
512
518
|
value: response,
|
|
@@ -573,7 +579,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
573
579
|
};
|
|
574
580
|
}
|
|
575
581
|
async doStream(options) {
|
|
576
|
-
const { args, warnings } = this.getArgs(options);
|
|
582
|
+
const { args, warnings } = await this.getArgs(options);
|
|
577
583
|
const body = {
|
|
578
584
|
...args,
|
|
579
585
|
stream: true,
|
|
@@ -866,9 +872,10 @@ import {
|
|
|
866
872
|
combineHeaders as combineHeaders2,
|
|
867
873
|
createEventSourceResponseHandler as createEventSourceResponseHandler2,
|
|
868
874
|
createJsonResponseHandler as createJsonResponseHandler2,
|
|
875
|
+
parseProviderOptions as parseProviderOptions2,
|
|
869
876
|
postJsonToApi as postJsonToApi2
|
|
870
877
|
} from "@ai-sdk/provider-utils";
|
|
871
|
-
import { z as
|
|
878
|
+
import { z as z5 } from "zod";
|
|
872
879
|
|
|
873
880
|
// src/convert-to-openai-completion-prompt.ts
|
|
874
881
|
import {
|
|
@@ -877,13 +884,9 @@ import {
|
|
|
877
884
|
} from "@ai-sdk/provider";
|
|
878
885
|
function convertToOpenAICompletionPrompt({
|
|
879
886
|
prompt,
|
|
880
|
-
inputFormat,
|
|
881
887
|
user = "user",
|
|
882
888
|
assistant = "assistant"
|
|
883
889
|
}) {
|
|
884
|
-
if (inputFormat === "prompt" && prompt.length === 1 && prompt[0].role === "user" && prompt[0].content.length === 1 && prompt[0].content[0].type === "text") {
|
|
885
|
-
return { prompt: prompt[0].content[0].text };
|
|
886
|
-
}
|
|
887
890
|
let text = "";
|
|
888
891
|
if (prompt[0].role === "system") {
|
|
889
892
|
text += `${prompt[0].content}
|
|
@@ -952,14 +955,49 @@ ${user}:`]
|
|
|
952
955
|
};
|
|
953
956
|
}
|
|
954
957
|
|
|
958
|
+
// src/openai-completion-options.ts
|
|
959
|
+
import { z as z4 } from "zod";
|
|
960
|
+
var openaiCompletionProviderOptions = z4.object({
|
|
961
|
+
/**
|
|
962
|
+
Echo back the prompt in addition to the completion.
|
|
963
|
+
*/
|
|
964
|
+
echo: z4.boolean().optional(),
|
|
965
|
+
/**
|
|
966
|
+
Modify the likelihood of specified tokens appearing in the completion.
|
|
967
|
+
|
|
968
|
+
Accepts a JSON object that maps tokens (specified by their token ID in
|
|
969
|
+
the GPT tokenizer) to an associated bias value from -100 to 100. You
|
|
970
|
+
can use this tokenizer tool to convert text to token IDs. Mathematically,
|
|
971
|
+
the bias is added to the logits generated by the model prior to sampling.
|
|
972
|
+
The exact effect will vary per model, but values between -1 and 1 should
|
|
973
|
+
decrease or increase likelihood of selection; values like -100 or 100
|
|
974
|
+
should result in a ban or exclusive selection of the relevant token.
|
|
975
|
+
|
|
976
|
+
As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
|
|
977
|
+
token from being generated.
|
|
978
|
+
*/
|
|
979
|
+
logitBias: z4.record(z4.string(), z4.number()).optional(),
|
|
980
|
+
/**
|
|
981
|
+
The suffix that comes after a completion of inserted text.
|
|
982
|
+
*/
|
|
983
|
+
suffix: z4.string().optional(),
|
|
984
|
+
/**
|
|
985
|
+
A unique identifier representing your end-user, which can help OpenAI to
|
|
986
|
+
monitor and detect abuse. Learn more.
|
|
987
|
+
*/
|
|
988
|
+
user: z4.string().optional()
|
|
989
|
+
});
|
|
990
|
+
|
|
955
991
|
// src/openai-completion-language-model.ts
|
|
956
992
|
var OpenAICompletionLanguageModel = class {
|
|
957
|
-
constructor(modelId,
|
|
993
|
+
constructor(modelId, config) {
|
|
958
994
|
this.specificationVersion = "v2";
|
|
959
995
|
this.modelId = modelId;
|
|
960
|
-
this.settings = settings;
|
|
961
996
|
this.config = config;
|
|
962
997
|
}
|
|
998
|
+
get providerOptionsName() {
|
|
999
|
+
return this.config.provider.split(".")[0].trim();
|
|
1000
|
+
}
|
|
963
1001
|
get provider() {
|
|
964
1002
|
return this.config.provider;
|
|
965
1003
|
}
|
|
@@ -968,8 +1006,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
968
1006
|
// no supported urls for completion models
|
|
969
1007
|
};
|
|
970
1008
|
}
|
|
971
|
-
getArgs({
|
|
972
|
-
inputFormat,
|
|
1009
|
+
async getArgs({
|
|
973
1010
|
prompt,
|
|
974
1011
|
maxOutputTokens,
|
|
975
1012
|
temperature,
|
|
@@ -981,9 +1018,22 @@ var OpenAICompletionLanguageModel = class {
|
|
|
981
1018
|
responseFormat,
|
|
982
1019
|
tools,
|
|
983
1020
|
toolChoice,
|
|
984
|
-
seed
|
|
1021
|
+
seed,
|
|
1022
|
+
providerOptions
|
|
985
1023
|
}) {
|
|
986
1024
|
const warnings = [];
|
|
1025
|
+
const openaiOptions = {
|
|
1026
|
+
...await parseProviderOptions2({
|
|
1027
|
+
provider: "openai",
|
|
1028
|
+
providerOptions,
|
|
1029
|
+
schema: openaiCompletionProviderOptions
|
|
1030
|
+
}),
|
|
1031
|
+
...await parseProviderOptions2({
|
|
1032
|
+
provider: this.providerOptionsName,
|
|
1033
|
+
providerOptions,
|
|
1034
|
+
schema: openaiCompletionProviderOptions
|
|
1035
|
+
})
|
|
1036
|
+
};
|
|
987
1037
|
if (topK != null) {
|
|
988
1038
|
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
989
1039
|
}
|
|
@@ -1000,17 +1050,17 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1000
1050
|
details: "JSON response format is not supported."
|
|
1001
1051
|
});
|
|
1002
1052
|
}
|
|
1003
|
-
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt
|
|
1053
|
+
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt });
|
|
1004
1054
|
const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
|
|
1005
1055
|
return {
|
|
1006
1056
|
args: {
|
|
1007
1057
|
// model id:
|
|
1008
1058
|
model: this.modelId,
|
|
1009
1059
|
// model specific settings:
|
|
1010
|
-
echo:
|
|
1011
|
-
logit_bias:
|
|
1012
|
-
suffix:
|
|
1013
|
-
user:
|
|
1060
|
+
echo: openaiOptions.echo,
|
|
1061
|
+
logit_bias: openaiOptions.logitBias,
|
|
1062
|
+
suffix: openaiOptions.suffix,
|
|
1063
|
+
user: openaiOptions.user,
|
|
1014
1064
|
// standardized settings:
|
|
1015
1065
|
max_tokens: maxOutputTokens,
|
|
1016
1066
|
temperature,
|
|
@@ -1027,7 +1077,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1027
1077
|
};
|
|
1028
1078
|
}
|
|
1029
1079
|
async doGenerate(options) {
|
|
1030
|
-
const { args, warnings } = this.getArgs(options);
|
|
1080
|
+
const { args, warnings } = await this.getArgs(options);
|
|
1031
1081
|
const {
|
|
1032
1082
|
responseHeaders,
|
|
1033
1083
|
value: response,
|
|
@@ -1064,7 +1114,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1064
1114
|
};
|
|
1065
1115
|
}
|
|
1066
1116
|
async doStream(options) {
|
|
1067
|
-
const { args, warnings } = this.getArgs(options);
|
|
1117
|
+
const { args, warnings } = await this.getArgs(options);
|
|
1068
1118
|
const body = {
|
|
1069
1119
|
...args,
|
|
1070
1120
|
stream: true,
|
|
@@ -1145,36 +1195,36 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1145
1195
|
};
|
|
1146
1196
|
}
|
|
1147
1197
|
};
|
|
1148
|
-
var openaiCompletionResponseSchema =
|
|
1149
|
-
id:
|
|
1150
|
-
created:
|
|
1151
|
-
model:
|
|
1152
|
-
choices:
|
|
1153
|
-
|
|
1154
|
-
text:
|
|
1155
|
-
finish_reason:
|
|
1198
|
+
var openaiCompletionResponseSchema = z5.object({
|
|
1199
|
+
id: z5.string().nullish(),
|
|
1200
|
+
created: z5.number().nullish(),
|
|
1201
|
+
model: z5.string().nullish(),
|
|
1202
|
+
choices: z5.array(
|
|
1203
|
+
z5.object({
|
|
1204
|
+
text: z5.string(),
|
|
1205
|
+
finish_reason: z5.string()
|
|
1156
1206
|
})
|
|
1157
1207
|
),
|
|
1158
|
-
usage:
|
|
1159
|
-
prompt_tokens:
|
|
1160
|
-
completion_tokens:
|
|
1208
|
+
usage: z5.object({
|
|
1209
|
+
prompt_tokens: z5.number(),
|
|
1210
|
+
completion_tokens: z5.number()
|
|
1161
1211
|
})
|
|
1162
1212
|
});
|
|
1163
|
-
var openaiCompletionChunkSchema =
|
|
1164
|
-
|
|
1165
|
-
id:
|
|
1166
|
-
created:
|
|
1167
|
-
model:
|
|
1168
|
-
choices:
|
|
1169
|
-
|
|
1170
|
-
text:
|
|
1171
|
-
finish_reason:
|
|
1172
|
-
index:
|
|
1213
|
+
var openaiCompletionChunkSchema = z5.union([
|
|
1214
|
+
z5.object({
|
|
1215
|
+
id: z5.string().nullish(),
|
|
1216
|
+
created: z5.number().nullish(),
|
|
1217
|
+
model: z5.string().nullish(),
|
|
1218
|
+
choices: z5.array(
|
|
1219
|
+
z5.object({
|
|
1220
|
+
text: z5.string(),
|
|
1221
|
+
finish_reason: z5.string().nullish(),
|
|
1222
|
+
index: z5.number()
|
|
1173
1223
|
})
|
|
1174
1224
|
),
|
|
1175
|
-
usage:
|
|
1176
|
-
prompt_tokens:
|
|
1177
|
-
completion_tokens:
|
|
1225
|
+
usage: z5.object({
|
|
1226
|
+
prompt_tokens: z5.number(),
|
|
1227
|
+
completion_tokens: z5.number()
|
|
1178
1228
|
}).nullish()
|
|
1179
1229
|
}),
|
|
1180
1230
|
openaiErrorDataSchema
|
|
@@ -1187,45 +1237,38 @@ import {
|
|
|
1187
1237
|
import {
|
|
1188
1238
|
combineHeaders as combineHeaders3,
|
|
1189
1239
|
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1190
|
-
parseProviderOptions as
|
|
1240
|
+
parseProviderOptions as parseProviderOptions3,
|
|
1191
1241
|
postJsonToApi as postJsonToApi3
|
|
1192
1242
|
} from "@ai-sdk/provider-utils";
|
|
1193
|
-
import { z as
|
|
1243
|
+
import { z as z7 } from "zod";
|
|
1194
1244
|
|
|
1195
1245
|
// src/openai-embedding-options.ts
|
|
1196
|
-
import { z as
|
|
1197
|
-
var openaiEmbeddingProviderOptions =
|
|
1246
|
+
import { z as z6 } from "zod";
|
|
1247
|
+
var openaiEmbeddingProviderOptions = z6.object({
|
|
1198
1248
|
/**
|
|
1199
1249
|
The number of dimensions the resulting output embeddings should have.
|
|
1200
1250
|
Only supported in text-embedding-3 and later models.
|
|
1201
1251
|
*/
|
|
1202
|
-
dimensions:
|
|
1252
|
+
dimensions: z6.number().optional(),
|
|
1203
1253
|
/**
|
|
1204
1254
|
A unique identifier representing your end-user, which can help OpenAI to
|
|
1205
1255
|
monitor and detect abuse. Learn more.
|
|
1206
1256
|
*/
|
|
1207
|
-
user:
|
|
1257
|
+
user: z6.string().optional()
|
|
1208
1258
|
});
|
|
1209
1259
|
|
|
1210
1260
|
// src/openai-embedding-model.ts
|
|
1211
1261
|
var OpenAIEmbeddingModel = class {
|
|
1212
|
-
constructor(modelId,
|
|
1262
|
+
constructor(modelId, config) {
|
|
1213
1263
|
this.specificationVersion = "v2";
|
|
1264
|
+
this.maxEmbeddingsPerCall = 2048;
|
|
1265
|
+
this.supportsParallelCalls = true;
|
|
1214
1266
|
this.modelId = modelId;
|
|
1215
|
-
this.settings = settings;
|
|
1216
1267
|
this.config = config;
|
|
1217
1268
|
}
|
|
1218
1269
|
get provider() {
|
|
1219
1270
|
return this.config.provider;
|
|
1220
1271
|
}
|
|
1221
|
-
get maxEmbeddingsPerCall() {
|
|
1222
|
-
var _a;
|
|
1223
|
-
return (_a = this.settings.maxEmbeddingsPerCall) != null ? _a : 2048;
|
|
1224
|
-
}
|
|
1225
|
-
get supportsParallelCalls() {
|
|
1226
|
-
var _a;
|
|
1227
|
-
return (_a = this.settings.supportsParallelCalls) != null ? _a : true;
|
|
1228
|
-
}
|
|
1229
1272
|
async doEmbed({
|
|
1230
1273
|
values,
|
|
1231
1274
|
headers,
|
|
@@ -1241,7 +1284,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1241
1284
|
values
|
|
1242
1285
|
});
|
|
1243
1286
|
}
|
|
1244
|
-
const openaiOptions = (_a =
|
|
1287
|
+
const openaiOptions = (_a = await parseProviderOptions3({
|
|
1245
1288
|
provider: "openai",
|
|
1246
1289
|
providerOptions,
|
|
1247
1290
|
schema: openaiEmbeddingProviderOptions
|
|
@@ -1277,9 +1320,9 @@ var OpenAIEmbeddingModel = class {
|
|
|
1277
1320
|
};
|
|
1278
1321
|
}
|
|
1279
1322
|
};
|
|
1280
|
-
var openaiTextEmbeddingResponseSchema =
|
|
1281
|
-
data:
|
|
1282
|
-
usage:
|
|
1323
|
+
var openaiTextEmbeddingResponseSchema = z7.object({
|
|
1324
|
+
data: z7.array(z7.object({ embedding: z7.array(z7.number()) })),
|
|
1325
|
+
usage: z7.object({ prompt_tokens: z7.number() }).nullish()
|
|
1283
1326
|
});
|
|
1284
1327
|
|
|
1285
1328
|
// src/openai-image-model.ts
|
|
@@ -1288,13 +1331,15 @@ import {
|
|
|
1288
1331
|
createJsonResponseHandler as createJsonResponseHandler4,
|
|
1289
1332
|
postJsonToApi as postJsonToApi4
|
|
1290
1333
|
} from "@ai-sdk/provider-utils";
|
|
1291
|
-
import { z as
|
|
1334
|
+
import { z as z8 } from "zod";
|
|
1292
1335
|
|
|
1293
1336
|
// src/openai-image-settings.ts
|
|
1294
1337
|
var modelMaxImagesPerCall = {
|
|
1295
1338
|
"dall-e-3": 1,
|
|
1296
|
-
"dall-e-2": 10
|
|
1339
|
+
"dall-e-2": 10,
|
|
1340
|
+
"gpt-image-1": 10
|
|
1297
1341
|
};
|
|
1342
|
+
var hasDefaultResponseFormat = /* @__PURE__ */ new Set(["gpt-image-1"]);
|
|
1298
1343
|
|
|
1299
1344
|
// src/openai-image-model.ts
|
|
1300
1345
|
var OpenAIImageModel = class {
|
|
@@ -1346,7 +1391,7 @@ var OpenAIImageModel = class {
|
|
|
1346
1391
|
n,
|
|
1347
1392
|
size,
|
|
1348
1393
|
...(_d = providerOptions.openai) != null ? _d : {},
|
|
1349
|
-
response_format: "b64_json"
|
|
1394
|
+
...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
|
|
1350
1395
|
},
|
|
1351
1396
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1352
1397
|
successfulResponseHandler: createJsonResponseHandler4(
|
|
@@ -1366,13 +1411,13 @@ var OpenAIImageModel = class {
|
|
|
1366
1411
|
};
|
|
1367
1412
|
}
|
|
1368
1413
|
};
|
|
1369
|
-
var openaiImageResponseSchema =
|
|
1370
|
-
data:
|
|
1414
|
+
var openaiImageResponseSchema = z8.object({
|
|
1415
|
+
data: z8.array(z8.object({ b64_json: z8.string() }))
|
|
1371
1416
|
});
|
|
1372
1417
|
|
|
1373
1418
|
// src/openai-tools.ts
|
|
1374
|
-
import { z as
|
|
1375
|
-
var WebSearchPreviewParameters =
|
|
1419
|
+
import { z as z9 } from "zod";
|
|
1420
|
+
var WebSearchPreviewParameters = z9.object({});
|
|
1376
1421
|
function webSearchPreviewTool({
|
|
1377
1422
|
searchContextSize,
|
|
1378
1423
|
userLocation
|
|
@@ -1396,17 +1441,39 @@ import {
|
|
|
1396
1441
|
combineHeaders as combineHeaders5,
|
|
1397
1442
|
convertBase64ToUint8Array,
|
|
1398
1443
|
createJsonResponseHandler as createJsonResponseHandler5,
|
|
1399
|
-
parseProviderOptions as
|
|
1444
|
+
parseProviderOptions as parseProviderOptions4,
|
|
1400
1445
|
postFormDataToApi
|
|
1401
1446
|
} from "@ai-sdk/provider-utils";
|
|
1402
|
-
import { z as
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1447
|
+
import { z as z11 } from "zod";
|
|
1448
|
+
|
|
1449
|
+
// src/openai-transcription-options.ts
|
|
1450
|
+
import { z as z10 } from "zod";
|
|
1451
|
+
var openAITranscriptionProviderOptions = z10.object({
|
|
1452
|
+
/**
|
|
1453
|
+
* Additional information to include in the transcription response.
|
|
1454
|
+
*/
|
|
1455
|
+
include: z10.array(z10.string()).nullish(),
|
|
1456
|
+
/**
|
|
1457
|
+
* The language of the input audio in ISO-639-1 format.
|
|
1458
|
+
*/
|
|
1459
|
+
language: z10.string().nullish(),
|
|
1460
|
+
/**
|
|
1461
|
+
* An optional text to guide the model's style or continue a previous audio segment.
|
|
1462
|
+
*/
|
|
1463
|
+
prompt: z10.string().nullish(),
|
|
1464
|
+
/**
|
|
1465
|
+
* The sampling temperature, between 0 and 1.
|
|
1466
|
+
* @default 0
|
|
1467
|
+
*/
|
|
1468
|
+
temperature: z10.number().min(0).max(1).default(0).nullish(),
|
|
1469
|
+
/**
|
|
1470
|
+
* The timestamp granularities to populate for this transcription.
|
|
1471
|
+
* @default ['segment']
|
|
1472
|
+
*/
|
|
1473
|
+
timestampGranularities: z10.array(z10.enum(["word", "segment"])).default(["segment"]).nullish()
|
|
1409
1474
|
});
|
|
1475
|
+
|
|
1476
|
+
// src/openai-transcription-model.ts
|
|
1410
1477
|
var languageMap = {
|
|
1411
1478
|
afrikaans: "af",
|
|
1412
1479
|
arabic: "ar",
|
|
@@ -1475,17 +1542,16 @@ var OpenAITranscriptionModel = class {
|
|
|
1475
1542
|
get provider() {
|
|
1476
1543
|
return this.config.provider;
|
|
1477
1544
|
}
|
|
1478
|
-
getArgs({
|
|
1545
|
+
async getArgs({
|
|
1479
1546
|
audio,
|
|
1480
1547
|
mediaType,
|
|
1481
1548
|
providerOptions
|
|
1482
1549
|
}) {
|
|
1483
|
-
var _a, _b, _c, _d, _e;
|
|
1484
1550
|
const warnings = [];
|
|
1485
|
-
const openAIOptions =
|
|
1551
|
+
const openAIOptions = await parseProviderOptions4({
|
|
1486
1552
|
provider: "openai",
|
|
1487
1553
|
providerOptions,
|
|
1488
|
-
schema:
|
|
1554
|
+
schema: openAITranscriptionProviderOptions
|
|
1489
1555
|
});
|
|
1490
1556
|
const formData = new FormData();
|
|
1491
1557
|
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
@@ -1493,15 +1559,14 @@ var OpenAITranscriptionModel = class {
|
|
|
1493
1559
|
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
1494
1560
|
if (openAIOptions) {
|
|
1495
1561
|
const transcriptionModelOptions = {
|
|
1496
|
-
include:
|
|
1497
|
-
language:
|
|
1498
|
-
prompt:
|
|
1499
|
-
temperature:
|
|
1500
|
-
timestamp_granularities:
|
|
1562
|
+
include: openAIOptions.include,
|
|
1563
|
+
language: openAIOptions.language,
|
|
1564
|
+
prompt: openAIOptions.prompt,
|
|
1565
|
+
temperature: openAIOptions.temperature,
|
|
1566
|
+
timestamp_granularities: openAIOptions.timestampGranularities
|
|
1501
1567
|
};
|
|
1502
|
-
for (const key
|
|
1503
|
-
|
|
1504
|
-
if (value !== void 0) {
|
|
1568
|
+
for (const [key, value] of Object.entries(transcriptionModelOptions)) {
|
|
1569
|
+
if (value != null) {
|
|
1505
1570
|
formData.append(key, String(value));
|
|
1506
1571
|
}
|
|
1507
1572
|
}
|
|
@@ -1514,7 +1579,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1514
1579
|
async doGenerate(options) {
|
|
1515
1580
|
var _a, _b, _c, _d, _e, _f;
|
|
1516
1581
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1517
|
-
const { formData, warnings } = this.getArgs(options);
|
|
1582
|
+
const { formData, warnings } = await this.getArgs(options);
|
|
1518
1583
|
const {
|
|
1519
1584
|
value: response,
|
|
1520
1585
|
responseHeaders,
|
|
@@ -1553,15 +1618,15 @@ var OpenAITranscriptionModel = class {
|
|
|
1553
1618
|
};
|
|
1554
1619
|
}
|
|
1555
1620
|
};
|
|
1556
|
-
var openaiTranscriptionResponseSchema =
|
|
1557
|
-
text:
|
|
1558
|
-
language:
|
|
1559
|
-
duration:
|
|
1560
|
-
words:
|
|
1561
|
-
|
|
1562
|
-
word:
|
|
1563
|
-
start:
|
|
1564
|
-
end:
|
|
1621
|
+
var openaiTranscriptionResponseSchema = z11.object({
|
|
1622
|
+
text: z11.string(),
|
|
1623
|
+
language: z11.string().nullish(),
|
|
1624
|
+
duration: z11.number().nullish(),
|
|
1625
|
+
words: z11.array(
|
|
1626
|
+
z11.object({
|
|
1627
|
+
word: z11.string(),
|
|
1628
|
+
start: z11.number(),
|
|
1629
|
+
end: z11.number()
|
|
1565
1630
|
})
|
|
1566
1631
|
).nullish()
|
|
1567
1632
|
});
|
|
@@ -1572,10 +1637,10 @@ import {
|
|
|
1572
1637
|
createEventSourceResponseHandler as createEventSourceResponseHandler3,
|
|
1573
1638
|
createJsonResponseHandler as createJsonResponseHandler6,
|
|
1574
1639
|
generateId as generateId2,
|
|
1575
|
-
parseProviderOptions as
|
|
1640
|
+
parseProviderOptions as parseProviderOptions5,
|
|
1576
1641
|
postJsonToApi as postJsonToApi5
|
|
1577
1642
|
} from "@ai-sdk/provider-utils";
|
|
1578
|
-
import { z as
|
|
1643
|
+
import { z as z12 } from "zod";
|
|
1579
1644
|
|
|
1580
1645
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1581
1646
|
import {
|
|
@@ -1799,7 +1864,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1799
1864
|
get provider() {
|
|
1800
1865
|
return this.config.provider;
|
|
1801
1866
|
}
|
|
1802
|
-
getArgs({
|
|
1867
|
+
async getArgs({
|
|
1803
1868
|
maxOutputTokens,
|
|
1804
1869
|
temperature,
|
|
1805
1870
|
stopSequences,
|
|
@@ -1843,7 +1908,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1843
1908
|
systemMessageMode: modelConfig.systemMessageMode
|
|
1844
1909
|
});
|
|
1845
1910
|
warnings.push(...messageWarnings);
|
|
1846
|
-
const openaiOptions =
|
|
1911
|
+
const openaiOptions = await parseProviderOptions5({
|
|
1847
1912
|
provider: "openai",
|
|
1848
1913
|
providerOptions,
|
|
1849
1914
|
schema: openaiResponsesProviderOptionsSchema
|
|
@@ -1926,7 +1991,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1926
1991
|
}
|
|
1927
1992
|
async doGenerate(options) {
|
|
1928
1993
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1929
|
-
const { args: body, warnings } = this.getArgs(options);
|
|
1994
|
+
const { args: body, warnings } = await this.getArgs(options);
|
|
1930
1995
|
const {
|
|
1931
1996
|
responseHeaders,
|
|
1932
1997
|
value: response,
|
|
@@ -1940,55 +2005,55 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1940
2005
|
body,
|
|
1941
2006
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1942
2007
|
successfulResponseHandler: createJsonResponseHandler6(
|
|
1943
|
-
|
|
1944
|
-
id:
|
|
1945
|
-
created_at:
|
|
1946
|
-
model:
|
|
1947
|
-
output:
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
type:
|
|
1951
|
-
role:
|
|
1952
|
-
content:
|
|
1953
|
-
|
|
1954
|
-
type:
|
|
1955
|
-
text:
|
|
1956
|
-
annotations:
|
|
1957
|
-
|
|
1958
|
-
type:
|
|
1959
|
-
start_index:
|
|
1960
|
-
end_index:
|
|
1961
|
-
url:
|
|
1962
|
-
title:
|
|
2008
|
+
z12.object({
|
|
2009
|
+
id: z12.string(),
|
|
2010
|
+
created_at: z12.number(),
|
|
2011
|
+
model: z12.string(),
|
|
2012
|
+
output: z12.array(
|
|
2013
|
+
z12.discriminatedUnion("type", [
|
|
2014
|
+
z12.object({
|
|
2015
|
+
type: z12.literal("message"),
|
|
2016
|
+
role: z12.literal("assistant"),
|
|
2017
|
+
content: z12.array(
|
|
2018
|
+
z12.object({
|
|
2019
|
+
type: z12.literal("output_text"),
|
|
2020
|
+
text: z12.string(),
|
|
2021
|
+
annotations: z12.array(
|
|
2022
|
+
z12.object({
|
|
2023
|
+
type: z12.literal("url_citation"),
|
|
2024
|
+
start_index: z12.number(),
|
|
2025
|
+
end_index: z12.number(),
|
|
2026
|
+
url: z12.string(),
|
|
2027
|
+
title: z12.string()
|
|
1963
2028
|
})
|
|
1964
2029
|
)
|
|
1965
2030
|
})
|
|
1966
2031
|
)
|
|
1967
2032
|
}),
|
|
1968
|
-
|
|
1969
|
-
type:
|
|
1970
|
-
call_id:
|
|
1971
|
-
name:
|
|
1972
|
-
arguments:
|
|
2033
|
+
z12.object({
|
|
2034
|
+
type: z12.literal("function_call"),
|
|
2035
|
+
call_id: z12.string(),
|
|
2036
|
+
name: z12.string(),
|
|
2037
|
+
arguments: z12.string()
|
|
1973
2038
|
}),
|
|
1974
|
-
|
|
1975
|
-
type:
|
|
2039
|
+
z12.object({
|
|
2040
|
+
type: z12.literal("web_search_call")
|
|
1976
2041
|
}),
|
|
1977
|
-
|
|
1978
|
-
type:
|
|
2042
|
+
z12.object({
|
|
2043
|
+
type: z12.literal("computer_call")
|
|
1979
2044
|
}),
|
|
1980
|
-
|
|
1981
|
-
type:
|
|
1982
|
-
summary:
|
|
1983
|
-
|
|
1984
|
-
type:
|
|
1985
|
-
text:
|
|
2045
|
+
z12.object({
|
|
2046
|
+
type: z12.literal("reasoning"),
|
|
2047
|
+
summary: z12.array(
|
|
2048
|
+
z12.object({
|
|
2049
|
+
type: z12.literal("summary_text"),
|
|
2050
|
+
text: z12.string()
|
|
1986
2051
|
})
|
|
1987
2052
|
)
|
|
1988
2053
|
})
|
|
1989
2054
|
])
|
|
1990
2055
|
),
|
|
1991
|
-
incomplete_details:
|
|
2056
|
+
incomplete_details: z12.object({ reason: z12.string() }).nullable(),
|
|
1992
2057
|
usage: usageSchema
|
|
1993
2058
|
})
|
|
1994
2059
|
),
|
|
@@ -2001,7 +2066,6 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2001
2066
|
case "reasoning": {
|
|
2002
2067
|
content.push({
|
|
2003
2068
|
type: "reasoning",
|
|
2004
|
-
reasoningType: "text",
|
|
2005
2069
|
text: part.summary.map((summary) => summary.text).join()
|
|
2006
2070
|
});
|
|
2007
2071
|
break;
|
|
@@ -2065,7 +2129,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2065
2129
|
};
|
|
2066
2130
|
}
|
|
2067
2131
|
async doStream(options) {
|
|
2068
|
-
const { args: body, warnings } = this.getArgs(options);
|
|
2132
|
+
const { args: body, warnings } = await this.getArgs(options);
|
|
2069
2133
|
const { responseHeaders, value: response } = await postJsonToApi5({
|
|
2070
2134
|
url: this.config.url({
|
|
2071
2135
|
path: "/responses",
|
|
@@ -2149,7 +2213,6 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2149
2213
|
} else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
|
|
2150
2214
|
controller.enqueue({
|
|
2151
2215
|
type: "reasoning",
|
|
2152
|
-
reasoningType: "text",
|
|
2153
2216
|
text: value.delta
|
|
2154
2217
|
});
|
|
2155
2218
|
} else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
|
|
@@ -2204,86 +2267,86 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2204
2267
|
};
|
|
2205
2268
|
}
|
|
2206
2269
|
};
|
|
2207
|
-
var usageSchema =
|
|
2208
|
-
input_tokens:
|
|
2209
|
-
input_tokens_details:
|
|
2210
|
-
output_tokens:
|
|
2211
|
-
output_tokens_details:
|
|
2270
|
+
var usageSchema = z12.object({
|
|
2271
|
+
input_tokens: z12.number(),
|
|
2272
|
+
input_tokens_details: z12.object({ cached_tokens: z12.number().nullish() }).nullish(),
|
|
2273
|
+
output_tokens: z12.number(),
|
|
2274
|
+
output_tokens_details: z12.object({ reasoning_tokens: z12.number().nullish() }).nullish()
|
|
2212
2275
|
});
|
|
2213
|
-
var textDeltaChunkSchema =
|
|
2214
|
-
type:
|
|
2215
|
-
delta:
|
|
2276
|
+
var textDeltaChunkSchema = z12.object({
|
|
2277
|
+
type: z12.literal("response.output_text.delta"),
|
|
2278
|
+
delta: z12.string()
|
|
2216
2279
|
});
|
|
2217
|
-
var responseFinishedChunkSchema =
|
|
2218
|
-
type:
|
|
2219
|
-
response:
|
|
2220
|
-
incomplete_details:
|
|
2280
|
+
var responseFinishedChunkSchema = z12.object({
|
|
2281
|
+
type: z12.enum(["response.completed", "response.incomplete"]),
|
|
2282
|
+
response: z12.object({
|
|
2283
|
+
incomplete_details: z12.object({ reason: z12.string() }).nullish(),
|
|
2221
2284
|
usage: usageSchema
|
|
2222
2285
|
})
|
|
2223
2286
|
});
|
|
2224
|
-
var responseCreatedChunkSchema =
|
|
2225
|
-
type:
|
|
2226
|
-
response:
|
|
2227
|
-
id:
|
|
2228
|
-
created_at:
|
|
2229
|
-
model:
|
|
2287
|
+
var responseCreatedChunkSchema = z12.object({
|
|
2288
|
+
type: z12.literal("response.created"),
|
|
2289
|
+
response: z12.object({
|
|
2290
|
+
id: z12.string(),
|
|
2291
|
+
created_at: z12.number(),
|
|
2292
|
+
model: z12.string()
|
|
2230
2293
|
})
|
|
2231
2294
|
});
|
|
2232
|
-
var responseOutputItemDoneSchema =
|
|
2233
|
-
type:
|
|
2234
|
-
output_index:
|
|
2235
|
-
item:
|
|
2236
|
-
|
|
2237
|
-
type:
|
|
2295
|
+
var responseOutputItemDoneSchema = z12.object({
|
|
2296
|
+
type: z12.literal("response.output_item.done"),
|
|
2297
|
+
output_index: z12.number(),
|
|
2298
|
+
item: z12.discriminatedUnion("type", [
|
|
2299
|
+
z12.object({
|
|
2300
|
+
type: z12.literal("message")
|
|
2238
2301
|
}),
|
|
2239
|
-
|
|
2240
|
-
type:
|
|
2241
|
-
id:
|
|
2242
|
-
call_id:
|
|
2243
|
-
name:
|
|
2244
|
-
arguments:
|
|
2245
|
-
status:
|
|
2302
|
+
z12.object({
|
|
2303
|
+
type: z12.literal("function_call"),
|
|
2304
|
+
id: z12.string(),
|
|
2305
|
+
call_id: z12.string(),
|
|
2306
|
+
name: z12.string(),
|
|
2307
|
+
arguments: z12.string(),
|
|
2308
|
+
status: z12.literal("completed")
|
|
2246
2309
|
})
|
|
2247
2310
|
])
|
|
2248
2311
|
});
|
|
2249
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2250
|
-
type:
|
|
2251
|
-
item_id:
|
|
2252
|
-
output_index:
|
|
2253
|
-
delta:
|
|
2312
|
+
var responseFunctionCallArgumentsDeltaSchema = z12.object({
|
|
2313
|
+
type: z12.literal("response.function_call_arguments.delta"),
|
|
2314
|
+
item_id: z12.string(),
|
|
2315
|
+
output_index: z12.number(),
|
|
2316
|
+
delta: z12.string()
|
|
2254
2317
|
});
|
|
2255
|
-
var responseOutputItemAddedSchema =
|
|
2256
|
-
type:
|
|
2257
|
-
output_index:
|
|
2258
|
-
item:
|
|
2259
|
-
|
|
2260
|
-
type:
|
|
2318
|
+
var responseOutputItemAddedSchema = z12.object({
|
|
2319
|
+
type: z12.literal("response.output_item.added"),
|
|
2320
|
+
output_index: z12.number(),
|
|
2321
|
+
item: z12.discriminatedUnion("type", [
|
|
2322
|
+
z12.object({
|
|
2323
|
+
type: z12.literal("message")
|
|
2261
2324
|
}),
|
|
2262
|
-
|
|
2263
|
-
type:
|
|
2264
|
-
id:
|
|
2265
|
-
call_id:
|
|
2266
|
-
name:
|
|
2267
|
-
arguments:
|
|
2325
|
+
z12.object({
|
|
2326
|
+
type: z12.literal("function_call"),
|
|
2327
|
+
id: z12.string(),
|
|
2328
|
+
call_id: z12.string(),
|
|
2329
|
+
name: z12.string(),
|
|
2330
|
+
arguments: z12.string()
|
|
2268
2331
|
})
|
|
2269
2332
|
])
|
|
2270
2333
|
});
|
|
2271
|
-
var responseAnnotationAddedSchema =
|
|
2272
|
-
type:
|
|
2273
|
-
annotation:
|
|
2274
|
-
type:
|
|
2275
|
-
url:
|
|
2276
|
-
title:
|
|
2334
|
+
var responseAnnotationAddedSchema = z12.object({
|
|
2335
|
+
type: z12.literal("response.output_text.annotation.added"),
|
|
2336
|
+
annotation: z12.object({
|
|
2337
|
+
type: z12.literal("url_citation"),
|
|
2338
|
+
url: z12.string(),
|
|
2339
|
+
title: z12.string()
|
|
2277
2340
|
})
|
|
2278
2341
|
});
|
|
2279
|
-
var responseReasoningSummaryTextDeltaSchema =
|
|
2280
|
-
type:
|
|
2281
|
-
item_id:
|
|
2282
|
-
output_index:
|
|
2283
|
-
summary_index:
|
|
2284
|
-
delta:
|
|
2342
|
+
var responseReasoningSummaryTextDeltaSchema = z12.object({
|
|
2343
|
+
type: z12.literal("response.reasoning_summary_text.delta"),
|
|
2344
|
+
item_id: z12.string(),
|
|
2345
|
+
output_index: z12.number(),
|
|
2346
|
+
summary_index: z12.number(),
|
|
2347
|
+
delta: z12.string()
|
|
2285
2348
|
});
|
|
2286
|
-
var openaiResponsesChunkSchema =
|
|
2349
|
+
var openaiResponsesChunkSchema = z12.union([
|
|
2287
2350
|
textDeltaChunkSchema,
|
|
2288
2351
|
responseFinishedChunkSchema,
|
|
2289
2352
|
responseCreatedChunkSchema,
|
|
@@ -2292,7 +2355,7 @@ var openaiResponsesChunkSchema = z10.union([
|
|
|
2292
2355
|
responseOutputItemAddedSchema,
|
|
2293
2356
|
responseAnnotationAddedSchema,
|
|
2294
2357
|
responseReasoningSummaryTextDeltaSchema,
|
|
2295
|
-
|
|
2358
|
+
z12.object({ type: z12.string() }).passthrough()
|
|
2296
2359
|
// fallback for unknown chunks
|
|
2297
2360
|
]);
|
|
2298
2361
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2340,29 +2403,29 @@ function getResponsesModelConfig(modelId) {
|
|
|
2340
2403
|
requiredAutoTruncation: false
|
|
2341
2404
|
};
|
|
2342
2405
|
}
|
|
2343
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2344
|
-
metadata:
|
|
2345
|
-
parallelToolCalls:
|
|
2346
|
-
previousResponseId:
|
|
2347
|
-
store:
|
|
2348
|
-
user:
|
|
2349
|
-
reasoningEffort:
|
|
2350
|
-
strictSchemas:
|
|
2351
|
-
instructions:
|
|
2352
|
-
reasoningSummary:
|
|
2406
|
+
var openaiResponsesProviderOptionsSchema = z12.object({
|
|
2407
|
+
metadata: z12.any().nullish(),
|
|
2408
|
+
parallelToolCalls: z12.boolean().nullish(),
|
|
2409
|
+
previousResponseId: z12.string().nullish(),
|
|
2410
|
+
store: z12.boolean().nullish(),
|
|
2411
|
+
user: z12.string().nullish(),
|
|
2412
|
+
reasoningEffort: z12.string().nullish(),
|
|
2413
|
+
strictSchemas: z12.boolean().nullish(),
|
|
2414
|
+
instructions: z12.string().nullish(),
|
|
2415
|
+
reasoningSummary: z12.string().nullish()
|
|
2353
2416
|
});
|
|
2354
2417
|
|
|
2355
2418
|
// src/openai-speech-model.ts
|
|
2356
2419
|
import {
|
|
2357
2420
|
combineHeaders as combineHeaders7,
|
|
2358
2421
|
createBinaryResponseHandler,
|
|
2359
|
-
parseProviderOptions as
|
|
2422
|
+
parseProviderOptions as parseProviderOptions6,
|
|
2360
2423
|
postJsonToApi as postJsonToApi6
|
|
2361
2424
|
} from "@ai-sdk/provider-utils";
|
|
2362
|
-
import { z as
|
|
2363
|
-
var OpenAIProviderOptionsSchema =
|
|
2364
|
-
instructions:
|
|
2365
|
-
speed:
|
|
2425
|
+
import { z as z13 } from "zod";
|
|
2426
|
+
var OpenAIProviderOptionsSchema = z13.object({
|
|
2427
|
+
instructions: z13.string().nullish(),
|
|
2428
|
+
speed: z13.number().min(0.25).max(4).default(1).nullish()
|
|
2366
2429
|
});
|
|
2367
2430
|
var OpenAISpeechModel = class {
|
|
2368
2431
|
constructor(modelId, config) {
|
|
@@ -2373,7 +2436,7 @@ var OpenAISpeechModel = class {
|
|
|
2373
2436
|
get provider() {
|
|
2374
2437
|
return this.config.provider;
|
|
2375
2438
|
}
|
|
2376
|
-
getArgs({
|
|
2439
|
+
async getArgs({
|
|
2377
2440
|
text,
|
|
2378
2441
|
voice = "alloy",
|
|
2379
2442
|
outputFormat = "mp3",
|
|
@@ -2382,7 +2445,7 @@ var OpenAISpeechModel = class {
|
|
|
2382
2445
|
providerOptions
|
|
2383
2446
|
}) {
|
|
2384
2447
|
const warnings = [];
|
|
2385
|
-
const openAIOptions =
|
|
2448
|
+
const openAIOptions = await parseProviderOptions6({
|
|
2386
2449
|
provider: "openai",
|
|
2387
2450
|
providerOptions,
|
|
2388
2451
|
schema: OpenAIProviderOptionsSchema
|
|
@@ -2423,7 +2486,7 @@ var OpenAISpeechModel = class {
|
|
|
2423
2486
|
async doGenerate(options) {
|
|
2424
2487
|
var _a, _b, _c;
|
|
2425
2488
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2426
|
-
const { requestBody, warnings } = this.getArgs(options);
|
|
2489
|
+
const { requestBody, warnings } = await this.getArgs(options);
|
|
2427
2490
|
const {
|
|
2428
2491
|
value: audio,
|
|
2429
2492
|
responseHeaders,
|
|
@@ -2472,21 +2535,21 @@ function createOpenAI(options = {}) {
|
|
|
2472
2535
|
"OpenAI-Project": options.project,
|
|
2473
2536
|
...options.headers
|
|
2474
2537
|
});
|
|
2475
|
-
const createChatModel = (modelId
|
|
2538
|
+
const createChatModel = (modelId) => new OpenAIChatLanguageModel(modelId, {
|
|
2476
2539
|
provider: `${providerName}.chat`,
|
|
2477
2540
|
url: ({ path }) => `${baseURL}${path}`,
|
|
2478
2541
|
headers: getHeaders,
|
|
2479
2542
|
compatibility,
|
|
2480
2543
|
fetch: options.fetch
|
|
2481
2544
|
});
|
|
2482
|
-
const createCompletionModel = (modelId
|
|
2545
|
+
const createCompletionModel = (modelId) => new OpenAICompletionLanguageModel(modelId, {
|
|
2483
2546
|
provider: `${providerName}.completion`,
|
|
2484
2547
|
url: ({ path }) => `${baseURL}${path}`,
|
|
2485
2548
|
headers: getHeaders,
|
|
2486
2549
|
compatibility,
|
|
2487
2550
|
fetch: options.fetch
|
|
2488
2551
|
});
|
|
2489
|
-
const createEmbeddingModel = (modelId
|
|
2552
|
+
const createEmbeddingModel = (modelId) => new OpenAIEmbeddingModel(modelId, {
|
|
2490
2553
|
provider: `${providerName}.embedding`,
|
|
2491
2554
|
url: ({ path }) => `${baseURL}${path}`,
|
|
2492
2555
|
headers: getHeaders,
|
|
@@ -2510,19 +2573,16 @@ function createOpenAI(options = {}) {
|
|
|
2510
2573
|
headers: getHeaders,
|
|
2511
2574
|
fetch: options.fetch
|
|
2512
2575
|
});
|
|
2513
|
-
const createLanguageModel = (modelId
|
|
2576
|
+
const createLanguageModel = (modelId) => {
|
|
2514
2577
|
if (new.target) {
|
|
2515
2578
|
throw new Error(
|
|
2516
2579
|
"The OpenAI model function cannot be called with the new keyword."
|
|
2517
2580
|
);
|
|
2518
2581
|
}
|
|
2519
2582
|
if (modelId === "gpt-3.5-turbo-instruct") {
|
|
2520
|
-
return createCompletionModel(
|
|
2521
|
-
modelId,
|
|
2522
|
-
settings
|
|
2523
|
-
);
|
|
2583
|
+
return createCompletionModel(modelId);
|
|
2524
2584
|
}
|
|
2525
|
-
return createChatModel(modelId
|
|
2585
|
+
return createChatModel(modelId);
|
|
2526
2586
|
};
|
|
2527
2587
|
const createResponsesModel = (modelId) => {
|
|
2528
2588
|
return new OpenAIResponsesLanguageModel(modelId, {
|
|
@@ -2532,8 +2592,8 @@ function createOpenAI(options = {}) {
|
|
|
2532
2592
|
fetch: options.fetch
|
|
2533
2593
|
});
|
|
2534
2594
|
};
|
|
2535
|
-
const provider = function(modelId
|
|
2536
|
-
return createLanguageModel(modelId
|
|
2595
|
+
const provider = function(modelId) {
|
|
2596
|
+
return createLanguageModel(modelId);
|
|
2537
2597
|
};
|
|
2538
2598
|
provider.languageModel = createLanguageModel;
|
|
2539
2599
|
provider.chat = createChatModel;
|