@@ -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
0 commit comments