Files
semantic-kernel/python/semantic_kernel
ふぁー 93a14d5115 Python: feature: support gpt-image-1 (#12621)
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
2025-07-04 14:11:56 +00:00
..
2024-10-10 22:33:42 +00:00
2024-03-28 15:10:28 +00:00