Skip to content

Conversation

@giles17
Copy link
Contributor

@giles17 giles17 commented Jan 17, 2026

Motivation and Context

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 HostedImageGenerationTool to ImageGenTool mapping in Azure AI integration
  • Updated sample to use ImageGenerationToolResultContent instead of DataContent for extracting image data
  • Changed image save location from script directory to OS temporary directory
  • Updated model name from gpt-image-1-mini to gpt-image-1 in tool options (the Image Generation tool is empowered by the gpt-image-1 model.)

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings January 17, 2026 02:06
@github-actions github-actions bot changed the title azureai image gen sample fix Python: azureai image gen sample fix Jan 17, 2026
@markwallace-microsoft
Copy link
Member

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azure-ai/agent_framework_azure_ai
   _shared.py28010562%120, 122, 124, 126, 171, 259–262, 265–267, 270–271, 281, 288–290, 316–325, 372, 388–390, 392–409, 417–420, 423–424, 427–434, 439–440, 446–449, 457–458, 461–462, 464, 476, 478–479, 481–482, 484–485, 487–495, 497, 533, 535–538, 540, 546, 552, 556, 571, 574–575, 577
TOTAL17432267784% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3148 213 💤 0 ❌ 0 🔥 1m 2s ⏱️

Copy link
Contributor

Copilot AI left a 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 HostedImageGenerationTool to ImageGenTool mapping in Azure AI integration
  • Updated sample to use ImageGenerationToolResultContent instead of DataContent for extracting image data
  • Changed image save location from script directory to OS temporary directory
  • Updated model name from gpt-image-1-mini to gpt-image-1 in 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

Comment on lines +36 to 38
"model": "gpt-image-1",
"quality": "low",
"size": "1024x1024",
Copy link

Copilot AI Jan 17, 2026

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.

Suggested change
"model": "gpt-image-1",
"quality": "low",
"size": "1024x1024",
"model_id": "gpt-image-1",
"image_size": "1024x1024",

Copilot uses AI. Check for mistakes.
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())
Copy link

Copilot AI Jan 17, 2026

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).

Copilot uses AI. Check for mistakes.
@giles17 giles17 changed the title Python: azureai image gen sample fix Python: Azure AI mapping HostedImageGenerationTool to ImageGenTool Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants