@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/index.mjs
CHANGED
|
@@ -550,7 +550,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
550
550
|
};
|
|
551
551
|
}
|
|
552
552
|
async doGenerate(options) {
|
|
553
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
553
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
554
554
|
const { args: body, warnings } = this.getArgs(options);
|
|
555
555
|
const {
|
|
556
556
|
responseHeaders,
|
|
@@ -588,10 +588,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
588
588
|
providerMetadata.openai.cachedPromptTokens = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens;
|
|
589
589
|
}
|
|
590
590
|
return {
|
|
591
|
-
text:
|
|
592
|
-
toolCalls: (
|
|
591
|
+
text: choice.message.content != null ? { type: "text", text: choice.message.content } : void 0,
|
|
592
|
+
toolCalls: (_c = choice.message.tool_calls) == null ? void 0 : _c.map((toolCall) => {
|
|
593
593
|
var _a2;
|
|
594
594
|
return {
|
|
595
|
+
type: "tool-call",
|
|
595
596
|
toolCallType: "function",
|
|
596
597
|
toolCallId: (_a2 = toolCall.id) != null ? _a2 : generateId(),
|
|
597
598
|
toolName: toolCall.function.name,
|
|
@@ -600,8 +601,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
600
601
|
}),
|
|
601
602
|
finishReason: mapOpenAIFinishReason(choice.finish_reason),
|
|
602
603
|
usage: {
|
|
603
|
-
inputTokens: (
|
|
604
|
-
outputTokens: (
|
|
604
|
+
inputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.prompt_tokens) != null ? _e : void 0,
|
|
605
|
+
outputTokens: (_g = (_f = response.usage) == null ? void 0 : _f.completion_tokens) != null ? _g : void 0
|
|
605
606
|
},
|
|
606
607
|
request: { body },
|
|
607
608
|
response: {
|
|
@@ -701,8 +702,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
701
702
|
const delta = choice.delta;
|
|
702
703
|
if (delta.content != null) {
|
|
703
704
|
controller.enqueue({
|
|
704
|
-
type: "text
|
|
705
|
-
|
|
705
|
+
type: "text",
|
|
706
|
+
text: delta.content
|
|
706
707
|
});
|
|
707
708
|
}
|
|
708
709
|
const mappedLogprobs = mapOpenAIChatLogProbsOutput(
|
|
@@ -1139,7 +1140,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1139
1140
|
});
|
|
1140
1141
|
const choice = response.choices[0];
|
|
1141
1142
|
return {
|
|
1142
|
-
text: choice.text,
|
|
1143
|
+
text: { type: "text", text: choice.text },
|
|
1143
1144
|
usage: {
|
|
1144
1145
|
inputTokens: response.usage.prompt_tokens,
|
|
1145
1146
|
outputTokens: response.usage.completion_tokens
|
|
@@ -1216,8 +1217,8 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1216
1217
|
}
|
|
1217
1218
|
if ((choice == null ? void 0 : choice.text) != null) {
|
|
1218
1219
|
controller.enqueue({
|
|
1219
|
-
type: "text
|
|
1220
|
-
|
|
1220
|
+
type: "text",
|
|
1221
|
+
text: choice.text
|
|
1221
1222
|
});
|
|
1222
1223
|
}
|
|
1223
1224
|
const mappedLogprobs = mapOpenAICompletionLogProbs(
|
|
@@ -1301,7 +1302,7 @@ import {
|
|
|
1301
1302
|
import { z as z5 } from "zod";
|
|
1302
1303
|
var OpenAIEmbeddingModel = class {
|
|
1303
1304
|
constructor(modelId, settings, config) {
|
|
1304
|
-
this.specificationVersion = "
|
|
1305
|
+
this.specificationVersion = "v2";
|
|
1305
1306
|
this.modelId = modelId;
|
|
1306
1307
|
this.settings = settings;
|
|
1307
1308
|
this.config = config;
|
|
@@ -1330,7 +1331,11 @@ var OpenAIEmbeddingModel = class {
|
|
|
1330
1331
|
values
|
|
1331
1332
|
});
|
|
1332
1333
|
}
|
|
1333
|
-
const {
|
|
1334
|
+
const {
|
|
1335
|
+
responseHeaders,
|
|
1336
|
+
value: response,
|
|
1337
|
+
rawValue
|
|
1338
|
+
} = await postJsonToApi3({
|
|
1334
1339
|
url: this.config.url({
|
|
1335
1340
|
path: "/embeddings",
|
|
1336
1341
|
modelId: this.modelId
|
|
@@ -1353,7 +1358,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1353
1358
|
return {
|
|
1354
1359
|
embeddings: response.data.map((item) => item.embedding),
|
|
1355
1360
|
usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
|
|
1356
|
-
|
|
1361
|
+
response: { headers: responseHeaders, body: rawValue }
|
|
1357
1362
|
};
|
|
1358
1363
|
}
|
|
1359
1364
|
};
|
|
@@ -1480,7 +1485,7 @@ import {
|
|
|
1480
1485
|
postFormDataToApi
|
|
1481
1486
|
} from "@ai-sdk/provider-utils";
|
|
1482
1487
|
import { z as z8 } from "zod";
|
|
1483
|
-
var
|
|
1488
|
+
var openAIProviderOptionsSchema = z8.object({
|
|
1484
1489
|
include: z8.array(z8.string()).nullish(),
|
|
1485
1490
|
language: z8.string().nullish(),
|
|
1486
1491
|
prompt: z8.string().nullish(),
|
|
@@ -1565,7 +1570,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1565
1570
|
const openAIOptions = parseProviderOptions2({
|
|
1566
1571
|
provider: "openai",
|
|
1567
1572
|
providerOptions,
|
|
1568
|
-
schema:
|
|
1573
|
+
schema: openAIProviderOptionsSchema
|
|
1569
1574
|
});
|
|
1570
1575
|
const formData = new FormData();
|
|
1571
1576
|
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
@@ -2060,17 +2065,22 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2060
2065
|
});
|
|
2061
2066
|
const outputTextElements = response.output.filter((output) => output.type === "message").flatMap((output) => output.content).filter((content) => content.type === "output_text");
|
|
2062
2067
|
const toolCalls = response.output.filter((output) => output.type === "function_call").map((output) => ({
|
|
2068
|
+
type: "tool-call",
|
|
2063
2069
|
toolCallType: "function",
|
|
2064
2070
|
toolCallId: output.call_id,
|
|
2065
2071
|
toolName: output.name,
|
|
2066
2072
|
args: output.arguments
|
|
2067
2073
|
}));
|
|
2068
2074
|
return {
|
|
2069
|
-
text:
|
|
2075
|
+
text: {
|
|
2076
|
+
type: "text",
|
|
2077
|
+
text: outputTextElements.map((content) => content.text).join("\n")
|
|
2078
|
+
},
|
|
2070
2079
|
sources: outputTextElements.flatMap(
|
|
2071
2080
|
(content) => content.annotations.map((annotation) => {
|
|
2072
2081
|
var _a2, _b2, _c2;
|
|
2073
2082
|
return {
|
|
2083
|
+
type: "source",
|
|
2074
2084
|
sourceType: "url",
|
|
2075
2085
|
id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : generateId2(),
|
|
2076
2086
|
url: annotation.url,
|
|
@@ -2181,8 +2191,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2181
2191
|
});
|
|
2182
2192
|
} else if (isTextDeltaChunk(value)) {
|
|
2183
2193
|
controller.enqueue({
|
|
2184
|
-
type: "text
|
|
2185
|
-
|
|
2194
|
+
type: "text",
|
|
2195
|
+
text: value.delta
|
|
2186
2196
|
});
|
|
2187
2197
|
} else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
|
|
2188
2198
|
ongoingToolCalls[value.output_index] = void 0;
|
|
@@ -2206,12 +2216,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2206
2216
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2207
2217
|
controller.enqueue({
|
|
2208
2218
|
type: "source",
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
title: value.annotation.title
|
|
2214
|
-
}
|
|
2219
|
+
sourceType: "url",
|
|
2220
|
+
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : generateId2(),
|
|
2221
|
+
url: value.annotation.url,
|
|
2222
|
+
title: value.annotation.title
|
|
2215
2223
|
});
|
|
2216
2224
|
}
|
|
2217
2225
|
},
|