Skip to content

Commit 95fb9c4

Browse files
committed
feat: use GPT Image 2 for OpenAI image generation
1 parent f879df0 commit 95fb9c4

2 files changed

Lines changed: 59 additions & 2 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2+
import { createPinia, setActivePinia } from 'pinia'
3+
import { useSettingsStore } from '../../../stores/settingsStore'
4+
5+
function installWindowMocks() {
6+
;(globalThis as any).window = {
7+
customToolsAPI: {
8+
list: vi.fn().mockResolvedValue({
9+
success: true,
10+
data: {
11+
tools: [],
12+
diagnostics: [],
13+
filePath: '',
14+
lastModified: Date.now(),
15+
},
16+
}),
17+
},
18+
}
19+
}
20+
21+
describe('buildToolsForProvider', () => {
22+
beforeEach(() => {
23+
setActivePinia(createPinia())
24+
installWindowMocks()
25+
})
26+
27+
afterEach(() => {
28+
vi.restoreAllMocks()
29+
delete (globalThis as any).window
30+
})
31+
32+
it('uses GPT Image 2 for OpenAI image generation', async () => {
33+
const settingsStore = useSettingsStore()
34+
settingsStore.updateSetting('aiProvider', 'openai')
35+
settingsStore.updateSetting('assistantModel', 'gpt-5')
36+
settingsStore.updateSetting('assistantReasoningEffort', 'medium')
37+
38+
const { buildToolsForProvider } = await import('../tools')
39+
const tools = await buildToolsForProvider()
40+
41+
expect(tools).toContainEqual({
42+
type: 'image_generation',
43+
model: 'gpt-image-2',
44+
partial_images: 2,
45+
})
46+
})
47+
})

src/services/llmProviders/tools.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
} from '../../utils/assistantTools'
77
import { PROVIDER_CONFIGS } from './providerCatalog'
88

9+
const OPENAI_IMAGE_GENERATION_MODEL = 'gpt-image-2'
10+
911
export async function buildToolsForProvider(): Promise<any[]> {
1012
const settings = useSettingsStore().config
1113
const finalToolsForApi: any[] = []
@@ -71,12 +73,20 @@ export async function buildToolsForProvider(): Promise<any[]> {
7173

7274
if (!isOModel) {
7375
if (!isGpt5WithMinimalReasoning) {
74-
finalToolsForApi.push({ type: 'image_generation', partial_images: 2 })
76+
finalToolsForApi.push({
77+
type: 'image_generation',
78+
model: OPENAI_IMAGE_GENERATION_MODEL,
79+
partial_images: 2,
80+
})
7581
finalToolsForApi.push({ type: 'web_search_preview' })
7682
}
7783
} else {
7884
if (modelName.includes('o3-pro') && modelName === 'o3') {
79-
finalToolsForApi.push({ type: 'image_generation', partial_images: 2 })
85+
finalToolsForApi.push({
86+
type: 'image_generation',
87+
model: OPENAI_IMAGE_GENERATION_MODEL,
88+
partial_images: 2,
89+
})
8090
finalToolsForApi.push({ type: 'web_search_preview' })
8191
}
8292
}

0 commit comments

Comments
 (0)