@ai-sdk/openai 0.0.67 → 0.0.70
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +181 -118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +177 -112
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +1 -1
- package/internal/dist/index.d.ts +1 -1
- package/internal/dist/index.js +181 -118
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +177 -112
- package/internal/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 0.0.70
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3b1b69a: feat: provider-defined tools
|
|
8
|
+
- Updated dependencies [aa98cdb]
|
|
9
|
+
- Updated dependencies [1486128]
|
|
10
|
+
- Updated dependencies [7b937c5]
|
|
11
|
+
- Updated dependencies [3b1b69a]
|
|
12
|
+
- Updated dependencies [811a317]
|
|
13
|
+
- @ai-sdk/provider-utils@1.0.22
|
|
14
|
+
- @ai-sdk/provider@0.0.26
|
|
15
|
+
|
|
16
|
+
## 0.0.69
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- b9b0d7b: feat (ai): access raw request body
|
|
21
|
+
- Updated dependencies [b9b0d7b]
|
|
22
|
+
- @ai-sdk/provider@0.0.25
|
|
23
|
+
- @ai-sdk/provider-utils@1.0.21
|
|
24
|
+
|
|
25
|
+
## 0.0.68
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- 741ca51: feat (provider/openai): support mp3 and wav audio inputs
|
|
30
|
+
|
|
3
31
|
## 0.0.67
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LanguageModelV1, ProviderV1, EmbeddingModelV1 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
|
|
4
|
-
type OpenAIChatModelId = 'o1-preview' | 'o1-mini' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | (string & {});
|
|
4
|
+
type OpenAIChatModelId = 'o1-preview' | 'o1-mini' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-10-01' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | (string & {});
|
|
5
5
|
interface OpenAIChatSettings {
|
|
6
6
|
/**
|
|
7
7
|
Modify the likelihood of specified tokens appearing in the completion.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LanguageModelV1, ProviderV1, EmbeddingModelV1 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
|
|
4
|
-
type OpenAIChatModelId = 'o1-preview' | 'o1-mini' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | (string & {});
|
|
4
|
+
type OpenAIChatModelId = 'o1-preview' | 'o1-mini' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-10-01' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | (string & {});
|
|
5
5
|
interface OpenAIChatSettings {
|
|
6
6
|
/**
|
|
7
7
|
Modify the likelihood of specified tokens appearing in the completion.
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
30
30
|
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/openai-chat-language-model.ts
|
|
33
|
-
var
|
|
33
|
+
var import_provider3 = require("@ai-sdk/provider");
|
|
34
34
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
35
35
|
var import_zod2 = require("zod");
|
|
36
36
|
|
|
@@ -72,9 +72,31 @@ function convertToOpenAIChatMessages({
|
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
case "file": {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
if (part.data instanceof URL) {
|
|
76
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
77
|
+
functionality: "'File content parts with URL data' functionality not supported."
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
switch (part.mimeType) {
|
|
81
|
+
case "audio/wav": {
|
|
82
|
+
return {
|
|
83
|
+
type: "input_audio",
|
|
84
|
+
input_audio: { data: part.data, format: "wav" }
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
case "audio/mp3":
|
|
88
|
+
case "audio/mpeg": {
|
|
89
|
+
return {
|
|
90
|
+
type: "input_audio",
|
|
91
|
+
input_audio: { data: part.data, format: "mp3" }
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
default: {
|
|
95
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
96
|
+
functionality: `File content part type ${part.mimeType} in user messages`
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
78
100
|
}
|
|
79
101
|
}
|
|
80
102
|
})
|
|
@@ -216,6 +238,105 @@ function getResponseMetadata({
|
|
|
216
238
|
};
|
|
217
239
|
}
|
|
218
240
|
|
|
241
|
+
// src/openai-prepare-tools.ts
|
|
242
|
+
var import_provider2 = require("@ai-sdk/provider");
|
|
243
|
+
function prepareTools({
|
|
244
|
+
mode,
|
|
245
|
+
useLegacyFunctionCalling = false,
|
|
246
|
+
structuredOutputs = false
|
|
247
|
+
}) {
|
|
248
|
+
var _a;
|
|
249
|
+
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
|
250
|
+
const toolWarnings = [];
|
|
251
|
+
if (tools == null) {
|
|
252
|
+
return { tools: void 0, tool_choice: void 0, toolWarnings };
|
|
253
|
+
}
|
|
254
|
+
const toolChoice = mode.toolChoice;
|
|
255
|
+
if (useLegacyFunctionCalling) {
|
|
256
|
+
const openaiFunctions = [];
|
|
257
|
+
for (const tool of tools) {
|
|
258
|
+
if (tool.type === "provider-defined") {
|
|
259
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
260
|
+
} else {
|
|
261
|
+
openaiFunctions.push({
|
|
262
|
+
name: tool.name,
|
|
263
|
+
description: tool.description,
|
|
264
|
+
parameters: tool.parameters
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (toolChoice == null) {
|
|
269
|
+
return {
|
|
270
|
+
functions: openaiFunctions,
|
|
271
|
+
function_call: void 0,
|
|
272
|
+
toolWarnings
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
const type2 = toolChoice.type;
|
|
276
|
+
switch (type2) {
|
|
277
|
+
case "auto":
|
|
278
|
+
case "none":
|
|
279
|
+
case void 0:
|
|
280
|
+
return {
|
|
281
|
+
functions: openaiFunctions,
|
|
282
|
+
function_call: void 0,
|
|
283
|
+
toolWarnings
|
|
284
|
+
};
|
|
285
|
+
case "required":
|
|
286
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
287
|
+
functionality: "useLegacyFunctionCalling and toolChoice: required"
|
|
288
|
+
});
|
|
289
|
+
default:
|
|
290
|
+
return {
|
|
291
|
+
functions: openaiFunctions,
|
|
292
|
+
function_call: { name: toolChoice.toolName },
|
|
293
|
+
toolWarnings
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const openaiTools = [];
|
|
298
|
+
for (const tool of tools) {
|
|
299
|
+
if (tool.type === "provider-defined") {
|
|
300
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
301
|
+
} else {
|
|
302
|
+
openaiTools.push({
|
|
303
|
+
type: "function",
|
|
304
|
+
function: {
|
|
305
|
+
name: tool.name,
|
|
306
|
+
description: tool.description,
|
|
307
|
+
parameters: tool.parameters,
|
|
308
|
+
strict: structuredOutputs === true ? true : void 0
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (toolChoice == null) {
|
|
314
|
+
return { tools: openaiTools, tool_choice: void 0, toolWarnings };
|
|
315
|
+
}
|
|
316
|
+
const type = toolChoice.type;
|
|
317
|
+
switch (type) {
|
|
318
|
+
case "auto":
|
|
319
|
+
case "none":
|
|
320
|
+
case "required":
|
|
321
|
+
return { tools: openaiTools, tool_choice: type, toolWarnings };
|
|
322
|
+
case "tool":
|
|
323
|
+
return {
|
|
324
|
+
tools: openaiTools,
|
|
325
|
+
tool_choice: {
|
|
326
|
+
type: "function",
|
|
327
|
+
function: {
|
|
328
|
+
name: toolChoice.toolName
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
toolWarnings
|
|
332
|
+
};
|
|
333
|
+
default: {
|
|
334
|
+
const _exhaustiveCheck = type;
|
|
335
|
+
throw new Error(`Unsupported tool choice type: ${_exhaustiveCheck}`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
219
340
|
// src/openai-chat-language-model.ts
|
|
220
341
|
var OpenAIChatLanguageModel = class {
|
|
221
342
|
constructor(modelId, settings, config) {
|
|
@@ -228,6 +349,9 @@ var OpenAIChatLanguageModel = class {
|
|
|
228
349
|
return this.settings.structuredOutputs === true;
|
|
229
350
|
}
|
|
230
351
|
get defaultObjectGenerationMode() {
|
|
352
|
+
if (isAudioModel(this.modelId)) {
|
|
353
|
+
return "tool";
|
|
354
|
+
}
|
|
231
355
|
return this.supportsStructuredOutputs ? "json" : "tool";
|
|
232
356
|
}
|
|
233
357
|
get provider() {
|
|
@@ -268,12 +392,12 @@ var OpenAIChatLanguageModel = class {
|
|
|
268
392
|
}
|
|
269
393
|
const useLegacyFunctionCalling = this.settings.useLegacyFunctionCalling;
|
|
270
394
|
if (useLegacyFunctionCalling && this.settings.parallelToolCalls === true) {
|
|
271
|
-
throw new
|
|
395
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
272
396
|
functionality: "useLegacyFunctionCalling with parallelToolCalls"
|
|
273
397
|
});
|
|
274
398
|
}
|
|
275
399
|
if (useLegacyFunctionCalling && this.settings.structuredOutputs === true) {
|
|
276
|
-
throw new
|
|
400
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
277
401
|
functionality: "structuredOutputs with useLegacyFunctionCalling"
|
|
278
402
|
});
|
|
279
403
|
}
|
|
@@ -314,16 +438,20 @@ var OpenAIChatLanguageModel = class {
|
|
|
314
438
|
}
|
|
315
439
|
switch (type) {
|
|
316
440
|
case "regular": {
|
|
441
|
+
const { tools, tool_choice, functions, function_call, toolWarnings } = prepareTools({
|
|
442
|
+
mode,
|
|
443
|
+
useLegacyFunctionCalling,
|
|
444
|
+
structuredOutputs: this.settings.structuredOutputs
|
|
445
|
+
});
|
|
317
446
|
return {
|
|
318
447
|
args: {
|
|
319
448
|
...baseArgs,
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
})
|
|
449
|
+
tools,
|
|
450
|
+
tool_choice,
|
|
451
|
+
functions,
|
|
452
|
+
function_call
|
|
325
453
|
},
|
|
326
|
-
warnings
|
|
454
|
+
warnings: [...warnings, ...toolWarnings]
|
|
327
455
|
};
|
|
328
456
|
}
|
|
329
457
|
case "object-json": {
|
|
@@ -386,14 +514,14 @@ var OpenAIChatLanguageModel = class {
|
|
|
386
514
|
}
|
|
387
515
|
async doGenerate(options) {
|
|
388
516
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
389
|
-
const { args, warnings } = this.getArgs(options);
|
|
517
|
+
const { args: body, warnings } = this.getArgs(options);
|
|
390
518
|
const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
|
|
391
519
|
url: this.config.url({
|
|
392
520
|
path: "/chat/completions",
|
|
393
521
|
modelId: this.modelId
|
|
394
522
|
}),
|
|
395
523
|
headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
|
|
396
|
-
body
|
|
524
|
+
body,
|
|
397
525
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
398
526
|
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
|
399
527
|
openAIChatResponseSchema
|
|
@@ -401,7 +529,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
401
529
|
abortSignal: options.abortSignal,
|
|
402
530
|
fetch: this.config.fetch
|
|
403
531
|
});
|
|
404
|
-
const { messages: rawPrompt, ...rawSettings } =
|
|
532
|
+
const { messages: rawPrompt, ...rawSettings } = body;
|
|
405
533
|
const choice = response.choices[0];
|
|
406
534
|
let providerMetadata;
|
|
407
535
|
if (((_b = (_a = response.usage) == null ? void 0 : _a.completion_tokens_details) == null ? void 0 : _b.reasoning_tokens) != null || ((_d = (_c = response.usage) == null ? void 0 : _c.prompt_tokens_details) == null ? void 0 : _d.cached_tokens) != null) {
|
|
@@ -438,6 +566,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
438
566
|
},
|
|
439
567
|
rawCall: { rawPrompt, rawSettings },
|
|
440
568
|
rawResponse: { headers: responseHeaders },
|
|
569
|
+
request: { body: JSON.stringify(body) },
|
|
441
570
|
response: getResponseMetadata(response),
|
|
442
571
|
warnings,
|
|
443
572
|
logprobs: mapOpenAIChatLogProbsOutput(choice.logprobs),
|
|
@@ -482,18 +611,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
482
611
|
};
|
|
483
612
|
}
|
|
484
613
|
const { args, warnings } = this.getArgs(options);
|
|
614
|
+
const body = {
|
|
615
|
+
...args,
|
|
616
|
+
stream: true,
|
|
617
|
+
// only include stream_options when in strict compatibility mode:
|
|
618
|
+
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
619
|
+
};
|
|
485
620
|
const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
|
|
486
621
|
url: this.config.url({
|
|
487
622
|
path: "/chat/completions",
|
|
488
623
|
modelId: this.modelId
|
|
489
624
|
}),
|
|
490
625
|
headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
|
|
491
|
-
body
|
|
492
|
-
...args,
|
|
493
|
-
stream: true,
|
|
494
|
-
// only include stream_options when in strict compatibility mode:
|
|
495
|
-
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
496
|
-
},
|
|
626
|
+
body,
|
|
497
627
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
498
628
|
successfulResponseHandler: (0, import_provider_utils3.createEventSourceResponseHandler)(
|
|
499
629
|
openaiChatChunkSchema
|
|
@@ -582,19 +712,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
582
712
|
const index = toolCallDelta.index;
|
|
583
713
|
if (toolCalls[index] == null) {
|
|
584
714
|
if (toolCallDelta.type !== "function") {
|
|
585
|
-
throw new
|
|
715
|
+
throw new import_provider3.InvalidResponseDataError({
|
|
586
716
|
data: toolCallDelta,
|
|
587
717
|
message: `Expected 'function' type.`
|
|
588
718
|
});
|
|
589
719
|
}
|
|
590
720
|
if (toolCallDelta.id == null) {
|
|
591
|
-
throw new
|
|
721
|
+
throw new import_provider3.InvalidResponseDataError({
|
|
592
722
|
data: toolCallDelta,
|
|
593
723
|
message: `Expected 'id' to be a string.`
|
|
594
724
|
});
|
|
595
725
|
}
|
|
596
726
|
if (((_e = toolCallDelta.function) == null ? void 0 : _e.name) == null) {
|
|
597
|
-
throw new
|
|
727
|
+
throw new import_provider3.InvalidResponseDataError({
|
|
598
728
|
data: toolCallDelta,
|
|
599
729
|
message: `Expected 'function.name' to be a string.`
|
|
600
730
|
});
|
|
@@ -670,6 +800,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
670
800
|
),
|
|
671
801
|
rawCall: { rawPrompt, rawSettings },
|
|
672
802
|
rawResponse: { headers: responseHeaders },
|
|
803
|
+
request: { body: JSON.stringify(body) },
|
|
673
804
|
warnings
|
|
674
805
|
};
|
|
675
806
|
}
|
|
@@ -776,91 +907,20 @@ var openaiChatChunkSchema = import_zod2.z.union([
|
|
|
776
907
|
}),
|
|
777
908
|
openAIErrorDataSchema
|
|
778
909
|
]);
|
|
779
|
-
function prepareToolsAndToolChoice({
|
|
780
|
-
mode,
|
|
781
|
-
useLegacyFunctionCalling = false,
|
|
782
|
-
structuredOutputs = false
|
|
783
|
-
}) {
|
|
784
|
-
var _a;
|
|
785
|
-
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
|
786
|
-
if (tools == null) {
|
|
787
|
-
return { tools: void 0, tool_choice: void 0 };
|
|
788
|
-
}
|
|
789
|
-
const toolChoice = mode.toolChoice;
|
|
790
|
-
if (useLegacyFunctionCalling) {
|
|
791
|
-
const mappedFunctions = tools.map((tool) => ({
|
|
792
|
-
name: tool.name,
|
|
793
|
-
description: tool.description,
|
|
794
|
-
parameters: tool.parameters
|
|
795
|
-
}));
|
|
796
|
-
if (toolChoice == null) {
|
|
797
|
-
return { functions: mappedFunctions, function_call: void 0 };
|
|
798
|
-
}
|
|
799
|
-
const type2 = toolChoice.type;
|
|
800
|
-
switch (type2) {
|
|
801
|
-
case "auto":
|
|
802
|
-
case "none":
|
|
803
|
-
case void 0:
|
|
804
|
-
return {
|
|
805
|
-
functions: mappedFunctions,
|
|
806
|
-
function_call: void 0
|
|
807
|
-
};
|
|
808
|
-
case "required":
|
|
809
|
-
throw new import_provider2.UnsupportedFunctionalityError({
|
|
810
|
-
functionality: "useLegacyFunctionCalling and toolChoice: required"
|
|
811
|
-
});
|
|
812
|
-
default:
|
|
813
|
-
return {
|
|
814
|
-
functions: mappedFunctions,
|
|
815
|
-
function_call: { name: toolChoice.toolName }
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
const mappedTools = tools.map((tool) => ({
|
|
820
|
-
type: "function",
|
|
821
|
-
function: {
|
|
822
|
-
name: tool.name,
|
|
823
|
-
description: tool.description,
|
|
824
|
-
parameters: tool.parameters,
|
|
825
|
-
strict: structuredOutputs === true ? true : void 0
|
|
826
|
-
}
|
|
827
|
-
}));
|
|
828
|
-
if (toolChoice == null) {
|
|
829
|
-
return { tools: mappedTools, tool_choice: void 0 };
|
|
830
|
-
}
|
|
831
|
-
const type = toolChoice.type;
|
|
832
|
-
switch (type) {
|
|
833
|
-
case "auto":
|
|
834
|
-
case "none":
|
|
835
|
-
case "required":
|
|
836
|
-
return { tools: mappedTools, tool_choice: type };
|
|
837
|
-
case "tool":
|
|
838
|
-
return {
|
|
839
|
-
tools: mappedTools,
|
|
840
|
-
tool_choice: {
|
|
841
|
-
type: "function",
|
|
842
|
-
function: {
|
|
843
|
-
name: toolChoice.toolName
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
};
|
|
847
|
-
default: {
|
|
848
|
-
const _exhaustiveCheck = type;
|
|
849
|
-
throw new Error(`Unsupported tool choice type: ${_exhaustiveCheck}`);
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
910
|
function isReasoningModel(modelId) {
|
|
854
911
|
return modelId.startsWith("o1-");
|
|
855
912
|
}
|
|
913
|
+
function isAudioModel(modelId) {
|
|
914
|
+
return modelId.startsWith("gpt-4o-audio-preview");
|
|
915
|
+
}
|
|
856
916
|
|
|
857
917
|
// src/openai-completion-language-model.ts
|
|
858
|
-
var
|
|
918
|
+
var import_provider5 = require("@ai-sdk/provider");
|
|
859
919
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
860
920
|
var import_zod3 = require("zod");
|
|
861
921
|
|
|
862
922
|
// src/convert-to-openai-completion-prompt.ts
|
|
863
|
-
var
|
|
923
|
+
var import_provider4 = require("@ai-sdk/provider");
|
|
864
924
|
function convertToOpenAICompletionPrompt({
|
|
865
925
|
prompt,
|
|
866
926
|
inputFormat,
|
|
@@ -880,7 +940,7 @@ function convertToOpenAICompletionPrompt({
|
|
|
880
940
|
for (const { role, content } of prompt) {
|
|
881
941
|
switch (role) {
|
|
882
942
|
case "system": {
|
|
883
|
-
throw new
|
|
943
|
+
throw new import_provider4.InvalidPromptError({
|
|
884
944
|
message: "Unexpected system message in prompt: ${content}",
|
|
885
945
|
prompt
|
|
886
946
|
});
|
|
@@ -892,7 +952,7 @@ function convertToOpenAICompletionPrompt({
|
|
|
892
952
|
return part.text;
|
|
893
953
|
}
|
|
894
954
|
case "image": {
|
|
895
|
-
throw new
|
|
955
|
+
throw new import_provider4.UnsupportedFunctionalityError({
|
|
896
956
|
functionality: "images"
|
|
897
957
|
});
|
|
898
958
|
}
|
|
@@ -911,7 +971,7 @@ ${userMessage}
|
|
|
911
971
|
return part.text;
|
|
912
972
|
}
|
|
913
973
|
case "tool-call": {
|
|
914
|
-
throw new
|
|
974
|
+
throw new import_provider4.UnsupportedFunctionalityError({
|
|
915
975
|
functionality: "tool-call messages"
|
|
916
976
|
});
|
|
917
977
|
}
|
|
@@ -924,7 +984,7 @@ ${assistantMessage}
|
|
|
924
984
|
break;
|
|
925
985
|
}
|
|
926
986
|
case "tool": {
|
|
927
|
-
throw new
|
|
987
|
+
throw new import_provider4.UnsupportedFunctionalityError({
|
|
928
988
|
functionality: "tool messages"
|
|
929
989
|
});
|
|
930
990
|
}
|
|
@@ -1025,24 +1085,24 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1025
1085
|
switch (type) {
|
|
1026
1086
|
case "regular": {
|
|
1027
1087
|
if ((_a = mode.tools) == null ? void 0 : _a.length) {
|
|
1028
|
-
throw new
|
|
1088
|
+
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1029
1089
|
functionality: "tools"
|
|
1030
1090
|
});
|
|
1031
1091
|
}
|
|
1032
1092
|
if (mode.toolChoice) {
|
|
1033
|
-
throw new
|
|
1093
|
+
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1034
1094
|
functionality: "toolChoice"
|
|
1035
1095
|
});
|
|
1036
1096
|
}
|
|
1037
1097
|
return { args: baseArgs, warnings };
|
|
1038
1098
|
}
|
|
1039
1099
|
case "object-json": {
|
|
1040
|
-
throw new
|
|
1100
|
+
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1041
1101
|
functionality: "object-json mode"
|
|
1042
1102
|
});
|
|
1043
1103
|
}
|
|
1044
1104
|
case "object-tool": {
|
|
1045
|
-
throw new
|
|
1105
|
+
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1046
1106
|
functionality: "object-tool mode"
|
|
1047
1107
|
});
|
|
1048
1108
|
}
|
|
@@ -1081,23 +1141,25 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1081
1141
|
rawCall: { rawPrompt, rawSettings },
|
|
1082
1142
|
rawResponse: { headers: responseHeaders },
|
|
1083
1143
|
response: getResponseMetadata(response),
|
|
1084
|
-
warnings
|
|
1144
|
+
warnings,
|
|
1145
|
+
request: { body: JSON.stringify(args) }
|
|
1085
1146
|
};
|
|
1086
1147
|
}
|
|
1087
1148
|
async doStream(options) {
|
|
1088
1149
|
const { args, warnings } = this.getArgs(options);
|
|
1150
|
+
const body = {
|
|
1151
|
+
...args,
|
|
1152
|
+
stream: true,
|
|
1153
|
+
// only include stream_options when in strict compatibility mode:
|
|
1154
|
+
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
1155
|
+
};
|
|
1089
1156
|
const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
|
|
1090
1157
|
url: this.config.url({
|
|
1091
1158
|
path: "/completions",
|
|
1092
1159
|
modelId: this.modelId
|
|
1093
1160
|
}),
|
|
1094
1161
|
headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.headers),
|
|
1095
|
-
body
|
|
1096
|
-
...args,
|
|
1097
|
-
stream: true,
|
|
1098
|
-
// only include stream_options when in strict compatibility mode:
|
|
1099
|
-
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
1100
|
-
},
|
|
1162
|
+
body,
|
|
1101
1163
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1102
1164
|
successfulResponseHandler: (0, import_provider_utils4.createEventSourceResponseHandler)(
|
|
1103
1165
|
openaiCompletionChunkSchema
|
|
@@ -1171,7 +1233,8 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1171
1233
|
),
|
|
1172
1234
|
rawCall: { rawPrompt, rawSettings },
|
|
1173
1235
|
rawResponse: { headers: responseHeaders },
|
|
1174
|
-
warnings
|
|
1236
|
+
warnings,
|
|
1237
|
+
request: { body: JSON.stringify(body) }
|
|
1175
1238
|
};
|
|
1176
1239
|
}
|
|
1177
1240
|
};
|
|
@@ -1271,7 +1334,7 @@ var OpenAI = class {
|
|
|
1271
1334
|
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1272
1335
|
|
|
1273
1336
|
// src/openai-embedding-model.ts
|
|
1274
|
-
var
|
|
1337
|
+
var import_provider6 = require("@ai-sdk/provider");
|
|
1275
1338
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1276
1339
|
var import_zod4 = require("zod");
|
|
1277
1340
|
var OpenAIEmbeddingModel = class {
|
|
@@ -1298,7 +1361,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1298
1361
|
abortSignal
|
|
1299
1362
|
}) {
|
|
1300
1363
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1301
|
-
throw new
|
|
1364
|
+
throw new import_provider6.TooManyEmbeddingValuesForCallError({
|
|
1302
1365
|
provider: this.provider,
|
|
1303
1366
|
modelId: this.modelId,
|
|
1304
1367
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|