Skip to content

Commit e136854

Browse files
Merge branch 'main' into issue-216-input-pdf
2 parents dfb2d08 + 886e25a commit e136854

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

.changeset/shiny-beers-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openai/agents-openai': patch
3+
---
4+
5+
Add input_fidelity parameter support to image generation tool

examples/tools/image-generation.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function main() {
1818
const agent = new Agent({
1919
name: 'Image generator',
2020
instructions: 'You are a helpful agent.',
21-
tools: [imageGenerationTool({ quality: 'low' })],
21+
tools: [imageGenerationTool({ quality: 'low', inputFidelity: 'high' })],
2222
});
2323

2424
await withTrace('Image generation example', async () => {
@@ -40,6 +40,35 @@ async function main() {
4040
fs.writeFileSync(tmpPath, buffer);
4141
// console.log(`Image saved to ${tmpPath}`);
4242
openFile(tmpPath);
43+
44+
const revisedResult = await run(agent, [
45+
{
46+
role: 'user',
47+
content: [
48+
{
49+
type: 'input_text',
50+
text: 'Change only the background of the given image to Japanese style.',
51+
},
52+
{
53+
type: 'input_image',
54+
image: 'data:image/png;base64,' + item.rawItem.output,
55+
},
56+
],
57+
},
58+
]);
59+
for (const revisedItem of revisedResult.newItems) {
60+
if (
61+
revisedItem.type === 'tool_call_item' &&
62+
revisedItem.rawItem.type === 'hosted_tool_call' &&
63+
revisedItem.rawItem.output
64+
) {
65+
const buffer = Buffer.from(revisedItem.rawItem.output, 'base64');
66+
const tmpPath = path.join(os.tmpdir(), `image-${Date.now()}.png`);
67+
fs.writeFileSync(tmpPath, buffer);
68+
// console.log(`Image saved to ${tmpPath}`);
69+
openFile(tmpPath);
70+
}
71+
}
4372
}
4473
}
4574
// or using result.output works too

packages/agents-openai/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
},
2020
"dependencies": {
2121
"@openai/agents-core": "workspace:*",
22+
"@openai/zod": "npm:[email protected] - 3.25.67",
2223
"debug": "^4.4.0",
23-
"openai": "^5.10.1",
24-
"@openai/zod": "npm:[email protected] - 3.25.67"
24+
"openai": "^5.10.1"
2525
},
2626
"scripts": {
2727
"prebuild": "tsx ../../scripts/embedMeta.ts",

packages/agents-openai/src/openaiResponsesModel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ function converTool<_TContext = unknown>(
174174
tool: {
175175
type: 'image_generation',
176176
background: tool.providerData.background,
177+
input_fidelity: tool.providerData.input_fidelity,
177178
input_image_mask: tool.providerData.input_image_mask,
178179
model: tool.providerData.model,
179180
moderation: tool.providerData.moderation,

packages/agents-openai/src/tools.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export type ImageGenerationTool = {
156156
type: 'image_generation';
157157
name?: 'image_generation' | string;
158158
background?: 'transparent' | 'opaque' | 'auto' | string;
159+
inputFidelity?: 'high' | 'low' | null;
159160
inputImageMask?: OpenAI.Responses.Tool.ImageGeneration.InputImageMask;
160161
model?: 'gpt-image-1' | string;
161162
moderation?: 'auto' | 'low' | string;
@@ -178,6 +179,7 @@ export function imageGenerationTool(
178179
type: 'image_generation',
179180
name: options.name ?? 'image_generation',
180181
background: options.background,
182+
input_fidelity: options.inputFidelity,
181183
input_image_mask: options.inputImageMask,
182184
model: options.model,
183185
moderation: options.moderation,

0 commit comments

Comments
 (0)