@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/internal/dist/index.js
CHANGED
|
@@ -27,7 +27,7 @@ __export(internal_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(internal_exports);
|
|
28
28
|
|
|
29
29
|
// src/openai-chat-language-model.ts
|
|
30
|
-
var
|
|
30
|
+
var import_provider3 = require("@ai-sdk/provider");
|
|
31
31
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
32
32
|
var import_zod2 = require("zod");
|
|
33
33
|
|
|
@@ -69,9 +69,31 @@ function convertToOpenAIChatMessages({
|
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
case "file": {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
if (part.data instanceof URL) {
|
|
73
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
74
|
+
functionality: "'File content parts with URL data' functionality not supported."
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
switch (part.mimeType) {
|
|
78
|
+
case "audio/wav": {
|
|
79
|
+
return {
|
|
80
|
+
type: "input_audio",
|
|
81
|
+
input_audio: { data: part.data, format: "wav" }
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
case "audio/mp3":
|
|
85
|
+
case "audio/mpeg": {
|
|
86
|
+
return {
|
|
87
|
+
type: "input_audio",
|
|
88
|
+
input_audio: { data: part.data, format: "mp3" }
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
default: {
|
|
92
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
93
|
+
functionality: `File content part type ${part.mimeType} in user messages`
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
75
97
|
}
|
|
76
98
|
}
|
|
77
99
|
})
|
|
@@ -213,6 +235,105 @@ function getResponseMetadata({
|
|
|
213
235
|
};
|
|
214
236
|
}
|
|
215
237
|
|
|
238
|
+
// src/openai-prepare-tools.ts
|
|
239
|
+
var import_provider2 = require("@ai-sdk/provider");
|
|
240
|
+
function prepareTools({
|
|
241
|
+
mode,
|
|
242
|
+
useLegacyFunctionCalling = false,
|
|
243
|
+
structuredOutputs = false
|
|
244
|
+
}) {
|
|
245
|
+
var _a;
|
|
246
|
+
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
|
247
|
+
const toolWarnings = [];
|
|
248
|
+
if (tools == null) {
|
|
249
|
+
return { tools: void 0, tool_choice: void 0, toolWarnings };
|
|
250
|
+
}
|
|
251
|
+
const toolChoice = mode.toolChoice;
|
|
252
|
+
if (useLegacyFunctionCalling) {
|
|
253
|
+
const openaiFunctions = [];
|
|
254
|
+
for (const tool of tools) {
|
|
255
|
+
if (tool.type === "provider-defined") {
|
|
256
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
257
|
+
} else {
|
|
258
|
+
openaiFunctions.push({
|
|
259
|
+
name: tool.name,
|
|
260
|
+
description: tool.description,
|
|
261
|
+
parameters: tool.parameters
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (toolChoice == null) {
|
|
266
|
+
return {
|
|
267
|
+
functions: openaiFunctions,
|
|
268
|
+
function_call: void 0,
|
|
269
|
+
toolWarnings
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
const type2 = toolChoice.type;
|
|
273
|
+
switch (type2) {
|
|
274
|
+
case "auto":
|
|
275
|
+
case "none":
|
|
276
|
+
case void 0:
|
|
277
|
+
return {
|
|
278
|
+
functions: openaiFunctions,
|
|
279
|
+
function_call: void 0,
|
|
280
|
+
toolWarnings
|
|
281
|
+
};
|
|
282
|
+
case "required":
|
|
283
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
284
|
+
functionality: "useLegacyFunctionCalling and toolChoice: required"
|
|
285
|
+
});
|
|
286
|
+
default:
|
|
287
|
+
return {
|
|
288
|
+
functions: openaiFunctions,
|
|
289
|
+
function_call: { name: toolChoice.toolName },
|
|
290
|
+
toolWarnings
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const openaiTools = [];
|
|
295
|
+
for (const tool of tools) {
|
|
296
|
+
if (tool.type === "provider-defined") {
|
|
297
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
298
|
+
} else {
|
|
299
|
+
openaiTools.push({
|
|
300
|
+
type: "function",
|
|
301
|
+
function: {
|
|
302
|
+
name: tool.name,
|
|
303
|
+
description: tool.description,
|
|
304
|
+
parameters: tool.parameters,
|
|
305
|
+
strict: structuredOutputs === true ? true : void 0
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (toolChoice == null) {
|
|
311
|
+
return { tools: openaiTools, tool_choice: void 0, toolWarnings };
|
|
312
|
+
}
|
|
313
|
+
const type = toolChoice.type;
|
|
314
|
+
switch (type) {
|
|
315
|
+
case "auto":
|
|
316
|
+
case "none":
|
|
317
|
+
case "required":
|
|
318
|
+
return { tools: openaiTools, tool_choice: type, toolWarnings };
|
|
319
|
+
case "tool":
|
|
320
|
+
return {
|
|
321
|
+
tools: openaiTools,
|
|
322
|
+
tool_choice: {
|
|
323
|
+
type: "function",
|
|
324
|
+
function: {
|
|
325
|
+
name: toolChoice.toolName
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
toolWarnings
|
|
329
|
+
};
|
|
330
|
+
default: {
|
|
331
|
+
const _exhaustiveCheck = type;
|
|
332
|
+
throw new Error(`Unsupported tool choice type: ${_exhaustiveCheck}`);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
216
337
|
// src/openai-chat-language-model.ts
|
|
217
338
|
var OpenAIChatLanguageModel = class {
|
|
218
339
|
constructor(modelId, settings, config) {
|
|
@@ -225,6 +346,9 @@ var OpenAIChatLanguageModel = class {
|
|
|
225
346
|
return this.settings.structuredOutputs === true;
|
|
226
347
|
}
|
|
227
348
|
get defaultObjectGenerationMode() {
|
|
349
|
+
if (isAudioModel(this.modelId)) {
|
|
350
|
+
return "tool";
|
|
351
|
+
}
|
|
228
352
|
return this.supportsStructuredOutputs ? "json" : "tool";
|
|
229
353
|
}
|
|
230
354
|
get provider() {
|
|
@@ -265,12 +389,12 @@ var OpenAIChatLanguageModel = class {
|
|
|
265
389
|
}
|
|
266
390
|
const useLegacyFunctionCalling = this.settings.useLegacyFunctionCalling;
|
|
267
391
|
if (useLegacyFunctionCalling && this.settings.parallelToolCalls === true) {
|
|
268
|
-
throw new
|
|
392
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
269
393
|
functionality: "useLegacyFunctionCalling with parallelToolCalls"
|
|
270
394
|
});
|
|
271
395
|
}
|
|
272
396
|
if (useLegacyFunctionCalling && this.settings.structuredOutputs === true) {
|
|
273
|
-
throw new
|
|
397
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
274
398
|
functionality: "structuredOutputs with useLegacyFunctionCalling"
|
|
275
399
|
});
|
|
276
400
|
}
|
|
@@ -311,16 +435,20 @@ var OpenAIChatLanguageModel = class {
|
|
|
311
435
|
}
|
|
312
436
|
switch (type) {
|
|
313
437
|
case "regular": {
|
|
438
|
+
const { tools, tool_choice, functions, function_call, toolWarnings } = prepareTools({
|
|
439
|
+
mode,
|
|
440
|
+
useLegacyFunctionCalling,
|
|
441
|
+
structuredOutputs: this.settings.structuredOutputs
|
|
442
|
+
});
|
|
314
443
|
return {
|
|
315
444
|
args: {
|
|
316
445
|
...baseArgs,
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
})
|
|
446
|
+
tools,
|
|
447
|
+
tool_choice,
|
|
448
|
+
functions,
|
|
449
|
+
function_call
|
|
322
450
|
},
|
|
323
|
-
warnings
|
|
451
|
+
warnings: [...warnings, ...toolWarnings]
|
|
324
452
|
};
|
|
325
453
|
}
|
|
326
454
|
case "object-json": {
|
|
@@ -383,14 +511,14 @@ var OpenAIChatLanguageModel = class {
|
|
|
383
511
|
}
|
|
384
512
|
async doGenerate(options) {
|
|
385
513
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
386
|
-
const { args, warnings } = this.getArgs(options);
|
|
514
|
+
const { args: body, warnings } = this.getArgs(options);
|
|
387
515
|
const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
|
|
388
516
|
url: this.config.url({
|
|
389
517
|
path: "/chat/completions",
|
|
390
518
|
modelId: this.modelId
|
|
391
519
|
}),
|
|
392
520
|
headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
|
|
393
|
-
body
|
|
521
|
+
body,
|
|
394
522
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
395
523
|
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
|
396
524
|
openAIChatResponseSchema
|
|
@@ -398,7 +526,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
398
526
|
abortSignal: options.abortSignal,
|
|
399
527
|
fetch: this.config.fetch
|
|
400
528
|
});
|
|
401
|
-
const { messages: rawPrompt, ...rawSettings } =
|
|
529
|
+
const { messages: rawPrompt, ...rawSettings } = body;
|
|
402
530
|
const choice = response.choices[0];
|
|
403
531
|
let providerMetadata;
|
|
404
532
|
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) {
|
|
@@ -435,6 +563,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
435
563
|
},
|
|
436
564
|
rawCall: { rawPrompt, rawSettings },
|
|
437
565
|
rawResponse: { headers: responseHeaders },
|
|
566
|
+
request: { body: JSON.stringify(body) },
|
|
438
567
|
response: getResponseMetadata(response),
|
|
439
568
|
warnings,
|
|
440
569
|
logprobs: mapOpenAIChatLogProbsOutput(choice.logprobs),
|
|
@@ -479,18 +608,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
479
608
|
};
|
|
480
609
|
}
|
|
481
610
|
const { args, warnings } = this.getArgs(options);
|
|
611
|
+
const body = {
|
|
612
|
+
...args,
|
|
613
|
+
stream: true,
|
|
614
|
+
// only include stream_options when in strict compatibility mode:
|
|
615
|
+
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
616
|
+
};
|
|
482
617
|
const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
|
|
483
618
|
url: this.config.url({
|
|
484
619
|
path: "/chat/completions",
|
|
485
620
|
modelId: this.modelId
|
|
486
621
|
}),
|
|
487
622
|
headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
|
|
488
|
-
body
|
|
489
|
-
...args,
|
|
490
|
-
stream: true,
|
|
491
|
-
// only include stream_options when in strict compatibility mode:
|
|
492
|
-
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
493
|
-
},
|
|
623
|
+
body,
|
|
494
624
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
495
625
|
successfulResponseHandler: (0, import_provider_utils3.createEventSourceResponseHandler)(
|
|
496
626
|
openaiChatChunkSchema
|
|
@@ -579,19 +709,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
579
709
|
const index = toolCallDelta.index;
|
|
580
710
|
if (toolCalls[index] == null) {
|
|
581
711
|
if (toolCallDelta.type !== "function") {
|
|
582
|
-
throw new
|
|
712
|
+
throw new import_provider3.InvalidResponseDataError({
|
|
583
713
|
data: toolCallDelta,
|
|
584
714
|
message: `Expected 'function' type.`
|
|
585
715
|
});
|
|
586
716
|
}
|
|
587
717
|
if (toolCallDelta.id == null) {
|
|
588
|
-
throw new
|
|
718
|
+
throw new import_provider3.InvalidResponseDataError({
|
|
589
719
|
data: toolCallDelta,
|
|
590
720
|
message: `Expected 'id' to be a string.`
|
|
591
721
|
});
|
|
592
722
|
}
|
|
593
723
|
if (((_e = toolCallDelta.function) == null ? void 0 : _e.name) == null) {
|
|
594
|
-
throw new
|
|
724
|
+
throw new import_provider3.InvalidResponseDataError({
|
|
595
725
|
data: toolCallDelta,
|
|
596
726
|
message: `Expected 'function.name' to be a string.`
|
|
597
727
|
});
|
|
@@ -667,6 +797,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
667
797
|
),
|
|
668
798
|
rawCall: { rawPrompt, rawSettings },
|
|
669
799
|
rawResponse: { headers: responseHeaders },
|
|
800
|
+
request: { body: JSON.stringify(body) },
|
|
670
801
|
warnings
|
|
671
802
|
};
|
|
672
803
|
}
|
|
@@ -773,91 +904,20 @@ var openaiChatChunkSchema = import_zod2.z.union([
|
|
|
773
904
|
}),
|
|
774
905
|
openAIErrorDataSchema
|
|
775
906
|
]);
|
|
776
|
-
function prepareToolsAndToolChoice({
|
|
777
|
-
mode,
|
|
778
|
-
useLegacyFunctionCalling = false,
|
|
779
|
-
structuredOutputs = false
|
|
780
|
-
}) {
|
|
781
|
-
var _a;
|
|
782
|
-
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
|
783
|
-
if (tools == null) {
|
|
784
|
-
return { tools: void 0, tool_choice: void 0 };
|
|
785
|
-
}
|
|
786
|
-
const toolChoice = mode.toolChoice;
|
|
787
|
-
if (useLegacyFunctionCalling) {
|
|
788
|
-
const mappedFunctions = tools.map((tool) => ({
|
|
789
|
-
name: tool.name,
|
|
790
|
-
description: tool.description,
|
|
791
|
-
parameters: tool.parameters
|
|
792
|
-
}));
|
|
793
|
-
if (toolChoice == null) {
|
|
794
|
-
return { functions: mappedFunctions, function_call: void 0 };
|
|
795
|
-
}
|
|
796
|
-
const type2 = toolChoice.type;
|
|
797
|
-
switch (type2) {
|
|
798
|
-
case "auto":
|
|
799
|
-
case "none":
|
|
800
|
-
case void 0:
|
|
801
|
-
return {
|
|
802
|
-
functions: mappedFunctions,
|
|
803
|
-
function_call: void 0
|
|
804
|
-
};
|
|
805
|
-
case "required":
|
|
806
|
-
throw new import_provider2.UnsupportedFunctionalityError({
|
|
807
|
-
functionality: "useLegacyFunctionCalling and toolChoice: required"
|
|
808
|
-
});
|
|
809
|
-
default:
|
|
810
|
-
return {
|
|
811
|
-
functions: mappedFunctions,
|
|
812
|
-
function_call: { name: toolChoice.toolName }
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
const mappedTools = tools.map((tool) => ({
|
|
817
|
-
type: "function",
|
|
818
|
-
function: {
|
|
819
|
-
name: tool.name,
|
|
820
|
-
description: tool.description,
|
|
821
|
-
parameters: tool.parameters,
|
|
822
|
-
strict: structuredOutputs === true ? true : void 0
|
|
823
|
-
}
|
|
824
|
-
}));
|
|
825
|
-
if (toolChoice == null) {
|
|
826
|
-
return { tools: mappedTools, tool_choice: void 0 };
|
|
827
|
-
}
|
|
828
|
-
const type = toolChoice.type;
|
|
829
|
-
switch (type) {
|
|
830
|
-
case "auto":
|
|
831
|
-
case "none":
|
|
832
|
-
case "required":
|
|
833
|
-
return { tools: mappedTools, tool_choice: type };
|
|
834
|
-
case "tool":
|
|
835
|
-
return {
|
|
836
|
-
tools: mappedTools,
|
|
837
|
-
tool_choice: {
|
|
838
|
-
type: "function",
|
|
839
|
-
function: {
|
|
840
|
-
name: toolChoice.toolName
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
};
|
|
844
|
-
default: {
|
|
845
|
-
const _exhaustiveCheck = type;
|
|
846
|
-
throw new Error(`Unsupported tool choice type: ${_exhaustiveCheck}`);
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
907
|
function isReasoningModel(modelId) {
|
|
851
908
|
return modelId.startsWith("o1-");
|
|
852
909
|
}
|
|
910
|
+
function isAudioModel(modelId) {
|
|
911
|
+
return modelId.startsWith("gpt-4o-audio-preview");
|
|
912
|
+
}
|
|
853
913
|
|
|
854
914
|
// src/openai-completion-language-model.ts
|
|
855
|
-
var
|
|
915
|
+
var import_provider5 = require("@ai-sdk/provider");
|
|
856
916
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
857
917
|
var import_zod3 = require("zod");
|
|
858
918
|
|
|
859
919
|
// src/convert-to-openai-completion-prompt.ts
|
|
860
|
-
var
|
|
920
|
+
var import_provider4 = require("@ai-sdk/provider");
|
|
861
921
|
function convertToOpenAICompletionPrompt({
|
|
862
922
|
prompt,
|
|
863
923
|
inputFormat,
|
|
@@ -877,7 +937,7 @@ function convertToOpenAICompletionPrompt({
|
|
|
877
937
|
for (const { role, content } of prompt) {
|
|
878
938
|
switch (role) {
|
|
879
939
|
case "system": {
|
|
880
|
-
throw new
|
|
940
|
+
throw new import_provider4.InvalidPromptError({
|
|
881
941
|
message: "Unexpected system message in prompt: ${content}",
|
|
882
942
|
prompt
|
|
883
943
|
});
|
|
@@ -889,7 +949,7 @@ function convertToOpenAICompletionPrompt({
|
|
|
889
949
|
return part.text;
|
|
890
950
|
}
|
|
891
951
|
case "image": {
|
|
892
|
-
throw new
|
|
952
|
+
throw new import_provider4.UnsupportedFunctionalityError({
|
|
893
953
|
functionality: "images"
|
|
894
954
|
});
|
|
895
955
|
}
|
|
@@ -908,7 +968,7 @@ ${userMessage}
|
|
|
908
968
|
return part.text;
|
|
909
969
|
}
|
|
910
970
|
case "tool-call": {
|
|
911
|
-
throw new
|
|
971
|
+
throw new import_provider4.UnsupportedFunctionalityError({
|
|
912
972
|
functionality: "tool-call messages"
|
|
913
973
|
});
|
|
914
974
|
}
|
|
@@ -921,7 +981,7 @@ ${assistantMessage}
|
|
|
921
981
|
break;
|
|
922
982
|
}
|
|
923
983
|
case "tool": {
|
|
924
|
-
throw new
|
|
984
|
+
throw new import_provider4.UnsupportedFunctionalityError({
|
|
925
985
|
functionality: "tool messages"
|
|
926
986
|
});
|
|
927
987
|
}
|
|
@@ -1022,24 +1082,24 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1022
1082
|
switch (type) {
|
|
1023
1083
|
case "regular": {
|
|
1024
1084
|
if ((_a = mode.tools) == null ? void 0 : _a.length) {
|
|
1025
|
-
throw new
|
|
1085
|
+
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1026
1086
|
functionality: "tools"
|
|
1027
1087
|
});
|
|
1028
1088
|
}
|
|
1029
1089
|
if (mode.toolChoice) {
|
|
1030
|
-
throw new
|
|
1090
|
+
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1031
1091
|
functionality: "toolChoice"
|
|
1032
1092
|
});
|
|
1033
1093
|
}
|
|
1034
1094
|
return { args: baseArgs, warnings };
|
|
1035
1095
|
}
|
|
1036
1096
|
case "object-json": {
|
|
1037
|
-
throw new
|
|
1097
|
+
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1038
1098
|
functionality: "object-json mode"
|
|
1039
1099
|
});
|
|
1040
1100
|
}
|
|
1041
1101
|
case "object-tool": {
|
|
1042
|
-
throw new
|
|
1102
|
+
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1043
1103
|
functionality: "object-tool mode"
|
|
1044
1104
|
});
|
|
1045
1105
|
}
|
|
@@ -1078,23 +1138,25 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1078
1138
|
rawCall: { rawPrompt, rawSettings },
|
|
1079
1139
|
rawResponse: { headers: responseHeaders },
|
|
1080
1140
|
response: getResponseMetadata(response),
|
|
1081
|
-
warnings
|
|
1141
|
+
warnings,
|
|
1142
|
+
request: { body: JSON.stringify(args) }
|
|
1082
1143
|
};
|
|
1083
1144
|
}
|
|
1084
1145
|
async doStream(options) {
|
|
1085
1146
|
const { args, warnings } = this.getArgs(options);
|
|
1147
|
+
const body = {
|
|
1148
|
+
...args,
|
|
1149
|
+
stream: true,
|
|
1150
|
+
// only include stream_options when in strict compatibility mode:
|
|
1151
|
+
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
1152
|
+
};
|
|
1086
1153
|
const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
|
|
1087
1154
|
url: this.config.url({
|
|
1088
1155
|
path: "/completions",
|
|
1089
1156
|
modelId: this.modelId
|
|
1090
1157
|
}),
|
|
1091
1158
|
headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.headers),
|
|
1092
|
-
body
|
|
1093
|
-
...args,
|
|
1094
|
-
stream: true,
|
|
1095
|
-
// only include stream_options when in strict compatibility mode:
|
|
1096
|
-
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
1097
|
-
},
|
|
1159
|
+
body,
|
|
1098
1160
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1099
1161
|
successfulResponseHandler: (0, import_provider_utils4.createEventSourceResponseHandler)(
|
|
1100
1162
|
openaiCompletionChunkSchema
|
|
@@ -1168,7 +1230,8 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1168
1230
|
),
|
|
1169
1231
|
rawCall: { rawPrompt, rawSettings },
|
|
1170
1232
|
rawResponse: { headers: responseHeaders },
|
|
1171
|
-
warnings
|
|
1233
|
+
warnings,
|
|
1234
|
+
request: { body: JSON.stringify(body) }
|
|
1172
1235
|
};
|
|
1173
1236
|
}
|
|
1174
1237
|
};
|
|
@@ -1218,7 +1281,7 @@ var openaiCompletionChunkSchema = import_zod3.z.union([
|
|
|
1218
1281
|
]);
|
|
1219
1282
|
|
|
1220
1283
|
// src/openai-embedding-model.ts
|
|
1221
|
-
var
|
|
1284
|
+
var import_provider6 = require("@ai-sdk/provider");
|
|
1222
1285
|
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
1223
1286
|
var import_zod4 = require("zod");
|
|
1224
1287
|
var OpenAIEmbeddingModel = class {
|
|
@@ -1245,7 +1308,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1245
1308
|
abortSignal
|
|
1246
1309
|
}) {
|
|
1247
1310
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1248
|
-
throw new
|
|
1311
|
+
throw new import_provider6.TooManyEmbeddingValuesForCallError({
|
|
1249
1312
|
provider: this.provider,
|
|
1250
1313
|
modelId: this.modelId,
|
|
1251
1314
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|