Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions python/packages/azure-ai/agent_framework_azure_ai/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
HostedCodeInterpreterTool,
HostedFileContent,
HostedFileSearchTool,
HostedImageGenerationTool,
HostedMCPTool,
HostedVectorStoreContent,
HostedWebSearchTool,
Expand All @@ -31,6 +32,7 @@
CodeInterpreterTool,
CodeInterpreterToolAuto,
FunctionTool,
ImageGenTool,
MCPTool,
ResponseTextFormatConfigurationJsonObject,
ResponseTextFormatConfigurationJsonSchema,
Expand Down Expand Up @@ -442,6 +444,16 @@ def to_azure_ai_tools(
timezone=location.get("timezone"),
)
azure_tools.append(ws_tool)
case HostedImageGenerationTool():
opts = tool.options or {}
azure_tools.append(
ImageGenTool(
model=opts.get("model_id", "gpt-image-1"),
size=opts.get("image_size"),
output_format=opts.get("media_type"),
partial_images=opts.get("streaming_count"),
)
)
case _:
logger.debug("Unsupported tool passed (type: %s)", type(tool))
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright (c) Microsoft. All rights reserved.
import asyncio
import tempfile
from pathlib import Path

import aiofiles
from agent_framework import DataContent, HostedImageGenerationTool
from agent_framework import HostedImageGenerationTool, ImageGenerationToolResultContent
Comment thread
giles17 marked this conversation as resolved.
Outdated
from agent_framework.azure import AzureAIProjectAgentProvider
from azure.identity.aio import AzureCliCredential

Expand Down Expand Up @@ -32,7 +33,7 @@ async def main() -> None:
tools=[
HostedImageGenerationTool(
options={
"model": "gpt-image-1-mini",
"model": "gpt-image-1",
"quality": "low",
"size": "1024x1024",
Comment thread
giles17 marked this conversation as resolved.
Outdated
}
Expand All @@ -54,15 +55,14 @@ async def main() -> None:
# Save the image to a file
print("Downloading generated image...")
image_data = [
content
content.outputs
for content in result.messages[0].contents
if isinstance(content, DataContent) and content.media_type == "image/png"
if isinstance(content, ImageGenerationToolResultContent) and content.outputs is not None
]
if image_data and image_data[0]:
# Save to the same directory as this script
# Save to the OS temporary directory
filename = "microsoft.png"
current_dir = Path(__file__).parent.resolve()
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())
Comment thread
giles17 marked this conversation as resolved.
Outdated

Expand Down
Loading