@@ -228,252 +228,6 @@ in client.CreateResponseStreamingAsync(message, responseOptions))
228228 Assert . That ( searchItemId , Is . Not . Null . And . Not . Empty ) ;
229229 }
230230
231- [ RecordedTest ]
232- public async Task ResponseWithImageGenTool ( )
233- {
234- OpenAIResponseClient client = GetTestClient ( ) ;
235-
236- ResponseCreationOptions options = new ( )
237- {
238- Tools =
239- {
240- ResponseTool . CreateImageGenerationTool (
241- model : "gpt-image-1" ,
242- quality : ImageGenerationToolQuality . High ,
243- size : ImageGenerationToolSize . W1024xH1024 ,
244- outputFileFormat : ImageGenerationToolOutputFileFormat . Png ,
245- moderationLevel : ImageGenerationToolModerationLevel . Auto ,
246- background : ImageGenerationToolBackground . Transparent ,
247- inputFidelity : ImageGenerationToolInputFidelity . High )
248- }
249- } ;
250-
251- OpenAIResponse response = await client . CreateResponseAsync (
252- "Generate an image of gray tabby cat hugging an otter with an orange scarf" ,
253- options ) ;
254-
255- Assert . That ( response . OutputItems , Has . Count . EqualTo ( 2 ) ) ;
256- Assert . That ( response . OutputItems [ 0 ] , Is . InstanceOf < ImageGenerationCallResponseItem > ( ) ) ;
257- Assert . That ( response . OutputItems [ 1 ] , Is . InstanceOf < MessageResponseItem > ( ) ) ;
258-
259- MessageResponseItem message = ( MessageResponseItem ) response . OutputItems [ 1 ] ;
260- Assert . That ( message . Content , Has . Count . GreaterThan ( 0 ) ) ;
261- Assert . That ( message . Content [ 0 ] . Kind , Is . EqualTo ( ResponseContentPartKind . OutputText ) ) ;
262-
263- Assert . That ( response . Tools . FirstOrDefault ( ) , Is . TypeOf < ImageGenerationTool > ( ) ) ;
264-
265- ImageGenerationCallResponseItem imageGenResponse = ( ImageGenerationCallResponseItem ) response . OutputItems [ 0 ] ;
266- Assert . That ( imageGenResponse . Status , Is . EqualTo ( ImageGenerationCallStatus . Completed ) ) ;
267- Assert . That ( imageGenResponse . ImageResultBytes . ToArray ( ) , Is . Not . Null . And . Not . Empty ) ;
268- }
269-
270- [ RecordedTest ]
271- public async Task ImageGenToolStreaming ( )
272- {
273- OpenAIResponseClient client = GetTestClient ( ) ;
274-
275- const string message = "Draw a gorgeous image of a river made of white owl feathers, snaking its way through a serene winter landscape" ;
276-
277- ResponseCreationOptions responseOptions = new ( )
278- {
279- Tools =
280- {
281- ResponseTool . CreateImageGenerationTool (
282- model : "gpt-image-1" ,
283- quality : ImageGenerationToolQuality . High ,
284- size : ImageGenerationToolSize . W1024xH1024 ,
285- outputFileFormat : ImageGenerationToolOutputFileFormat . Png ,
286- moderationLevel : ImageGenerationToolModerationLevel . Auto ,
287- background : ImageGenerationToolBackground . Transparent )
288- }
289- } ;
290-
291- string imageGenItemId = null ;
292- int partialCount = 0 ;
293- int inProgressCount = 0 ;
294- int generateCount = 0 ;
295- bool gotCompletedImageGenItem = false ;
296- bool gotCompletedResponseItem = false ;
297-
298- await foreach ( StreamingResponseUpdate update
299- in client . CreateResponseStreamingAsync ( message , responseOptions ) )
300- {
301- if ( update is StreamingResponseImageGenerationCallPartialImageUpdate imageGenCallInPartialUpdate )
302- {
303- Assert . That ( imageGenCallInPartialUpdate . ItemId , Is . Not . Null . And . Not . Empty ) ;
304- imageGenItemId ??= imageGenCallInPartialUpdate . ItemId ;
305- Assert . That ( imageGenItemId , Is . EqualTo ( imageGenCallInPartialUpdate . ItemId ) ) ;
306- Assert . That ( imageGenCallInPartialUpdate . OutputIndex , Is . EqualTo ( 0 ) ) ;
307- partialCount ++ ;
308- }
309- else if ( update is StreamingResponseImageGenerationCallInProgressUpdate imageGenCallInProgressUpdate )
310- {
311- Assert . That ( imageGenCallInProgressUpdate . ItemId , Is . Not . Null . And . Not . Empty ) ;
312- imageGenItemId ??= imageGenCallInProgressUpdate . ItemId ;
313- Assert . That ( imageGenItemId , Is . EqualTo ( imageGenCallInProgressUpdate . ItemId ) ) ;
314- Assert . That ( imageGenCallInProgressUpdate . OutputIndex , Is . EqualTo ( 0 ) ) ;
315- inProgressCount ++ ;
316- }
317- else if ( update is StreamingResponseImageGenerationCallGeneratingUpdate imageGenCallGeneratingUpdate )
318- {
319- Assert . That ( imageGenCallGeneratingUpdate . ItemId , Is . Not . Null . And . Not . Empty ) ;
320- imageGenItemId ??= imageGenCallGeneratingUpdate . ItemId ;
321- Assert . That ( imageGenItemId , Is . EqualTo ( imageGenCallGeneratingUpdate . ItemId ) ) ;
322- Assert . That ( imageGenCallGeneratingUpdate . OutputIndex , Is . EqualTo ( 0 ) ) ;
323- generateCount ++ ;
324- }
325- else if ( update is StreamingResponseImageGenerationCallCompletedUpdate outputItemCompleteUpdate )
326- {
327- Assert . That ( outputItemCompleteUpdate . ItemId , Is . Not . Null . And . Not . Empty ) ;
328- imageGenItemId ??= outputItemCompleteUpdate . ItemId ;
329- Assert . That ( imageGenItemId , Is . EqualTo ( outputItemCompleteUpdate . ItemId ) ) ;
330- Assert . That ( outputItemCompleteUpdate . OutputIndex , Is . EqualTo ( 0 ) ) ;
331- gotCompletedImageGenItem = true ;
332- }
333- else if ( update is StreamingResponseOutputItemDoneUpdate outputItemDoneUpdate )
334- {
335- if ( outputItemDoneUpdate . Item is ImageGenerationCallResponseItem imageGenCallItem )
336- {
337- Assert . That ( imageGenCallItem . Id , Is . Not . Null . And . Not . Empty ) ;
338- imageGenItemId ??= imageGenCallItem . Id ;
339- Assert . That ( imageGenItemId , Is . EqualTo ( outputItemDoneUpdate . Item . Id ) ) ;
340- Assert . That ( outputItemDoneUpdate . OutputIndex , Is . EqualTo ( 0 ) ) ;
341- gotCompletedResponseItem = true ;
342- }
343- }
344- }
345-
346- Assert . That ( gotCompletedResponseItem || gotCompletedImageGenItem , Is . True ) ;
347- Assert . That ( partialCount , Is . EqualTo ( 1 ) ) ;
348- Assert . That ( inProgressCount , Is . EqualTo ( 1 ) ) ;
349- Assert . That ( generateCount , Is . EqualTo ( 1 ) ) ;
350- Assert . That ( imageGenItemId , Is . Not . Null . And . Not . Empty ) ;
351- }
352-
353- [ RecordedTest ]
354- public async Task ImageGenToolInputMaskWithImageBytes ( )
355- {
356- OpenAIResponseClient client = GetTestClient ( ) ;
357-
358- string imageFilename = "images_dog_and_cat.png" ;
359- string imagePath = Path . Combine ( "Assets" , imageFilename ) ;
360- ResponseCreationOptions options = new ( )
361- {
362- Tools =
363- {
364- ResponseTool . CreateImageGenerationTool (
365- model : "gpt-image-1" ,
366- outputFileFormat : ImageGenerationToolOutputFileFormat . Png ,
367- inputImageMask : new ( BinaryData . FromBytes ( File . ReadAllBytes ( imagePath ) ) , "image/png" ) )
368- }
369- } ;
370-
371- OpenAIResponse response = await client . CreateResponseAsync (
372- "Generate an image of gray tabby cat hugging an otter with an orange scarf" ,
373- options ) ;
374-
375- Assert . That ( response . OutputItems , Has . Count . EqualTo ( 2 ) ) ;
376- Assert . That ( response . OutputItems [ 0 ] , Is . InstanceOf < ImageGenerationCallResponseItem > ( ) ) ;
377- Assert . That ( response . OutputItems [ 1 ] , Is . InstanceOf < MessageResponseItem > ( ) ) ;
378-
379- MessageResponseItem message = ( MessageResponseItem ) response . OutputItems [ 1 ] ;
380- Assert . That ( message . Content , Has . Count . GreaterThan ( 0 ) ) ;
381- Assert . That ( message . Content [ 0 ] . Kind , Is . EqualTo ( ResponseContentPartKind . OutputText ) ) ;
382-
383- Assert . That ( response . Tools . FirstOrDefault ( ) , Is . TypeOf < ImageGenerationTool > ( ) ) ;
384-
385- ImageGenerationCallResponseItem imageGenResponse = ( ImageGenerationCallResponseItem ) response . OutputItems [ 0 ] ;
386- Assert . That ( imageGenResponse . Status , Is . EqualTo ( ImageGenerationCallStatus . Completed ) ) ;
387- Assert . That ( imageGenResponse . ImageResultBytes . ToArray ( ) , Is . Not . Null . And . Not . Empty ) ;
388- }
389-
390- [ RecordedTest ]
391- public async Task ImageGenToolInputMaskWithImageUri ( )
392- {
393- OpenAIResponseClient client = GetTestClient ( ) ;
394-
395- ResponseCreationOptions options = new ( )
396- {
397- Tools =
398- {
399- ResponseTool . CreateImageGenerationTool (
400- model : "gpt-image-1" ,
401- outputFileFormat : ImageGenerationToolOutputFileFormat . Png ,
402- inputImageMask : new ( imageUri : new Uri ( "https://upload.wikimedia.org/wikipedia/commons/c/c3/Openai.png" ) ) )
403- }
404- } ;
405-
406- OpenAIResponse response = await client . CreateResponseAsync (
407- "Generate an image of gray tabby cat hugging an otter with an orange scarf" ,
408- options ) ;
409-
410- Assert . That ( response . OutputItems , Has . Count . EqualTo ( 2 ) ) ;
411- Assert . That ( response . OutputItems [ 0 ] , Is . InstanceOf < ImageGenerationCallResponseItem > ( ) ) ;
412- Assert . That ( response . OutputItems [ 1 ] , Is . InstanceOf < MessageResponseItem > ( ) ) ;
413-
414- MessageResponseItem message = ( MessageResponseItem ) response . OutputItems [ 1 ] ;
415- Assert . That ( message . Content , Has . Count . GreaterThan ( 0 ) ) ;
416- Assert . That ( message . Content [ 0 ] . Kind , Is . EqualTo ( ResponseContentPartKind . OutputText ) ) ;
417-
418- Assert . That ( response . Tools . FirstOrDefault ( ) , Is . TypeOf < ImageGenerationTool > ( ) ) ;
419-
420- ImageGenerationCallResponseItem imageGenResponse = ( ImageGenerationCallResponseItem ) response . OutputItems [ 0 ] ;
421- Assert . That ( imageGenResponse . Status , Is . EqualTo ( ImageGenerationCallStatus . Completed ) ) ;
422- Assert . That ( imageGenResponse . ImageResultBytes . ToArray ( ) , Is . Not . Null . And . Not . Empty ) ;
423- }
424-
425- [ RecordedTest ]
426- public async Task ImageGenToolInputMaskWithFileId ( )
427- {
428- OpenAIResponseClient client = GetTestClient ( ) ;
429-
430- OpenAIFileClient fileClient = GetProxiedOpenAIClient < OpenAIFileClient > ( TestScenario . Files ) ;
431-
432- string imageFilename = "images_dog_and_cat.png" ;
433- string imagePath = Path . Combine ( "Assets" , imageFilename ) ;
434- using Stream image = File . OpenRead ( imagePath ) ;
435- BinaryData imageData = BinaryData . FromStream ( image ) ;
436-
437- OpenAIFile file ;
438- using ( Recording . DisableRequestBodyRecording ( ) ) // Temp pending https://github.com/Azure/azure-sdk-tools/issues/11901
439- {
440- file = await fileClient . UploadFileAsync (
441- imageData ,
442- imageFilename ,
443- FileUploadPurpose . UserData ) ;
444- }
445- Validate ( file ) ;
446-
447- ResponseCreationOptions options = new ( )
448- {
449- Tools =
450- {
451- ResponseTool . CreateImageGenerationTool (
452- model : "gpt-image-1" ,
453- outputFileFormat : ImageGenerationToolOutputFileFormat . Png ,
454- inputImageMask : new ( fileId : file . Id ) )
455- }
456- } ;
457-
458- OpenAIResponse response = await client . CreateResponseAsync (
459- "Generate an image of gray tabby cat hugging an otter with an orange scarf" ,
460- options ) ;
461-
462- Assert . That ( response . OutputItems , Has . Count . EqualTo ( 2 ) ) ;
463- Assert . That ( response . OutputItems [ 0 ] , Is . InstanceOf < ImageGenerationCallResponseItem > ( ) ) ;
464- Assert . That ( response . OutputItems [ 1 ] , Is . InstanceOf < MessageResponseItem > ( ) ) ;
465-
466- MessageResponseItem message = ( MessageResponseItem ) response . OutputItems [ 1 ] ;
467- Assert . That ( message . Content , Has . Count . GreaterThan ( 0 ) ) ;
468- Assert . That ( message . Content [ 0 ] . Kind , Is . EqualTo ( ResponseContentPartKind . OutputText ) ) ;
469-
470- Assert . That ( response . Tools . FirstOrDefault ( ) , Is . TypeOf < ImageGenerationTool > ( ) ) ;
471-
472- ImageGenerationCallResponseItem imageGenResponse = ( ImageGenerationCallResponseItem ) response . OutputItems [ 0 ] ;
473- Assert . That ( imageGenResponse . Status , Is . EqualTo ( ImageGenerationCallStatus . Completed ) ) ;
474- Assert . That ( imageGenResponse . ImageResultBytes . ToArray ( ) , Is . Not . Null . And . Not . Empty ) ;
475- }
476-
477231 [ RecordedTest ]
478232 public async Task StreamingResponses ( )
479233 {
0 commit comments