mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
This pull request was created in response to the issue https://github.com/microsoft/semantic-kernel/issues/12500#issuecomment-2998387488. The current AzureTextToImage implementation only works with DALL-E 3. For gpt-image-1, the response format has changed from a URL to base64 only, which the current code does not support. Additionally, gpt-image-1 introduces a new image editing feature that also needs to be supported. Since breaking changes are required, new methods have been added. Minimal code that reproduces the problem ```python service = AzureTextToImage( service_id=service_id, deployment_name="image-1", endpoint=AZURE_OPENAI_IMAGE_ENDPOINT, api_key=AZURE_OPENAI_IMAGE_API_KEY, ) ) settings = service.get_prompt_execution_settings_class()(service_id="image1") settings.prompt = "sky" settings.size = ImageSize(width=1024, height=1024) settings.quality = "low" r = await service.generate_image(settings=settings) ``` Example of use with newly added methods ```python from semantic_kernel.connectors.ai.open_ai import AzureTextToImage service = AzureTextToImage( service_id="image1", deployment_name="gpt-image-1", endpoint=AZURE_OPENAI_IMAGE_ENDPOINT, api_key=AZURE_OPENAI_IMAGE_API_KEY, api_version="2025-04-01-preview", ) settings = service.get_prompt_execution_settings_class()(service_id="image1") settings.n = 3 images_b64 = await service.generate_images("A cute cat wearing a whimsical striped hat", settings=settings) ``` ```python from semantic_kernel.connectors.ai.open_ai import AzureTextToImage service = AzureTextToImage( service_id="image1", deployment_name="gpt-image-1", endpoint=AZURE_OPENAI_IMAGE_ENDPOINT, api_key=AZURE_OPENAI_IMAGE_API_KEY, api_version="2025-04-01-preview", ) file_paths = ["./new_images/img_1.png", "./new_images/img_2.png"] settings = service.get_prompt_execution_settings_class()(service_id="image1") settings.n = 2 results = await service.edit_image( prompt="Make the cat wear a wizard hat", image_paths=file_paths, settings=settings, ) ``` ## Problems Identified 1. Assumption of URL-based responses. The current implementation assumes a response format that includes an image url, which is not the case for gpt-image-1. See: https://github.com/microsoft/semantic-kernel/blob/8d1b3fd55155bb65e9671383366d2672c4582fb0/python/semantic_kernel/connectors/ai/open_ai/services/open_ai_text_to_image_base.py#L69