@ai-sdk/openai 2.0.0-canary.6 → 2.0.0-canary.7
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 +22 -0
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +32 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -24
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +6 -6
- package/dist/internal/index.d.ts +6 -6
- package/dist/internal/index.js +32 -24
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +32 -24
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/internal/index.mjs
CHANGED
|
@@ -544,7 +544,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
544
544
|
};
|
|
545
545
|
}
|
|
546
546
|
async doGenerate(options) {
|
|
547
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
547
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
548
548
|
const { args: body, warnings } = this.getArgs(options);
|
|
549
549
|
const {
|
|
550
550
|
responseHeaders,
|
|
@@ -582,10 +582,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
582
582
|
providerMetadata.openai.cachedPromptTokens = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens;
|
|
583
583
|
}
|
|
584
584
|
return {
|
|
585
|
-
text:
|
|
586
|
-
toolCalls: (
|
|
585
|
+
text: choice.message.content != null ? { type: "text", text: choice.message.content } : void 0,
|
|
586
|
+
toolCalls: (_c = choice.message.tool_calls) == null ? void 0 : _c.map((toolCall) => {
|
|
587
587
|
var _a2;
|
|
588
588
|
return {
|
|
589
|
+
type: "tool-call",
|
|
589
590
|
toolCallType: "function",
|
|
590
591
|
toolCallId: (_a2 = toolCall.id) != null ? _a2 : generateId(),
|
|
591
592
|
toolName: toolCall.function.name,
|
|
@@ -594,8 +595,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
594
595
|
}),
|
|
595
596
|
finishReason: mapOpenAIFinishReason(choice.finish_reason),
|
|
596
597
|
usage: {
|
|
597
|
-
inputTokens: (
|
|
598
|
-
outputTokens: (
|
|
598
|
+
inputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.prompt_tokens) != null ? _e : void 0,
|
|
599
|
+
outputTokens: (_g = (_f = response.usage) == null ? void 0 : _f.completion_tokens) != null ? _g : void 0
|
|
599
600
|
},
|
|
600
601
|
request: { body },
|
|
601
602
|
response: {
|
|
@@ -695,8 +696,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
695
696
|
const delta = choice.delta;
|
|
696
697
|
if (delta.content != null) {
|
|
697
698
|
controller.enqueue({
|
|
698
|
-
type: "text
|
|
699
|
-
|
|
699
|
+
type: "text",
|
|
700
|
+
text: delta.content
|
|
700
701
|
});
|
|
701
702
|
}
|
|
702
703
|
const mappedLogprobs = mapOpenAIChatLogProbsOutput(
|
|
@@ -1133,7 +1134,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1133
1134
|
});
|
|
1134
1135
|
const choice = response.choices[0];
|
|
1135
1136
|
return {
|
|
1136
|
-
text: choice.text,
|
|
1137
|
+
text: { type: "text", text: choice.text },
|
|
1137
1138
|
usage: {
|
|
1138
1139
|
inputTokens: response.usage.prompt_tokens,
|
|
1139
1140
|
outputTokens: response.usage.completion_tokens
|
|
@@ -1210,8 +1211,8 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1210
1211
|
}
|
|
1211
1212
|
if ((choice == null ? void 0 : choice.text) != null) {
|
|
1212
1213
|
controller.enqueue({
|
|
1213
|
-
type: "text
|
|
1214
|
-
|
|
1214
|
+
type: "text",
|
|
1215
|
+
text: choice.text
|
|
1215
1216
|
});
|
|
1216
1217
|
}
|
|
1217
1218
|
const mappedLogprobs = mapOpenAICompletionLogProbs(
|
|
@@ -1295,7 +1296,7 @@ import {
|
|
|
1295
1296
|
import { z as z5 } from "zod";
|
|
1296
1297
|
var OpenAIEmbeddingModel = class {
|
|
1297
1298
|
constructor(modelId, settings, config) {
|
|
1298
|
-
this.specificationVersion = "
|
|
1299
|
+
this.specificationVersion = "v2";
|
|
1299
1300
|
this.modelId = modelId;
|
|
1300
1301
|
this.settings = settings;
|
|
1301
1302
|
this.config = config;
|
|
@@ -1324,7 +1325,11 @@ var OpenAIEmbeddingModel = class {
|
|
|
1324
1325
|
values
|
|
1325
1326
|
});
|
|
1326
1327
|
}
|
|
1327
|
-
const {
|
|
1328
|
+
const {
|
|
1329
|
+
responseHeaders,
|
|
1330
|
+
value: response,
|
|
1331
|
+
rawValue
|
|
1332
|
+
} = await postJsonToApi3({
|
|
1328
1333
|
url: this.config.url({
|
|
1329
1334
|
path: "/embeddings",
|
|
1330
1335
|
modelId: this.modelId
|
|
@@ -1347,7 +1352,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1347
1352
|
return {
|
|
1348
1353
|
embeddings: response.data.map((item) => item.embedding),
|
|
1349
1354
|
usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
|
|
1350
|
-
|
|
1355
|
+
response: { headers: responseHeaders, body: rawValue }
|
|
1351
1356
|
};
|
|
1352
1357
|
}
|
|
1353
1358
|
};
|
|
@@ -1453,7 +1458,7 @@ import {
|
|
|
1453
1458
|
postFormDataToApi
|
|
1454
1459
|
} from "@ai-sdk/provider-utils";
|
|
1455
1460
|
import { z as z7 } from "zod";
|
|
1456
|
-
var
|
|
1461
|
+
var openAIProviderOptionsSchema = z7.object({
|
|
1457
1462
|
include: z7.array(z7.string()).nullish(),
|
|
1458
1463
|
language: z7.string().nullish(),
|
|
1459
1464
|
prompt: z7.string().nullish(),
|
|
@@ -1538,7 +1543,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1538
1543
|
const openAIOptions = parseProviderOptions2({
|
|
1539
1544
|
provider: "openai",
|
|
1540
1545
|
providerOptions,
|
|
1541
|
-
schema:
|
|
1546
|
+
schema: openAIProviderOptionsSchema
|
|
1542
1547
|
});
|
|
1543
1548
|
const formData = new FormData();
|
|
1544
1549
|
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
@@ -2033,17 +2038,22 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2033
2038
|
});
|
|
2034
2039
|
const outputTextElements = response.output.filter((output) => output.type === "message").flatMap((output) => output.content).filter((content) => content.type === "output_text");
|
|
2035
2040
|
const toolCalls = response.output.filter((output) => output.type === "function_call").map((output) => ({
|
|
2041
|
+
type: "tool-call",
|
|
2036
2042
|
toolCallType: "function",
|
|
2037
2043
|
toolCallId: output.call_id,
|
|
2038
2044
|
toolName: output.name,
|
|
2039
2045
|
args: output.arguments
|
|
2040
2046
|
}));
|
|
2041
2047
|
return {
|
|
2042
|
-
text:
|
|
2048
|
+
text: {
|
|
2049
|
+
type: "text",
|
|
2050
|
+
text: outputTextElements.map((content) => content.text).join("\n")
|
|
2051
|
+
},
|
|
2043
2052
|
sources: outputTextElements.flatMap(
|
|
2044
2053
|
(content) => content.annotations.map((annotation) => {
|
|
2045
2054
|
var _a2, _b2, _c2;
|
|
2046
2055
|
return {
|
|
2056
|
+
type: "source",
|
|
2047
2057
|
sourceType: "url",
|
|
2048
2058
|
id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : generateId2(),
|
|
2049
2059
|
url: annotation.url,
|
|
@@ -2154,8 +2164,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2154
2164
|
});
|
|
2155
2165
|
} else if (isTextDeltaChunk(value)) {
|
|
2156
2166
|
controller.enqueue({
|
|
2157
|
-
type: "text
|
|
2158
|
-
|
|
2167
|
+
type: "text",
|
|
2168
|
+
text: value.delta
|
|
2159
2169
|
});
|
|
2160
2170
|
} else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
|
|
2161
2171
|
ongoingToolCalls[value.output_index] = void 0;
|
|
@@ -2179,12 +2189,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2179
2189
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2180
2190
|
controller.enqueue({
|
|
2181
2191
|
type: "source",
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
title: value.annotation.title
|
|
2187
|
-
}
|
|
2192
|
+
sourceType: "url",
|
|
2193
|
+
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : generateId2(),
|
|
2194
|
+
url: value.annotation.url,
|
|
2195
|
+
title: value.annotation.title
|
|
2188
2196
|
});
|
|
2189
2197
|
}
|
|
2190
2198
|
},
|