@@ -810,26 +810,38 @@ in client.CreateResponseStreamingAsync(message, responseOptions))
810810 }
811811
812812 [ RecordedTest ]
813+ [ LiveOnly ( Reason = "Temp due to the recording framework timing out" ) ]
813814 public async Task ImageGenToolInputMaskWithImageBytes ( )
814815 {
815- OpenAIResponseClient client = GetTestClient ( ) ;
816+ OpenAIResponseClient client = GetTestClient ( options : new ( ) { NetworkTimeout = TimeSpan . FromMinutes ( 5 ) } ) ;
816817
817- string imageFilename = "images_dog_and_cat .png" ;
818+ string imageFilename = "images_empty_room .png" ;
818819 string imagePath = Path . Combine ( "Assets" , imageFilename ) ;
820+ BinaryData imageBytes = BinaryData . FromBytes ( File . ReadAllBytes ( imagePath ) ) ;
821+
822+ string maskFilename = "images_empty_room_with_mask.png" ;
823+ string maskPath = Path . Combine ( "Assets" , maskFilename ) ;
824+ BinaryData maskBytes = BinaryData . FromBytes ( File . ReadAllBytes ( maskPath ) ) ;
825+
826+ List < ResponseItem > inputItems = [
827+ ResponseItem . CreateUserMessageItem ( "Edit this image by adding a big cat with big round eyes and large cat ears, sitting in an empty room and looking at the camera." ) ,
828+ ResponseItem . CreateUserMessageItem ( [ ResponseContentPart . CreateInputImagePart ( imageBytes , "image/png" ) ] )
829+ ] ;
830+
819831 ResponseCreationOptions options = new ( )
820832 {
821833 Tools =
822834 {
823- ResponseTool . CreateImageGenerationTool (
824- model : "gpt-image-1" ,
825- outputFileFormat : ImageGenerationToolOutputFileFormat . Png ,
826- inputImageMask : new ( BinaryData . FromBytes ( File . ReadAllBytes ( imagePath ) ) , "image/png" ) )
835+ ResponseTool . CreateImageGenerationTool (
836+ model : "gpt-image-1-mini" ,
837+ outputFileFormat : ImageGenerationToolOutputFileFormat . Png ,
838+ size : ImageGenerationToolSize . W1024xH1024 ,
839+ quality : ImageGenerationToolQuality . Low ,
840+ inputImageMask : new ( maskBytes , "image/png" ) )
827841 }
828842 } ;
829843
830- OpenAIResponse response = await client . CreateResponseAsync (
831- "Generate an image of gray tabby cat hugging an otter with an orange scarf" ,
832- options ) ;
844+ OpenAIResponse response = await client . CreateResponseAsync ( inputItems , options ) ;
833845
834846 Assert . That ( response . OutputItems , Has . Count . EqualTo ( 2 ) ) ;
835847 Assert . That ( response . OutputItems [ 0 ] , Is . InstanceOf < ImageGenerationCallResponseItem > ( ) ) ;
@@ -849,22 +861,30 @@ public async Task ImageGenToolInputMaskWithImageBytes()
849861 [ RecordedTest ]
850862 public async Task ImageGenToolInputMaskWithImageUri ( )
851863 {
852- OpenAIResponseClient client = GetTestClient ( ) ;
864+ OpenAIResponseClient client = GetTestClient ( options : new ( ) { NetworkTimeout = TimeSpan . FromMinutes ( 5 ) } ) ;
865+
866+ Uri imageUri = new ( "https://github.com/openai/openai-dotnet/blob/db6328accdd7927f19915cdc5412eb841f2447c1/tests/Assets/images_empty_room.png?raw=true" ) ;
867+ Uri maskUri = new ( "https://github.com/openai/openai-dotnet/blob/db6328accdd7927f19915cdc5412eb841f2447c1/tests/Assets/images_empty_room_with_mask.png?raw=true" ) ;
868+
869+ List < ResponseItem > inputItems = [
870+ ResponseItem . CreateUserMessageItem ( "Edit this image by adding a big cat with big round eyes and large cat ears, sitting in an empty room and looking at the camera." ) ,
871+ ResponseItem . CreateUserMessageItem ( [ ResponseContentPart . CreateInputImagePart ( imageUri ) ] )
872+ ] ;
853873
854874 ResponseCreationOptions options = new ( )
855875 {
856876 Tools =
857877 {
858- ResponseTool . CreateImageGenerationTool (
859- model : "gpt-image-1" ,
860- outputFileFormat : ImageGenerationToolOutputFileFormat . Png ,
861- inputImageMask : new ( imageUri : new Uri ( "https://upload.wikimedia.org/wikipedia/commons/c/c3/Openai.png" ) ) )
878+ ResponseTool . CreateImageGenerationTool (
879+ model : "gpt-image-1-mini" ,
880+ outputFileFormat : ImageGenerationToolOutputFileFormat . Png ,
881+ size : ImageGenerationToolSize . W1024xH1024 ,
882+ quality : ImageGenerationToolQuality . Low ,
883+ inputImageMask : new ( maskUri ) )
862884 }
863885 } ;
864886
865- OpenAIResponse response = await client . CreateResponseAsync (
866- "Generate an image of gray tabby cat hugging an otter with an orange scarf" ,
867- options ) ;
887+ OpenAIResponse response = await client . CreateResponseAsync ( inputItems , options ) ;
868888
869889 Assert . That ( response . OutputItems , Has . Count . EqualTo ( 2 ) ) ;
870890 Assert . That ( response . OutputItems [ 0 ] , Is . InstanceOf < ImageGenerationCallResponseItem > ( ) ) ;
@@ -882,41 +902,59 @@ public async Task ImageGenToolInputMaskWithImageUri()
882902 }
883903
884904 [ RecordedTest ]
905+ [ Category ( "MPFD" ) ]
885906 public async Task ImageGenToolInputMaskWithFileId ( )
886907 {
887- OpenAIResponseClient client = GetTestClient ( ) ;
908+ OpenAIResponseClient client = GetTestClient ( options : new ( ) { NetworkTimeout = TimeSpan . FromMinutes ( 5 ) } ) ;
888909
889910 OpenAIFileClient fileClient = GetProxiedOpenAIClient < OpenAIFileClient > ( TestScenario . Files ) ;
890911
891- string imageFilename = "images_dog_and_cat .png" ;
912+ string imageFilename = "images_empty_room .png" ;
892913 string imagePath = Path . Combine ( "Assets" , imageFilename ) ;
893- using Stream image = File . OpenRead ( imagePath ) ;
894- BinaryData imageData = BinaryData . FromStream ( image ) ;
914+ BinaryData imageBytes = BinaryData . FromBytes ( File . ReadAllBytes ( imagePath ) ) ;
915+
916+ string maskFilename = "images_empty_room_with_mask.png" ;
917+ string maskPath = Path . Combine ( "Assets" , maskFilename ) ;
918+ BinaryData maskBytes = BinaryData . FromBytes ( File . ReadAllBytes ( maskPath ) ) ;
895919
896- OpenAIFile file ;
920+ OpenAIFile imageFile ;
897921 using ( Recording . DisableRequestBodyRecording ( ) ) // Temp pending https://github.com/Azure/azure-sdk-tools/issues/11901
898922 {
899- file = await fileClient . UploadFileAsync (
900- imageData ,
901- imageFilename ,
902- FileUploadPurpose . UserData ) ;
923+ imageFile = await fileClient . UploadFileAsync ( imageBytes , imageFilename , FileUploadPurpose . UserData ) ;
924+ }
925+ Validate ( imageFile ) ;
926+
927+ OpenAIFile maskFile ;
928+ using ( Recording . DisableRequestBodyRecording ( ) ) // Temp pending https://github.com/Azure/azure-sdk-tools/issues/11901
929+ {
930+ maskFile = await fileClient . UploadFileAsync ( maskBytes , maskFilename , FileUploadPurpose . UserData ) ;
931+ }
932+ Validate ( imageFile ) ;
933+
934+ if ( Mode != RecordedTestMode . Playback )
935+ {
936+ await Task . Delay ( TimeSpan . FromSeconds ( 10 ) ) ;
903937 }
904- Validate ( file ) ;
938+
939+ List < ResponseItem > inputItems = [
940+ ResponseItem . CreateUserMessageItem ( "Edit this image by adding a big cat with big round eyes and large cat ears, sitting in an empty room and looking at the camera." ) ,
941+ ResponseItem . CreateUserMessageItem ( [ ResponseContentPart . CreateInputImagePart ( imageFileId : imageFile . Id ) ] )
942+ ] ;
905943
906944 ResponseCreationOptions options = new ( )
907945 {
908946 Tools =
909947 {
910- ResponseTool . CreateImageGenerationTool (
911- model : "gpt-image-1" ,
912- outputFileFormat : ImageGenerationToolOutputFileFormat . Png ,
913- inputImageMask : new ( fileId : file . Id ) )
948+ ResponseTool . CreateImageGenerationTool (
949+ model : "gpt-image-1-mini" ,
950+ outputFileFormat : ImageGenerationToolOutputFileFormat . Png ,
951+ size : ImageGenerationToolSize . W1024xH1024 ,
952+ quality : ImageGenerationToolQuality . Low ,
953+ inputImageMask : new ( fileId : maskFile . Id ) )
914954 }
915955 } ;
916956
917- OpenAIResponse response = await client . CreateResponseAsync (
918- "Generate an image of gray tabby cat hugging an otter with an orange scarf" ,
919- options ) ;
957+ OpenAIResponse response = await client . CreateResponseAsync ( inputItems , options ) ;
920958
921959 Assert . That ( response . OutputItems , Has . Count . EqualTo ( 2 ) ) ;
922960 Assert . That ( response . OutputItems [ 0 ] , Is . InstanceOf < ImageGenerationCallResponseItem > ( ) ) ;
@@ -1003,5 +1041,5 @@ private static void ValidateCodeInterpreterEvent(ref int inProgressCount, ref in
10031041 }
10041042 }
10051043
1006- private OpenAIResponseClient GetTestClient ( string overrideModel = null ) => GetProxiedOpenAIClient < OpenAIResponseClient > ( TestScenario . Responses , overrideModel ) ;
1044+ private OpenAIResponseClient GetTestClient ( string overrideModel = null , OpenAIClientOptions options = null ) => GetProxiedOpenAIClient < OpenAIResponseClient > ( TestScenario . Responses , overrideModel , options : options ) ;
10071045}
0 commit comments