fix: add gpt-image-2 high-resolution sizes
This commit is contained in:
1 parent
69a636921e
commit
bb79051a88
2 files changed
+34
-8
No files matched your search
@@ -10,6 +10,19 @@ import type {
|
||||
import { ImageError } from '../errors'
|
||||
import { IMAGE_ERROR_CODES } from '../../../constants/error-codes'
|
||||
|
||||
const GPT_IMAGE_2_SIZE_VALUES = [
|
||||
'1024x1024',
|
||||
'1536x1024',
|
||||
'1024x1536',
|
||||
'2048x2048',
|
||||
'2048x1152',
|
||||
'3840x2160',
|
||||
'2160x3840',
|
||||
'auto'
|
||||
] as const
|
||||
|
||||
const GPT_IMAGE_2_BACKGROUND_VALUES = ['auto', 'opaque'] as const
|
||||
|
||||
export class OpenAIImageAdapter extends AbstractImageProviderAdapter {
|
||||
private static readonly FORCED_SINGLE_OUTPUT_PARAM_KEYS = ['n', 'batch_size', 'outputMimeType', 'response_format']
|
||||
|
||||
@@ -56,7 +69,7 @@ export class OpenAIImageAdapter extends AbstractImageProviderAdapter {
|
||||
descriptionKey: 'image.params.size.description',
|
||||
type: 'string',
|
||||
defaultValue: '1024x1024',
|
||||
allowedValues: ['1024x1024', '1536x1024', '1024x1536', 'auto']
|
||||
allowedValues: [...GPT_IMAGE_2_SIZE_VALUES]
|
||||
},
|
||||
{
|
||||
name: 'quality',
|
||||
@@ -72,7 +85,7 @@ export class OpenAIImageAdapter extends AbstractImageProviderAdapter {
|
||||
descriptionKey: 'image.params.background.description',
|
||||
type: 'string',
|
||||
defaultValue: 'auto',
|
||||
allowedValues: ['auto', 'transparent', 'opaque']
|
||||
allowedValues: [...GPT_IMAGE_2_BACKGROUND_VALUES]
|
||||
}
|
||||
],
|
||||
defaultParameterValues: {
|
||||
@@ -145,7 +158,7 @@ export class OpenAIImageAdapter extends AbstractImageProviderAdapter {
|
||||
}
|
||||
|
||||
protected getParameterDefinitions(_modelId: string): readonly ImageParameterDefinition[] {
|
||||
// GPT Image 1 使用统一的参数定义,n参数固定为1不暴露给用户
|
||||
// GPT Image 2 使用统一的参数定义,n参数固定为1不暴露给用户
|
||||
return [
|
||||
{
|
||||
name: 'size',
|
||||
@@ -153,7 +166,7 @@ export class OpenAIImageAdapter extends AbstractImageProviderAdapter {
|
||||
descriptionKey: 'image.params.size.description',
|
||||
type: 'string',
|
||||
defaultValue: '1024x1024',
|
||||
allowedValues: ['1024x1024', '1536x1024', '1024x1536', 'auto']
|
||||
allowedValues: [...GPT_IMAGE_2_SIZE_VALUES]
|
||||
},
|
||||
{
|
||||
name: 'quality',
|
||||
@@ -169,7 +182,7 @@ export class OpenAIImageAdapter extends AbstractImageProviderAdapter {
|
||||
descriptionKey: 'image.params.background.description',
|
||||
type: 'string',
|
||||
defaultValue: 'auto',
|
||||
allowedValues: ['auto', 'transparent', 'opaque']
|
||||
allowedValues: [...GPT_IMAGE_2_BACKGROUND_VALUES]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -54,20 +54,32 @@ describe('OpenAIImageAdapter', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('should include quality and size parameters', () => {
|
||||
test('should expose supported GPT Image 2 parameters', () => {
|
||||
const models = adapter.getModels()
|
||||
const model = models.find(m => m.id === 'gpt-image-2')
|
||||
|
||||
expect(model?.parameterDefinitions).toBeDefined()
|
||||
const qualityParam = model?.parameterDefinitions?.find(p => p.name === 'quality')
|
||||
const sizeParam = model?.parameterDefinitions?.find(p => p.name === 'size')
|
||||
const backgroundParam = model?.parameterDefinitions?.find(p => p.name === 'background')
|
||||
|
||||
expect(qualityParam).toBeDefined()
|
||||
expect(qualityParam?.type).toBe('string')
|
||||
expect(qualityParam?.allowedValues).toEqual(expect.arrayContaining(['auto', 'high', 'medium', 'low']))
|
||||
|
||||
expect(sizeParam).toBeDefined()
|
||||
expect(sizeParam?.allowedValues).toContain('1024x1024')
|
||||
expect(sizeParam?.allowedValues).toEqual([
|
||||
'1024x1024',
|
||||
'1536x1024',
|
||||
'1024x1536',
|
||||
'2048x2048',
|
||||
'2048x1152',
|
||||
'3840x2160',
|
||||
'2160x3840',
|
||||
'auto'
|
||||
])
|
||||
|
||||
expect(backgroundParam?.allowedValues).toEqual(['auto', 'opaque'])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -136,7 +148,7 @@ describe('OpenAIImageAdapter', () => {
|
||||
},
|
||||
paramOverrides: {
|
||||
quality: 'standard',
|
||||
size: '1024x1024'
|
||||
size: '3840x2160'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,6 +185,7 @@ describe('OpenAIImageAdapter', () => {
|
||||
|
||||
const [, options] = (global.fetch as any).mock.calls[0]
|
||||
const body = JSON.parse(options.body)
|
||||
expect(body.size).toBe('3840x2160')
|
||||
expect(body.response_format).toBeUndefined()
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user