@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 2.0.0-canary.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 26735b5: chore(embedding-model): add v2 interface
|
|
8
|
+
- 443d8ec: feat(embedding-model-v2): add response body field
|
|
9
|
+
- fd65bc6: chore(embedding-model-v2): rename rawResponse to response
|
|
10
|
+
- Updated dependencies [26735b5]
|
|
11
|
+
- Updated dependencies [443d8ec]
|
|
12
|
+
- Updated dependencies [14c9410]
|
|
13
|
+
- Updated dependencies [d9c98f4]
|
|
14
|
+
- Updated dependencies [c4a2fec]
|
|
15
|
+
- Updated dependencies [0054544]
|
|
16
|
+
- Updated dependencies [9e9c809]
|
|
17
|
+
- Updated dependencies [32831c6]
|
|
18
|
+
- Updated dependencies [d0f9495]
|
|
19
|
+
- Updated dependencies [fd65bc6]
|
|
20
|
+
- Updated dependencies [393138b]
|
|
21
|
+
- Updated dependencies [7182d14]
|
|
22
|
+
- @ai-sdk/provider@2.0.0-canary.6
|
|
23
|
+
- @ai-sdk/provider-utils@3.0.0-canary.7
|
|
24
|
+
|
|
3
25
|
## 2.0.0-canary.6
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV2, ProviderV2,
|
|
1
|
+
import { LanguageModelV2, ProviderV2, EmbeddingModelV2, ImageModelV1, TranscriptionModelV1 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
@@ -165,17 +165,17 @@ interface OpenAIProvider extends ProviderV2 {
|
|
|
165
165
|
/**
|
|
166
166
|
Creates a model for text embeddings.
|
|
167
167
|
*/
|
|
168
|
-
embedding(modelId: OpenAIEmbeddingModelId, settings?: OpenAIEmbeddingSettings):
|
|
168
|
+
embedding(modelId: OpenAIEmbeddingModelId, settings?: OpenAIEmbeddingSettings): EmbeddingModelV2<string>;
|
|
169
169
|
/**
|
|
170
170
|
Creates a model for text embeddings.
|
|
171
171
|
|
|
172
172
|
@deprecated Use `textEmbeddingModel` instead.
|
|
173
173
|
*/
|
|
174
|
-
textEmbedding(modelId: OpenAIEmbeddingModelId, settings?: OpenAIEmbeddingSettings):
|
|
174
|
+
textEmbedding(modelId: OpenAIEmbeddingModelId, settings?: OpenAIEmbeddingSettings): EmbeddingModelV2<string>;
|
|
175
175
|
/**
|
|
176
176
|
Creates a model for text embeddings.
|
|
177
177
|
*/
|
|
178
|
-
textEmbeddingModel(modelId: OpenAIEmbeddingModelId, settings?: OpenAIEmbeddingSettings):
|
|
178
|
+
textEmbeddingModel(modelId: OpenAIEmbeddingModelId, settings?: OpenAIEmbeddingSettings): EmbeddingModelV2<string>;
|
|
179
179
|
/**
|
|
180
180
|
Creates a model for image generation.
|
|
181
181
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV2, ProviderV2,
|
|
1
|
+
import { LanguageModelV2, ProviderV2, EmbeddingModelV2, ImageModelV1, TranscriptionModelV1 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
@@ -165,17 +165,17 @@ interface OpenAIProvider extends ProviderV2 {
|
|
|
165
165
|
/**
|
|
166
166
|
Creates a model for text embeddings.
|
|
167
167
|
*/
|
|
168
|
-
embedding(modelId: OpenAIEmbeddingModelId, settings?: OpenAIEmbeddingSettings):
|
|
168
|
+
embedding(modelId: OpenAIEmbeddingModelId, settings?: OpenAIEmbeddingSettings): EmbeddingModelV2<string>;
|
|
169
169
|
/**
|
|
170
170
|
Creates a model for text embeddings.
|
|
171
171
|
|
|
172
172
|
@deprecated Use `textEmbeddingModel` instead.
|
|
173
173
|
*/
|
|
174
|
-
textEmbedding(modelId: OpenAIEmbeddingModelId, settings?: OpenAIEmbeddingSettings):
|
|
174
|
+
textEmbedding(modelId: OpenAIEmbeddingModelId, settings?: OpenAIEmbeddingSettings): EmbeddingModelV2<string>;
|
|
175
175
|
/**
|
|
176
176
|
Creates a model for text embeddings.
|
|
177
177
|
*/
|
|
178
|
-
textEmbeddingModel(modelId: OpenAIEmbeddingModelId, settings?: OpenAIEmbeddingSettings):
|
|
178
|
+
textEmbeddingModel(modelId: OpenAIEmbeddingModelId, settings?: OpenAIEmbeddingSettings): EmbeddingModelV2<string>;
|
|
179
179
|
/**
|
|
180
180
|
Creates a model for image generation.
|
|
181
181
|
*/
|
package/dist/index.js
CHANGED
|
@@ -560,7 +560,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
560
560
|
};
|
|
561
561
|
}
|
|
562
562
|
async doGenerate(options) {
|
|
563
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
563
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
564
564
|
const { args: body, warnings } = this.getArgs(options);
|
|
565
565
|
const {
|
|
566
566
|
responseHeaders,
|
|
@@ -598,10 +598,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
598
598
|
providerMetadata.openai.cachedPromptTokens = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens;
|
|
599
599
|
}
|
|
600
600
|
return {
|
|
601
|
-
text:
|
|
602
|
-
toolCalls: (
|
|
601
|
+
text: choice.message.content != null ? { type: "text", text: choice.message.content } : void 0,
|
|
602
|
+
toolCalls: (_c = choice.message.tool_calls) == null ? void 0 : _c.map((toolCall) => {
|
|
603
603
|
var _a2;
|
|
604
604
|
return {
|
|
605
|
+
type: "tool-call",
|
|
605
606
|
toolCallType: "function",
|
|
606
607
|
toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0, import_provider_utils3.generateId)(),
|
|
607
608
|
toolName: toolCall.function.name,
|
|
@@ -610,8 +611,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
610
611
|
}),
|
|
611
612
|
finishReason: mapOpenAIFinishReason(choice.finish_reason),
|
|
612
613
|
usage: {
|
|
613
|
-
inputTokens: (
|
|
614
|
-
outputTokens: (
|
|
614
|
+
inputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.prompt_tokens) != null ? _e : void 0,
|
|
615
|
+
outputTokens: (_g = (_f = response.usage) == null ? void 0 : _f.completion_tokens) != null ? _g : void 0
|
|
615
616
|
},
|
|
616
617
|
request: { body },
|
|
617
618
|
response: {
|
|
@@ -711,8 +712,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
711
712
|
const delta = choice.delta;
|
|
712
713
|
if (delta.content != null) {
|
|
713
714
|
controller.enqueue({
|
|
714
|
-
type: "text
|
|
715
|
-
|
|
715
|
+
type: "text",
|
|
716
|
+
text: delta.content
|
|
716
717
|
});
|
|
717
718
|
}
|
|
718
719
|
const mappedLogprobs = mapOpenAIChatLogProbsOutput(
|
|
@@ -1141,7 +1142,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1141
1142
|
});
|
|
1142
1143
|
const choice = response.choices[0];
|
|
1143
1144
|
return {
|
|
1144
|
-
text: choice.text,
|
|
1145
|
+
text: { type: "text", text: choice.text },
|
|
1145
1146
|
usage: {
|
|
1146
1147
|
inputTokens: response.usage.prompt_tokens,
|
|
1147
1148
|
outputTokens: response.usage.completion_tokens
|
|
@@ -1218,8 +1219,8 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1218
1219
|
}
|
|
1219
1220
|
if ((choice == null ? void 0 : choice.text) != null) {
|
|
1220
1221
|
controller.enqueue({
|
|
1221
|
-
type: "text
|
|
1222
|
-
|
|
1222
|
+
type: "text",
|
|
1223
|
+
text: choice.text
|
|
1223
1224
|
});
|
|
1224
1225
|
}
|
|
1225
1226
|
const mappedLogprobs = mapOpenAICompletionLogProbs(
|
|
@@ -1297,7 +1298,7 @@ var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
|
1297
1298
|
var import_zod5 = require("zod");
|
|
1298
1299
|
var OpenAIEmbeddingModel = class {
|
|
1299
1300
|
constructor(modelId, settings, config) {
|
|
1300
|
-
this.specificationVersion = "
|
|
1301
|
+
this.specificationVersion = "v2";
|
|
1301
1302
|
this.modelId = modelId;
|
|
1302
1303
|
this.settings = settings;
|
|
1303
1304
|
this.config = config;
|
|
@@ -1326,7 +1327,11 @@ var OpenAIEmbeddingModel = class {
|
|
|
1326
1327
|
values
|
|
1327
1328
|
});
|
|
1328
1329
|
}
|
|
1329
|
-
const {
|
|
1330
|
+
const {
|
|
1331
|
+
responseHeaders,
|
|
1332
|
+
value: response,
|
|
1333
|
+
rawValue
|
|
1334
|
+
} = await (0, import_provider_utils5.postJsonToApi)({
|
|
1330
1335
|
url: this.config.url({
|
|
1331
1336
|
path: "/embeddings",
|
|
1332
1337
|
modelId: this.modelId
|
|
@@ -1349,7 +1354,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1349
1354
|
return {
|
|
1350
1355
|
embeddings: response.data.map((item) => item.embedding),
|
|
1351
1356
|
usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
|
|
1352
|
-
|
|
1357
|
+
response: { headers: responseHeaders, body: rawValue }
|
|
1353
1358
|
};
|
|
1354
1359
|
}
|
|
1355
1360
|
};
|
|
@@ -1466,7 +1471,7 @@ var openaiTools = {
|
|
|
1466
1471
|
// src/openai-transcription-model.ts
|
|
1467
1472
|
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1468
1473
|
var import_zod8 = require("zod");
|
|
1469
|
-
var
|
|
1474
|
+
var openAIProviderOptionsSchema = import_zod8.z.object({
|
|
1470
1475
|
include: import_zod8.z.array(import_zod8.z.string()).nullish(),
|
|
1471
1476
|
language: import_zod8.z.string().nullish(),
|
|
1472
1477
|
prompt: import_zod8.z.string().nullish(),
|
|
@@ -1551,7 +1556,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1551
1556
|
const openAIOptions = (0, import_provider_utils7.parseProviderOptions)({
|
|
1552
1557
|
provider: "openai",
|
|
1553
1558
|
providerOptions,
|
|
1554
|
-
schema:
|
|
1559
|
+
schema: openAIProviderOptionsSchema
|
|
1555
1560
|
});
|
|
1556
1561
|
const formData = new FormData();
|
|
1557
1562
|
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils7.convertBase64ToUint8Array)(audio)]);
|
|
@@ -2035,17 +2040,22 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2035
2040
|
});
|
|
2036
2041
|
const outputTextElements = response.output.filter((output) => output.type === "message").flatMap((output) => output.content).filter((content) => content.type === "output_text");
|
|
2037
2042
|
const toolCalls = response.output.filter((output) => output.type === "function_call").map((output) => ({
|
|
2043
|
+
type: "tool-call",
|
|
2038
2044
|
toolCallType: "function",
|
|
2039
2045
|
toolCallId: output.call_id,
|
|
2040
2046
|
toolName: output.name,
|
|
2041
2047
|
args: output.arguments
|
|
2042
2048
|
}));
|
|
2043
2049
|
return {
|
|
2044
|
-
text:
|
|
2050
|
+
text: {
|
|
2051
|
+
type: "text",
|
|
2052
|
+
text: outputTextElements.map((content) => content.text).join("\n")
|
|
2053
|
+
},
|
|
2045
2054
|
sources: outputTextElements.flatMap(
|
|
2046
2055
|
(content) => content.annotations.map((annotation) => {
|
|
2047
2056
|
var _a2, _b2, _c2;
|
|
2048
2057
|
return {
|
|
2058
|
+
type: "source",
|
|
2049
2059
|
sourceType: "url",
|
|
2050
2060
|
id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : (0, import_provider_utils8.generateId)(),
|
|
2051
2061
|
url: annotation.url,
|
|
@@ -2156,8 +2166,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2156
2166
|
});
|
|
2157
2167
|
} else if (isTextDeltaChunk(value)) {
|
|
2158
2168
|
controller.enqueue({
|
|
2159
|
-
type: "text
|
|
2160
|
-
|
|
2169
|
+
type: "text",
|
|
2170
|
+
text: value.delta
|
|
2161
2171
|
});
|
|
2162
2172
|
} else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
|
|
2163
2173
|
ongoingToolCalls[value.output_index] = void 0;
|
|
@@ -2181,12 +2191,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2181
2191
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2182
2192
|
controller.enqueue({
|
|
2183
2193
|
type: "source",
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
title: value.annotation.title
|
|
2189
|
-
}
|
|
2194
|
+
sourceType: "url",
|
|
2195
|
+
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils8.generateId)(),
|
|
2196
|
+
url: value.annotation.url,
|
|
2197
|
+
title: value.annotation.title
|
|
2190
2198
|
});
|
|
2191
2199
|
}
|
|
2192
2200
|
},
|