-
Notifications
You must be signed in to change notification settings - Fork 1k
Python: Azure AI mapping HostedImageGenerationTool to ImageGenTool #3263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes the Azure AI image generation sample by adding the missing handler for HostedImageGenerationTool in the Azure AI integration layer and updating the sample to use the correct content types for image generation results.
Changes:
- Added
HostedImageGenerationTooltoImageGenToolmapping in Azure AI integration - Updated sample to use
ImageGenerationToolResultContentinstead ofDataContentfor extracting image data - Changed image save location from script directory to OS temporary directory
- Updated model name from
gpt-image-1-minitogpt-image-1in tool options
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
python/samples/getting_started/agents/azure_ai/azure_ai_with_image_generation.py |
Updated sample to use correct content types and save location; however, uses incorrect option keys |
python/packages/azure-ai/agent_framework_azure_ai/_shared.py |
Added handler to map HostedImageGenerationTool to Azure AI's ImageGenTool |
| "model": "gpt-image-1", | ||
| "quality": "low", | ||
| "size": "1024x1024", |
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The option keys used here don't match the HostedImageGenerationToolOptions type definition. According to the HostedImageGenerationToolOptions, the correct keys should be:
- "model_id" instead of "model"
- "image_size" instead of "size"
- "quality" is not a valid option key in HostedImageGenerationToolOptions
The valid keys defined in HostedImageGenerationToolOptions are: count, image_size, media_type, model_id, response_format, and streaming_count.
| "model": "gpt-image-1", | |
| "quality": "low", | |
| "size": "1024x1024", | |
| "model_id": "gpt-image-1", | |
| "image_size": "1024x1024", |
| file_path = current_dir / filename | ||
| file_path = Path(tempfile.gettempdir()) / filename | ||
| async with aiofiles.open(file_path, "wb") as f: | ||
| await f.write(image_data[0].get_data_bytes()) |
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code assumes that image_data[0] (which is content.outputs) will always be a DataContent object with a get_data_bytes() method. However, according to the ImageGenerationToolResultContent type definition, outputs can be either DataContent | UriContent | None. The UriContent class does not have a get_data_bytes() method, which would cause an AttributeError at runtime if a UriContent is returned.
Consider adding a type check or handling for both DataContent (with get_data_bytes()) and UriContent (which would need a different approach, such as downloading from the URI).
Motivation and Context
This PR fixes the Azure AI image generation sample by adding the missing handler for
HostedImageGenerationToolin the Azure AI integration layer and updating the sample to use the correct content types for image generation results.Changes:
HostedImageGenerationTooltoImageGenToolmapping in Azure AI integrationImageGenerationToolResultContentinstead ofDataContentfor extracting image datagpt-image-1-minitogpt-image-1in tool options (the Image Generation tool is empowered by the gpt-image-1 model.)Description
Contribution Checklist