@@ -340,6 +340,126 @@ in client.CreateResponseStreamingAsync(message, responseOptions))
340340 Assert . That ( imageGenItemId , Is . Not . Null . And . Not . Empty ) ;
341341 }
342342
343+ [ Test ]
344+ public async Task ImageGenToolInputMaskWithImageBytes ( )
345+ {
346+ OpenAIResponseClient client = GetTestClient ( ) ;
347+
348+ string imageFilename = "images_dog_and_cat.png" ;
349+ string imagePath = Path . Combine ( "Assets" , imageFilename ) ;
350+ ResponseCreationOptions options = new ( )
351+ {
352+ Tools =
353+ {
354+ ResponseTool . CreateImageGenerationTool (
355+ model : "gpt-image-1" ,
356+ outputFileFormat : ImageGenerationToolOutputFileFormat . Png ,
357+ inputImageMask : new ( BinaryData . FromBytes ( File . ReadAllBytes ( imagePath ) ) , "image/png" ) )
358+ }
359+ } ;
360+
361+ OpenAIResponse response = await client . CreateResponseAsync (
362+ "Generate an image of gray tabby cat hugging an otter with an orange scarf" ,
363+ options ) ;
364+
365+ Assert . That ( response . OutputItems , Has . Count . EqualTo ( 2 ) ) ;
366+ Assert . That ( response . OutputItems [ 0 ] , Is . InstanceOf < ImageGenerationCallResponseItem > ( ) ) ;
367+ Assert . That ( response . OutputItems [ 1 ] , Is . InstanceOf < MessageResponseItem > ( ) ) ;
368+
369+ MessageResponseItem message = ( MessageResponseItem ) response . OutputItems [ 1 ] ;
370+ Assert . That ( message . Content , Has . Count . GreaterThan ( 0 ) ) ;
371+ Assert . That ( message . Content [ 0 ] . Kind , Is . EqualTo ( ResponseContentPartKind . OutputText ) ) ;
372+
373+ Assert . That ( response . Tools . FirstOrDefault ( ) , Is . TypeOf < ImageGenerationTool > ( ) ) ;
374+
375+ ImageGenerationCallResponseItem imageGenResponse = ( ImageGenerationCallResponseItem ) response . OutputItems [ 0 ] ;
376+ Assert . AreEqual ( imageGenResponse . Status , ImageGenerationCallStatus . Completed ) ;
377+ Assert . That ( imageGenResponse . GeneratedImageBytes . ToArray ( ) , Is . Not . Null . And . Not . Empty ) ;
378+ }
379+
380+ [ Test ]
381+ public async Task ImageGenToolInputMaskWithImageUri ( )
382+ {
383+ OpenAIResponseClient client = GetTestClient ( ) ;
384+
385+ ResponseCreationOptions options = new ( )
386+ {
387+ Tools =
388+ {
389+ ResponseTool . CreateImageGenerationTool (
390+ model : "gpt-image-1" ,
391+ outputFileFormat : ImageGenerationToolOutputFileFormat . Png ,
392+ inputImageMask : new ( imageUri : new Uri ( "https://upload.wikimedia.org/wikipedia/commons/c/c3/Openai.png" ) ) )
393+ }
394+ } ;
395+
396+ OpenAIResponse response = await client . CreateResponseAsync (
397+ "Generate an image of gray tabby cat hugging an otter with an orange scarf" ,
398+ options ) ;
399+
400+ Assert . That ( response . OutputItems , Has . Count . EqualTo ( 2 ) ) ;
401+ Assert . That ( response . OutputItems [ 0 ] , Is . InstanceOf < ImageGenerationCallResponseItem > ( ) ) ;
402+ Assert . That ( response . OutputItems [ 1 ] , Is . InstanceOf < MessageResponseItem > ( ) ) ;
403+
404+ MessageResponseItem message = ( MessageResponseItem ) response . OutputItems [ 1 ] ;
405+ Assert . That ( message . Content , Has . Count . GreaterThan ( 0 ) ) ;
406+ Assert . That ( message . Content [ 0 ] . Kind , Is . EqualTo ( ResponseContentPartKind . OutputText ) ) ;
407+
408+ Assert . That ( response . Tools . FirstOrDefault ( ) , Is . TypeOf < ImageGenerationTool > ( ) ) ;
409+
410+ ImageGenerationCallResponseItem imageGenResponse = ( ImageGenerationCallResponseItem ) response . OutputItems [ 0 ] ;
411+ Assert . AreEqual ( imageGenResponse . Status , ImageGenerationCallStatus . Completed ) ;
412+ Assert . That ( imageGenResponse . GeneratedImageBytes . ToArray ( ) , Is . Not . Null . And . Not . Empty ) ;
413+ }
414+
415+ [ Test ]
416+ public async Task ImageGenToolInputMaskWithFileId ( )
417+ {
418+ OpenAIResponseClient client = GetTestClient ( ) ;
419+
420+ OpenAIFileClient fileClient = GetTestClient < OpenAIFileClient > ( TestScenario . Files ) ;
421+
422+ string imageFilename = "images_dog_and_cat.png" ;
423+ string imagePath = Path . Combine ( "Assets" , imageFilename ) ;
424+ using Stream image = File . OpenRead ( imagePath ) ;
425+ BinaryData imageData = BinaryData . FromStream ( image ) ;
426+
427+ OpenAIFile file = await fileClient . UploadFileAsync (
428+ imageData ,
429+ imageFilename ,
430+ FileUploadPurpose . UserData ) ;
431+ Validate ( file ) ;
432+
433+ ResponseCreationOptions options = new ( )
434+ {
435+ Tools =
436+ {
437+ ResponseTool . CreateImageGenerationTool (
438+ model : "gpt-image-1" ,
439+ outputFileFormat : ImageGenerationToolOutputFileFormat . Png ,
440+ inputImageMask : new ( fileId : file . Id ) )
441+ }
442+ } ;
443+
444+ OpenAIResponse response = await client . CreateResponseAsync (
445+ "Generate an image of gray tabby cat hugging an otter with an orange scarf" ,
446+ options ) ;
447+
448+ Assert . That ( response . OutputItems , Has . Count . EqualTo ( 2 ) ) ;
449+ Assert . That ( response . OutputItems [ 0 ] , Is . InstanceOf < ImageGenerationCallResponseItem > ( ) ) ;
450+ Assert . That ( response . OutputItems [ 1 ] , Is . InstanceOf < MessageResponseItem > ( ) ) ;
451+
452+ MessageResponseItem message = ( MessageResponseItem ) response . OutputItems [ 1 ] ;
453+ Assert . That ( message . Content , Has . Count . GreaterThan ( 0 ) ) ;
454+ Assert . That ( message . Content [ 0 ] . Kind , Is . EqualTo ( ResponseContentPartKind . OutputText ) ) ;
455+
456+ Assert . That ( response . Tools . FirstOrDefault ( ) , Is . TypeOf < ImageGenerationTool > ( ) ) ;
457+
458+ ImageGenerationCallResponseItem imageGenResponse = ( ImageGenerationCallResponseItem ) response . OutputItems [ 0 ] ;
459+ Assert . AreEqual ( imageGenResponse . Status , ImageGenerationCallStatus . Completed ) ;
460+ Assert . That ( imageGenResponse . GeneratedImageBytes . ToArray ( ) , Is . Not . Null . And . Not . Empty ) ;
461+ }
462+
343463 [ Test ]
344464 public async Task StreamingResponses ( )
345465 {
0 commit comments