|
6 | 6 | from pathlib import Path |
7 | 7 |
|
8 | 8 | import anyio |
| 9 | +from agent_framework import Content |
9 | 10 | from agent_framework.openai import OpenAIResponsesClient |
10 | 11 |
|
11 | 12 | """OpenAI Responses Client Streaming Image Generation Example |
@@ -72,23 +73,24 @@ async def main(): |
72 | 73 | # Handle partial images |
73 | 74 | # The final partial image IS the complete, full-quality image. Each partial |
74 | 75 | # represents a progressive refinement, with the last one being the finished result. |
75 | | - if ( |
76 | | - content.type == "uri" |
77 | | - and content.additional_properties |
78 | | - and content.additional_properties.get("is_partial_image") |
79 | | - ): |
80 | | - print(f" Image {image_count} received") |
81 | | - |
82 | | - # Extract file extension from media_type (e.g., "image/png" -> "png") |
83 | | - extension = "png" # Default fallback |
84 | | - if content.media_type and "/" in content.media_type: |
85 | | - extension = content.media_type.split("/")[-1] |
86 | | - |
87 | | - # Save images with correct extension |
88 | | - filename = output_dir / f"image{image_count}.{extension}" |
89 | | - await save_image_from_data_uri(content.uri, str(filename)) |
90 | | - |
91 | | - image_count += 1 |
| 76 | + if content.type == "image_generation_tool_result" and isinstance(content.outputs, Content): |
| 77 | + image_output: Content = content.outputs |
| 78 | + if ( |
| 79 | + image_output.type == "data" |
| 80 | + and image_output.additional_properties.get("is_partial_image") |
| 81 | + ): |
| 82 | + print(f" Image {image_count} received") |
| 83 | + |
| 84 | + # Extract file extension from media_type (e.g., "image/png" -> "png") |
| 85 | + extension = "png" # Default fallback |
| 86 | + if image_output.media_type and "/" in image_output.media_type: |
| 87 | + extension = image_output.media_type.split("/")[-1] |
| 88 | + |
| 89 | + # Save images with correct extension |
| 90 | + filename = output_dir / f"image{image_count}.{extension}" |
| 91 | + await save_image_from_data_uri(image_output.uri, str(filename)) |
| 92 | + |
| 93 | + image_count += 1 |
92 | 94 |
|
93 | 95 | # Summary |
94 | 96 | print("\n Summary:") |
|
0 commit comments