@ai-sdk/openai 3.0.28 → 3.0.29
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 +6 -0
- package/dist/index.js +34 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -7
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +33 -6
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +33 -6
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/image/openai-image-model.ts +46 -2
package/package.json
CHANGED
|
@@ -133,7 +133,7 @@ export class OpenAIImageModel implements ImageModelV3 {
|
|
|
133
133
|
},
|
|
134
134
|
providerMetadata: {
|
|
135
135
|
openai: {
|
|
136
|
-
images: response.data.map(item => ({
|
|
136
|
+
images: response.data.map((item, index) => ({
|
|
137
137
|
...(item.revised_prompt
|
|
138
138
|
? { revisedPrompt: item.revised_prompt }
|
|
139
139
|
: {}),
|
|
@@ -142,6 +142,11 @@ export class OpenAIImageModel implements ImageModelV3 {
|
|
|
142
142
|
quality: response.quality ?? undefined,
|
|
143
143
|
background: response.background ?? undefined,
|
|
144
144
|
outputFormat: response.output_format ?? undefined,
|
|
145
|
+
...distributeTokenDetails(
|
|
146
|
+
response.usage?.input_tokens_details,
|
|
147
|
+
index,
|
|
148
|
+
response.data.length,
|
|
149
|
+
),
|
|
145
150
|
})),
|
|
146
151
|
},
|
|
147
152
|
},
|
|
@@ -190,7 +195,7 @@ export class OpenAIImageModel implements ImageModelV3 {
|
|
|
190
195
|
},
|
|
191
196
|
providerMetadata: {
|
|
192
197
|
openai: {
|
|
193
|
-
images: response.data.map(item => ({
|
|
198
|
+
images: response.data.map((item, index) => ({
|
|
194
199
|
...(item.revised_prompt
|
|
195
200
|
? { revisedPrompt: item.revised_prompt }
|
|
196
201
|
: {}),
|
|
@@ -199,6 +204,11 @@ export class OpenAIImageModel implements ImageModelV3 {
|
|
|
199
204
|
quality: response.quality ?? undefined,
|
|
200
205
|
background: response.background ?? undefined,
|
|
201
206
|
outputFormat: response.output_format ?? undefined,
|
|
207
|
+
...distributeTokenDetails(
|
|
208
|
+
response.usage?.input_tokens_details,
|
|
209
|
+
index,
|
|
210
|
+
response.data.length,
|
|
211
|
+
),
|
|
202
212
|
})),
|
|
203
213
|
},
|
|
204
214
|
},
|
|
@@ -206,6 +216,40 @@ export class OpenAIImageModel implements ImageModelV3 {
|
|
|
206
216
|
}
|
|
207
217
|
}
|
|
208
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Distributes input token details evenly across images, with the remainder
|
|
221
|
+
* assigned to the last image so that summing across all entries gives the
|
|
222
|
+
* exact total.
|
|
223
|
+
*/
|
|
224
|
+
function distributeTokenDetails(
|
|
225
|
+
details:
|
|
226
|
+
| { image_tokens?: number | null; text_tokens?: number | null }
|
|
227
|
+
| null
|
|
228
|
+
| undefined,
|
|
229
|
+
index: number,
|
|
230
|
+
total: number,
|
|
231
|
+
): { imageTokens?: number; textTokens?: number } {
|
|
232
|
+
if (details == null) {
|
|
233
|
+
return {};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const result: { imageTokens?: number; textTokens?: number } = {};
|
|
237
|
+
|
|
238
|
+
if (details.image_tokens != null) {
|
|
239
|
+
const base = Math.floor(details.image_tokens / total);
|
|
240
|
+
const remainder = details.image_tokens - base * (total - 1);
|
|
241
|
+
result.imageTokens = index === total - 1 ? remainder : base;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (details.text_tokens != null) {
|
|
245
|
+
const base = Math.floor(details.text_tokens / total);
|
|
246
|
+
const remainder = details.text_tokens - base * (total - 1);
|
|
247
|
+
result.textTokens = index === total - 1 ? remainder : base;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
|
|
209
253
|
type OpenAIImageEditInput = {
|
|
210
254
|
/**
|
|
211
255
|
* Allows to set transparency for the background of the generated image(s).
|