@ai-sdk/openai 4.0.0-beta.41 → 4.0.0-beta.44
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 +25 -0
- package/dist/index.d.ts +30 -1
- package/dist/index.js +1207 -1107
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +30 -1
- package/dist/internal/index.js +1189 -1086
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +12 -3
- package/package.json +2 -2
- package/src/chat/openai-chat-language-model.ts +1 -1
- package/src/completion/openai-completion-language-model.ts +1 -1
- package/src/embedding/openai-embedding-model.ts +1 -1
- package/src/image/openai-image-model-options.ts +123 -0
- package/src/image/openai-image-model.ts +40 -77
- package/src/index.ts +11 -6
- package/src/internal/index.ts +6 -6
- package/src/openai-provider.ts +7 -7
- package/src/responses/openai-responses-api.ts +3 -0
- package/src/responses/openai-responses-language-model.ts +12 -1
- package/src/speech/openai-speech-model.ts +1 -1
- package/src/transcription/openai-transcription-model.ts +1 -1
- package/src/image/openai-image-options.ts +0 -34
- /package/src/chat/{openai-chat-options.ts → openai-chat-language-model-options.ts} +0 -0
- /package/src/completion/{openai-completion-options.ts → openai-completion-language-model-options.ts} +0 -0
- /package/src/embedding/{openai-embedding-options.ts → openai-embedding-model-options.ts} +0 -0
- /package/src/responses/{openai-responses-options.ts → openai-responses-language-model-options.ts} +0 -0
- /package/src/speech/{openai-speech-options.ts → openai-speech-model-options.ts} +0 -0
- /package/src/transcription/{openai-transcription-options.ts → openai-transcription-model-options.ts} +0 -0
package/docs/03-openai.mdx
CHANGED
|
@@ -2442,6 +2442,9 @@ const { images } = await generateImage({
|
|
|
2442
2442
|
Remove the background from an image by setting `background` to `transparent`:
|
|
2443
2443
|
|
|
2444
2444
|
```ts
|
|
2445
|
+
import { openai, type OpenAIImageModelEditOptions } from '@ai-sdk/openai';
|
|
2446
|
+
import { generateImage } from 'ai';
|
|
2447
|
+
|
|
2445
2448
|
const imageBuffer = readFileSync('./input-image.png');
|
|
2446
2449
|
|
|
2447
2450
|
const { images } = await generateImage({
|
|
@@ -2453,8 +2456,8 @@ const { images } = await generateImage({
|
|
|
2453
2456
|
providerOptions: {
|
|
2454
2457
|
openai: {
|
|
2455
2458
|
background: 'transparent',
|
|
2456
|
-
|
|
2457
|
-
},
|
|
2459
|
+
outputFormat: 'png',
|
|
2460
|
+
} satisfies OpenAIImageModelEditOptions,
|
|
2458
2461
|
},
|
|
2459
2462
|
});
|
|
2460
2463
|
```
|
|
@@ -2497,11 +2500,17 @@ const { images } = await generateImage({
|
|
|
2497
2500
|
You can pass optional `providerOptions` to the image model. These are prone to change by OpenAI and are model dependent. For example, the `gpt-image-1` model supports the `quality` option:
|
|
2498
2501
|
|
|
2499
2502
|
```ts
|
|
2503
|
+
import {
|
|
2504
|
+
openai,
|
|
2505
|
+
type OpenAIImageModelGenerationOptions,
|
|
2506
|
+
} from '@ai-sdk/openai';
|
|
2507
|
+
import { generateImage } from 'ai';
|
|
2508
|
+
|
|
2500
2509
|
const { image, providerMetadata } = await generateImage({
|
|
2501
2510
|
model: openai.image('gpt-image-1.5'),
|
|
2502
2511
|
prompt: 'A salamander at sunrise in a forest pond in the Seychelles.',
|
|
2503
2512
|
providerOptions: {
|
|
2504
|
-
openai: { quality: 'high' },
|
|
2513
|
+
openai: { quality: 'high' } satisfies OpenAIImageModelGenerationOptions,
|
|
2505
2514
|
},
|
|
2506
2515
|
});
|
|
2507
2516
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/openai",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.44",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@ai-sdk/provider": "4.0.0-beta.14",
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.0-beta.
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.30"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "20.17.24",
|
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
import {
|
|
42
42
|
openaiLanguageModelChatOptions,
|
|
43
43
|
type OpenAIChatModelId,
|
|
44
|
-
} from './openai-chat-options';
|
|
44
|
+
} from './openai-chat-language-model-options';
|
|
45
45
|
import { prepareChatTools } from './openai-chat-prepare-tools';
|
|
46
46
|
|
|
47
47
|
type OpenAIChatConfig = {
|
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
import {
|
|
37
37
|
openaiLanguageModelCompletionOptions,
|
|
38
38
|
type OpenAICompletionModelId,
|
|
39
|
-
} from './openai-completion-options';
|
|
39
|
+
} from './openai-completion-language-model-options';
|
|
40
40
|
type OpenAICompletionConfig = {
|
|
41
41
|
provider: string;
|
|
42
42
|
headers?: () => Record<string, string | undefined>;
|
|
@@ -16,7 +16,7 @@ import { openaiFailedResponseHandler } from '../openai-error';
|
|
|
16
16
|
import {
|
|
17
17
|
openaiEmbeddingModelOptions,
|
|
18
18
|
type OpenAIEmbeddingModelId,
|
|
19
|
-
} from './openai-embedding-options';
|
|
19
|
+
} from './openai-embedding-model-options';
|
|
20
20
|
import { openaiTextEmbeddingResponseSchema } from './openai-embedding-api';
|
|
21
21
|
|
|
22
22
|
export class OpenAIEmbeddingModel implements EmbeddingModelV4 {
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lazySchema,
|
|
3
|
+
zodSchema,
|
|
4
|
+
type InferSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from 'zod/v4';
|
|
7
|
+
|
|
8
|
+
export type OpenAIImageModelId =
|
|
9
|
+
| 'dall-e-3'
|
|
10
|
+
| 'dall-e-2'
|
|
11
|
+
| 'gpt-image-1'
|
|
12
|
+
| 'gpt-image-1-mini'
|
|
13
|
+
| 'gpt-image-1.5'
|
|
14
|
+
| 'gpt-image-2'
|
|
15
|
+
| 'chatgpt-image-latest'
|
|
16
|
+
| (string & {});
|
|
17
|
+
|
|
18
|
+
// https://platform.openai.com/docs/guides/images
|
|
19
|
+
export const modelMaxImagesPerCall: Record<OpenAIImageModelId, number> = {
|
|
20
|
+
'dall-e-3': 1,
|
|
21
|
+
'dall-e-2': 10,
|
|
22
|
+
'gpt-image-1': 10,
|
|
23
|
+
'gpt-image-1-mini': 10,
|
|
24
|
+
'gpt-image-1.5': 10,
|
|
25
|
+
'gpt-image-2': 10,
|
|
26
|
+
'chatgpt-image-latest': 10,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const defaultResponseFormatPrefixes = [
|
|
30
|
+
'chatgpt-image-',
|
|
31
|
+
'gpt-image-1-mini',
|
|
32
|
+
'gpt-image-1.5',
|
|
33
|
+
'gpt-image-1',
|
|
34
|
+
'gpt-image-2',
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
export function hasDefaultResponseFormat(modelId: string): boolean {
|
|
38
|
+
return defaultResponseFormatPrefixes.some(prefix =>
|
|
39
|
+
modelId.startsWith(prefix),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const baseImageModelOptionsObject = z.object({
|
|
44
|
+
/**
|
|
45
|
+
* Quality of the generated image(s).
|
|
46
|
+
*
|
|
47
|
+
* Valid values: `standard`, `hd`, `low`, `medium`, `high`, `auto`.
|
|
48
|
+
*/
|
|
49
|
+
quality: z
|
|
50
|
+
.enum(['standard', 'hd', 'low', 'medium', 'high', 'auto'])
|
|
51
|
+
.optional(),
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Background behavior for the generated image(s).
|
|
55
|
+
*
|
|
56
|
+
* If `transparent`, the output format must support transparency
|
|
57
|
+
* (i.e. `png` or `webp`).
|
|
58
|
+
*/
|
|
59
|
+
background: z.enum(['transparent', 'opaque', 'auto']).optional(),
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Format in which the generated image(s) are returned.
|
|
63
|
+
*/
|
|
64
|
+
outputFormat: z.enum(['png', 'jpeg', 'webp']).optional(),
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Compression level (0-100) for the generated image(s). Applies to the
|
|
68
|
+
* `jpeg` and `webp` output formats.
|
|
69
|
+
*/
|
|
70
|
+
outputCompression: z.number().int().min(0).max(100).optional(),
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A unique identifier representing your end-user, which can help OpenAI
|
|
74
|
+
* to monitor and detect abuse.
|
|
75
|
+
*/
|
|
76
|
+
user: z.string().optional(),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export const openaiImageModelOptions = lazySchema(() =>
|
|
80
|
+
zodSchema(baseImageModelOptionsObject),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
export type OpenAIImageModelOptions = InferSchema<
|
|
84
|
+
typeof openaiImageModelOptions
|
|
85
|
+
>;
|
|
86
|
+
|
|
87
|
+
export const openaiImageModelGenerationOptions = lazySchema(() =>
|
|
88
|
+
zodSchema(
|
|
89
|
+
baseImageModelOptionsObject.extend({
|
|
90
|
+
/**
|
|
91
|
+
* Style of the generated image. `vivid` produces hyper-real and
|
|
92
|
+
* dramatic images; `natural` produces more subdued, less hyper-real
|
|
93
|
+
* looking images.
|
|
94
|
+
*/
|
|
95
|
+
style: z.enum(['vivid', 'natural']).optional(),
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Content moderation level for the generated image(s). `low` applies
|
|
99
|
+
* less restrictive filtering.
|
|
100
|
+
*/
|
|
101
|
+
moderation: z.enum(['auto', 'low']).optional(),
|
|
102
|
+
}),
|
|
103
|
+
),
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
export type OpenAIImageModelGenerationOptions = InferSchema<
|
|
107
|
+
typeof openaiImageModelGenerationOptions
|
|
108
|
+
>;
|
|
109
|
+
|
|
110
|
+
export const openaiImageModelEditOptions = lazySchema(() =>
|
|
111
|
+
zodSchema(
|
|
112
|
+
baseImageModelOptionsObject.extend({
|
|
113
|
+
/**
|
|
114
|
+
* Fidelity of the output image(s) to the input image(s).
|
|
115
|
+
*/
|
|
116
|
+
inputFidelity: z.enum(['high', 'low']).optional(),
|
|
117
|
+
}),
|
|
118
|
+
),
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
export type OpenAIImageModelEditOptions = InferSchema<
|
|
122
|
+
typeof openaiImageModelEditOptions
|
|
123
|
+
>;
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
convertToFormData,
|
|
10
10
|
createJsonResponseHandler,
|
|
11
11
|
downloadBlob,
|
|
12
|
+
parseProviderOptions,
|
|
12
13
|
postFormDataToApi,
|
|
13
14
|
postJsonToApi,
|
|
14
15
|
serializeModelOptions,
|
|
@@ -21,8 +22,11 @@ import { openaiImageResponseSchema } from './openai-image-api';
|
|
|
21
22
|
import {
|
|
22
23
|
hasDefaultResponseFormat,
|
|
23
24
|
modelMaxImagesPerCall,
|
|
25
|
+
openaiImageModelEditOptions,
|
|
26
|
+
openaiImageModelGenerationOptions,
|
|
27
|
+
type OpenAIImageModelEditOptions,
|
|
24
28
|
type OpenAIImageModelId,
|
|
25
|
-
} from './openai-image-options';
|
|
29
|
+
} from './openai-image-model-options';
|
|
26
30
|
interface OpenAIImageModelConfig extends OpenAIConfig {
|
|
27
31
|
_internal?: {
|
|
28
32
|
currentDate?: () => Date;
|
|
@@ -91,6 +95,13 @@ export class OpenAIImageModel implements ImageModelV4 {
|
|
|
91
95
|
const currentDate = this.config._internal?.currentDate?.() ?? new Date();
|
|
92
96
|
|
|
93
97
|
if (files != null) {
|
|
98
|
+
const openaiOptions =
|
|
99
|
+
(await parseProviderOptions({
|
|
100
|
+
provider: 'openai',
|
|
101
|
+
providerOptions,
|
|
102
|
+
schema: openaiImageModelEditOptions,
|
|
103
|
+
})) ?? {};
|
|
104
|
+
|
|
94
105
|
const { value: response, responseHeaders } = await postFormDataToApi({
|
|
95
106
|
url: this.config.url({
|
|
96
107
|
path: '/images/edits',
|
|
@@ -121,7 +132,12 @@ export class OpenAIImageModel implements ImageModelV4 {
|
|
|
121
132
|
mask: mask != null ? await fileToBlob(mask) : undefined,
|
|
122
133
|
n,
|
|
123
134
|
size,
|
|
124
|
-
|
|
135
|
+
quality: openaiOptions.quality,
|
|
136
|
+
background: openaiOptions.background,
|
|
137
|
+
output_format: openaiOptions.outputFormat,
|
|
138
|
+
output_compression: openaiOptions.outputCompression,
|
|
139
|
+
input_fidelity: openaiOptions.inputFidelity,
|
|
140
|
+
user: openaiOptions.user,
|
|
125
141
|
}),
|
|
126
142
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
127
143
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -169,6 +185,13 @@ export class OpenAIImageModel implements ImageModelV4 {
|
|
|
169
185
|
};
|
|
170
186
|
}
|
|
171
187
|
|
|
188
|
+
const openaiOptions =
|
|
189
|
+
(await parseProviderOptions({
|
|
190
|
+
provider: 'openai',
|
|
191
|
+
providerOptions,
|
|
192
|
+
schema: openaiImageModelGenerationOptions,
|
|
193
|
+
})) ?? {};
|
|
194
|
+
|
|
172
195
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
173
196
|
url: this.config.url({
|
|
174
197
|
path: '/images/generations',
|
|
@@ -180,7 +203,13 @@ export class OpenAIImageModel implements ImageModelV4 {
|
|
|
180
203
|
prompt,
|
|
181
204
|
n,
|
|
182
205
|
size,
|
|
183
|
-
|
|
206
|
+
quality: openaiOptions.quality,
|
|
207
|
+
style: openaiOptions.style,
|
|
208
|
+
background: openaiOptions.background,
|
|
209
|
+
moderation: openaiOptions.moderation,
|
|
210
|
+
output_format: openaiOptions.outputFormat,
|
|
211
|
+
output_compression: openaiOptions.outputCompression,
|
|
212
|
+
user: openaiOptions.user,
|
|
184
213
|
...(!hasDefaultResponseFormat(this.modelId)
|
|
185
214
|
? { response_format: 'b64_json' }
|
|
186
215
|
: {}),
|
|
@@ -267,84 +296,18 @@ function distributeTokenDetails(
|
|
|
267
296
|
}
|
|
268
297
|
|
|
269
298
|
type OpenAIImageEditInput = {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
* This parameter is only supported for `gpt-image-1`. Must be one of
|
|
273
|
-
* `transparent`, `opaque` or `auto` (default value). When `auto` is used, the
|
|
274
|
-
* model will automatically determine the best background for the image.
|
|
275
|
-
*
|
|
276
|
-
* If `transparent`, the output format needs to support transparency, so it
|
|
277
|
-
* should be set to either `png` (default value) or `webp`.
|
|
278
|
-
*
|
|
279
|
-
*/
|
|
280
|
-
background?: 'transparent' | 'opaque' | 'auto';
|
|
281
|
-
/**
|
|
282
|
-
* The image(s) to edit. Must be a supported image file or an array of images.
|
|
283
|
-
*
|
|
284
|
-
* For `gpt-image-1`, each image should be a `png`, `webp`, or `jpg` file less
|
|
285
|
-
* than 50MB. You can provide up to 16 images.
|
|
286
|
-
*
|
|
287
|
-
* For `dall-e-2`, you can only provide one image, and it should be a square
|
|
288
|
-
* `png` file less than 4MB.
|
|
289
|
-
*
|
|
290
|
-
*/
|
|
299
|
+
model: OpenAIImageModelId;
|
|
300
|
+
prompt?: string;
|
|
291
301
|
image: Blob | Blob[];
|
|
292
|
-
input_fidelity?: ('high' | 'low') | null;
|
|
293
|
-
/**
|
|
294
|
-
* An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where `image` should be edited. If there are multiple images provided, the mask will be applied on the first image. Must be a valid PNG file, less than 4MB, and have the same dimensions as `image`.
|
|
295
|
-
*/
|
|
296
302
|
mask?: Blob;
|
|
297
|
-
/**
|
|
298
|
-
* The model to use for image generation. Only `dall-e-2` and `gpt-image-1` are supported. Defaults to `dall-e-2` unless a parameter specific to `gpt-image-1` is used.
|
|
299
|
-
*/
|
|
300
|
-
model?: 'dall-e-2' | 'gpt-image-1' | 'gpt-image-1-mini' | (string & {});
|
|
301
|
-
/**
|
|
302
|
-
* The number of images to generate. Must be between 1 and 10.
|
|
303
|
-
*/
|
|
304
303
|
n?: number;
|
|
305
|
-
/**
|
|
306
|
-
* The compression level (0-100%) for the generated images. This parameter
|
|
307
|
-
* is only supported for `gpt-image-1` with the `webp` or `jpeg` output
|
|
308
|
-
* formats, and defaults to 100.
|
|
309
|
-
*
|
|
310
|
-
*/
|
|
311
|
-
output_compression?: number;
|
|
312
|
-
/**
|
|
313
|
-
* The format in which the generated images are returned. This parameter is
|
|
314
|
-
* only supported for `gpt-image-1`. Must be one of `png`, `jpeg`, or `webp`.
|
|
315
|
-
* The default value is `png`.
|
|
316
|
-
*
|
|
317
|
-
*/
|
|
318
|
-
output_format?: 'png' | 'jpeg' | 'webp';
|
|
319
|
-
partial_images?: number | null;
|
|
320
|
-
/**
|
|
321
|
-
* A text description of the desired image(s). The maximum length is 1000 characters for `dall-e-2`, and 32000 characters for `gpt-image-1`.
|
|
322
|
-
*/
|
|
323
|
-
prompt?: string;
|
|
324
|
-
/**
|
|
325
|
-
* The quality of the image that will be generated. `high`, `medium` and `low` are only supported for `gpt-image-1`. `dall-e-2` only supports `standard` quality. Defaults to `auto`.
|
|
326
|
-
*
|
|
327
|
-
*/
|
|
328
|
-
quality?: 'standard' | 'low' | 'medium' | 'high' | 'auto';
|
|
329
|
-
/**
|
|
330
|
-
* The format in which the generated images are returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes after the image has been generated. This parameter is only supported for `dall-e-2`, as `gpt-image-1` will always return base64-encoded images.
|
|
331
|
-
*/
|
|
332
|
-
response_format?: 'url' | 'b64_json';
|
|
333
|
-
/**
|
|
334
|
-
* The size of the generated images. Must be one of `1024x1024`, `1536x1024` (landscape), `1024x1536` (portrait), or `auto` (default value) for `gpt-image-1`, and one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`.
|
|
335
|
-
*/
|
|
336
304
|
size?: `${number}x${number}`;
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
|
|
345
|
-
*
|
|
346
|
-
*/
|
|
347
|
-
user?: string;
|
|
305
|
+
quality?: OpenAIImageModelEditOptions['quality'];
|
|
306
|
+
background?: OpenAIImageModelEditOptions['background'];
|
|
307
|
+
output_format?: OpenAIImageModelEditOptions['outputFormat'];
|
|
308
|
+
output_compression?: OpenAIImageModelEditOptions['outputCompression'];
|
|
309
|
+
input_fidelity?: OpenAIImageModelEditOptions['inputFidelity'];
|
|
310
|
+
user?: OpenAIImageModelEditOptions['user'];
|
|
348
311
|
};
|
|
349
312
|
|
|
350
313
|
async function fileToBlob(
|
package/src/index.ts
CHANGED
|
@@ -4,16 +4,21 @@ export type {
|
|
|
4
4
|
OpenAILanguageModelResponsesOptions,
|
|
5
5
|
/** @deprecated Use `OpenAILanguageModelResponsesOptions` instead. */
|
|
6
6
|
OpenAILanguageModelResponsesOptions as OpenAIResponsesProviderOptions,
|
|
7
|
-
} from './responses/openai-responses-options';
|
|
7
|
+
} from './responses/openai-responses-language-model-options';
|
|
8
8
|
export type {
|
|
9
9
|
OpenAILanguageModelChatOptions,
|
|
10
10
|
/** @deprecated Use `OpenAILanguageModelChatOptions` instead. */
|
|
11
11
|
OpenAILanguageModelChatOptions as OpenAIChatLanguageModelOptions,
|
|
12
|
-
} from './chat/openai-chat-options';
|
|
13
|
-
export type {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
} from './chat/openai-chat-language-model-options';
|
|
13
|
+
export type {
|
|
14
|
+
OpenAIImageModelOptions,
|
|
15
|
+
OpenAIImageModelGenerationOptions,
|
|
16
|
+
OpenAIImageModelEditOptions,
|
|
17
|
+
} from './image/openai-image-model-options';
|
|
18
|
+
export type { OpenAILanguageModelCompletionOptions } from './completion/openai-completion-language-model-options';
|
|
19
|
+
export type { OpenAIEmbeddingModelOptions } from './embedding/openai-embedding-model-options';
|
|
20
|
+
export type { OpenAISpeechModelOptions } from './speech/openai-speech-model-options';
|
|
21
|
+
export type { OpenAITranscriptionModelOptions } from './transcription/openai-transcription-model-options';
|
|
17
22
|
export type { OpenAIFilesOptions } from './files/openai-files-options';
|
|
18
23
|
export type {
|
|
19
24
|
OpenaiResponsesCompactionProviderMetadata,
|
package/src/internal/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export * from '../chat/openai-chat-language-model';
|
|
2
|
-
export * from '../chat/openai-chat-options';
|
|
2
|
+
export * from '../chat/openai-chat-language-model-options';
|
|
3
3
|
export * from '../completion/openai-completion-language-model';
|
|
4
|
-
export * from '../completion/openai-completion-options';
|
|
4
|
+
export * from '../completion/openai-completion-language-model-options';
|
|
5
5
|
export * from '../embedding/openai-embedding-model';
|
|
6
|
-
export * from '../embedding/openai-embedding-options';
|
|
6
|
+
export * from '../embedding/openai-embedding-model-options';
|
|
7
7
|
export * from '../image/openai-image-model';
|
|
8
|
-
export * from '../image/openai-image-options';
|
|
8
|
+
export * from '../image/openai-image-model-options';
|
|
9
9
|
export * from '../transcription/openai-transcription-model';
|
|
10
|
-
export * from '../transcription/openai-transcription-options';
|
|
10
|
+
export * from '../transcription/openai-transcription-model-options';
|
|
11
11
|
export * from '../speech/openai-speech-model';
|
|
12
|
-
export * from '../speech/openai-speech-options';
|
|
12
|
+
export * from '../speech/openai-speech-model-options';
|
|
13
13
|
export * from '../responses/openai-responses-language-model';
|
|
14
14
|
export * from '../responses/openai-responses-provider-metadata';
|
|
15
15
|
export * from '../tool/apply-patch';
|
package/src/openai-provider.ts
CHANGED
|
@@ -16,21 +16,21 @@ import {
|
|
|
16
16
|
type FetchFunction,
|
|
17
17
|
} from '@ai-sdk/provider-utils';
|
|
18
18
|
import { OpenAIChatLanguageModel } from './chat/openai-chat-language-model';
|
|
19
|
-
import type { OpenAIChatModelId } from './chat/openai-chat-options';
|
|
19
|
+
import type { OpenAIChatModelId } from './chat/openai-chat-language-model-options';
|
|
20
20
|
import { OpenAICompletionLanguageModel } from './completion/openai-completion-language-model';
|
|
21
|
-
import type { OpenAICompletionModelId } from './completion/openai-completion-options';
|
|
21
|
+
import type { OpenAICompletionModelId } from './completion/openai-completion-language-model-options';
|
|
22
22
|
import { OpenAIEmbeddingModel } from './embedding/openai-embedding-model';
|
|
23
23
|
import { OpenAIFiles } from './files/openai-files';
|
|
24
|
-
import type { OpenAIEmbeddingModelId } from './embedding/openai-embedding-options';
|
|
24
|
+
import type { OpenAIEmbeddingModelId } from './embedding/openai-embedding-model-options';
|
|
25
25
|
import { OpenAIImageModel } from './image/openai-image-model';
|
|
26
|
-
import type { OpenAIImageModelId } from './image/openai-image-options';
|
|
26
|
+
import type { OpenAIImageModelId } from './image/openai-image-model-options';
|
|
27
27
|
import { openaiTools } from './openai-tools';
|
|
28
28
|
import { OpenAIResponsesLanguageModel } from './responses/openai-responses-language-model';
|
|
29
|
-
import type { OpenAIResponsesModelId } from './responses/openai-responses-options';
|
|
29
|
+
import type { OpenAIResponsesModelId } from './responses/openai-responses-language-model-options';
|
|
30
30
|
import { OpenAISpeechModel } from './speech/openai-speech-model';
|
|
31
|
-
import type { OpenAISpeechModelId } from './speech/openai-speech-options';
|
|
31
|
+
import type { OpenAISpeechModelId } from './speech/openai-speech-model-options';
|
|
32
32
|
import { OpenAITranscriptionModel } from './transcription/openai-transcription-model';
|
|
33
|
-
import type { OpenAITranscriptionModelId } from './transcription/openai-transcription-options';
|
|
33
|
+
import type { OpenAITranscriptionModelId } from './transcription/openai-transcription-model-options';
|
|
34
34
|
import { OpenAISkills } from './skills/openai-skills';
|
|
35
35
|
import { VERSION } from './version';
|
|
36
36
|
|
|
@@ -562,6 +562,7 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
|
|
|
562
562
|
call_id: z.string(),
|
|
563
563
|
name: z.string(),
|
|
564
564
|
arguments: z.string(),
|
|
565
|
+
namespace: z.string().nullish(),
|
|
565
566
|
}),
|
|
566
567
|
z.object({
|
|
567
568
|
type: z.literal('web_search_call'),
|
|
@@ -711,6 +712,7 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
|
|
|
711
712
|
name: z.string(),
|
|
712
713
|
arguments: z.string(),
|
|
713
714
|
status: z.literal('completed'),
|
|
715
|
+
namespace: z.string().nullish(),
|
|
714
716
|
}),
|
|
715
717
|
z.object({
|
|
716
718
|
type: z.literal('custom_tool_call'),
|
|
@@ -1226,6 +1228,7 @@ export const openaiResponsesResponseSchema = lazySchema(() =>
|
|
|
1226
1228
|
name: z.string(),
|
|
1227
1229
|
arguments: z.string(),
|
|
1228
1230
|
id: z.string(),
|
|
1231
|
+
namespace: z.string().nullish(),
|
|
1229
1232
|
}),
|
|
1230
1233
|
z.object({
|
|
1231
1234
|
type: z.literal('custom_tool_call'),
|
|
@@ -68,7 +68,7 @@ import {
|
|
|
68
68
|
openaiLanguageModelResponsesOptionsSchema,
|
|
69
69
|
TOP_LOGPROBS_MAX,
|
|
70
70
|
type OpenAIResponsesModelId,
|
|
71
|
-
} from './openai-responses-options';
|
|
71
|
+
} from './openai-responses-language-model-options';
|
|
72
72
|
import { prepareResponsesTools } from './openai-responses-prepare-tools';
|
|
73
73
|
import type {
|
|
74
74
|
ResponsesCompactionProviderMetadata,
|
|
@@ -803,6 +803,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV4 {
|
|
|
803
803
|
providerMetadata: {
|
|
804
804
|
[providerOptionsName]: {
|
|
805
805
|
itemId: part.id,
|
|
806
|
+
...(part.namespace != null && { namespace: part.namespace }),
|
|
806
807
|
},
|
|
807
808
|
},
|
|
808
809
|
});
|
|
@@ -1426,6 +1427,13 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV4 {
|
|
|
1426
1427
|
controller.enqueue({
|
|
1427
1428
|
type: 'tool-input-end',
|
|
1428
1429
|
id: value.item.call_id,
|
|
1430
|
+
...(value.item.namespace != null && {
|
|
1431
|
+
providerMetadata: {
|
|
1432
|
+
[providerOptionsName]: {
|
|
1433
|
+
namespace: value.item.namespace,
|
|
1434
|
+
},
|
|
1435
|
+
},
|
|
1436
|
+
}),
|
|
1429
1437
|
});
|
|
1430
1438
|
|
|
1431
1439
|
controller.enqueue({
|
|
@@ -1436,6 +1444,9 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV4 {
|
|
|
1436
1444
|
providerMetadata: {
|
|
1437
1445
|
[providerOptionsName]: {
|
|
1438
1446
|
itemId: value.item.id,
|
|
1447
|
+
...(value.item.namespace != null && {
|
|
1448
|
+
namespace: value.item.namespace,
|
|
1449
|
+
}),
|
|
1439
1450
|
},
|
|
1440
1451
|
},
|
|
1441
1452
|
});
|
|
@@ -14,7 +14,7 @@ import type { OpenAISpeechAPITypes } from './openai-speech-api';
|
|
|
14
14
|
import {
|
|
15
15
|
openaiSpeechModelOptionsSchema,
|
|
16
16
|
type OpenAISpeechModelId,
|
|
17
|
-
} from './openai-speech-options';
|
|
17
|
+
} from './openai-speech-model-options';
|
|
18
18
|
interface OpenAISpeechModelConfig extends OpenAIConfig {
|
|
19
19
|
_internal?: {
|
|
20
20
|
currentDate?: () => Date;
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
openAITranscriptionModelOptions,
|
|
22
22
|
type OpenAITranscriptionModelId,
|
|
23
23
|
type OpenAITranscriptionModelOptions,
|
|
24
|
-
} from './openai-transcription-options';
|
|
24
|
+
} from './openai-transcription-model-options';
|
|
25
25
|
export type OpenAITranscriptionCallOptions = Omit<
|
|
26
26
|
TranscriptionModelV4CallOptions,
|
|
27
27
|
'providerOptions'
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export type OpenAIImageModelId =
|
|
2
|
-
| 'dall-e-3'
|
|
3
|
-
| 'dall-e-2'
|
|
4
|
-
| 'gpt-image-1'
|
|
5
|
-
| 'gpt-image-1-mini'
|
|
6
|
-
| 'gpt-image-1.5'
|
|
7
|
-
| 'gpt-image-2'
|
|
8
|
-
| 'chatgpt-image-latest'
|
|
9
|
-
| (string & {});
|
|
10
|
-
|
|
11
|
-
// https://platform.openai.com/docs/guides/images
|
|
12
|
-
export const modelMaxImagesPerCall: Record<OpenAIImageModelId, number> = {
|
|
13
|
-
'dall-e-3': 1,
|
|
14
|
-
'dall-e-2': 10,
|
|
15
|
-
'gpt-image-1': 10,
|
|
16
|
-
'gpt-image-1-mini': 10,
|
|
17
|
-
'gpt-image-1.5': 10,
|
|
18
|
-
'gpt-image-2': 10,
|
|
19
|
-
'chatgpt-image-latest': 10,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const defaultResponseFormatPrefixes = [
|
|
23
|
-
'chatgpt-image-',
|
|
24
|
-
'gpt-image-1-mini',
|
|
25
|
-
'gpt-image-1.5',
|
|
26
|
-
'gpt-image-1',
|
|
27
|
-
'gpt-image-2',
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
export function hasDefaultResponseFormat(modelId: string): boolean {
|
|
31
|
-
return defaultResponseFormatPrefixes.some(prefix =>
|
|
32
|
-
modelId.startsWith(prefix),
|
|
33
|
-
);
|
|
34
|
-
}
|
|
File without changes
|
/package/src/completion/{openai-completion-options.ts → openai-completion-language-model-options.ts}
RENAMED
|
File without changes
|
|
File without changes
|
/package/src/responses/{openai-responses-options.ts → openai-responses-language-model-options.ts}
RENAMED
|
File without changes
|
|
File without changes
|
/package/src/transcription/{openai-transcription-options.ts → openai-transcription-model-options.ts}
RENAMED
|
File without changes
|