Skip to content

Python: Add Ollama text to image service - #14437

Open
Shoumik Chakravarty (shoumikchakravarty-dev) wants to merge 2 commits into
microsoft:mainfrom
shoumikchakravarty-dev:python/ollama-text-to-image-13938
Open

Python: Add Ollama text to image service#14437
Shoumik Chakravarty (shoumikchakravarty-dev) wants to merge 2 commits into
microsoft:mainfrom
shoumikchakravarty-dev:python/ollama-text-to-image-13938

Conversation

@shoumikchakravarty-dev

@shoumikchakravarty-dev Shoumik Chakravarty (shoumikchakravarty-dev) commented Sep 13, 2026

Copy link
Copy Markdown

Motivation and Context

Closes #13938
Ollama supports image generation https://ollama.com/blog/image-generation through POST /api/generate, which returns a base64-encoded image field for image models. Semantic Kernel has no Ollama text-to-image service, so these models cannot be used through the TextToImageClientBase abstraction.

Description

Adds OllamaTextToImage, following the connector's existing one-service-per-modality

  • ollama_text_to_image.py implementing generate_image() via AsyncClient.generate() and returning the
    decoded image bytes
  • OLLAMA_IMAGE_MODEL_ID setting on OllamaSettings, matching the existing chat, text and embedding model IDs.
  • OllamaTextToImagePromptExecutionSettings carrying width, height and steps.
  • Exports from connectors/ai/ollama/__init__.py.
  • Adds unit tests covering initialization, custom host and client, base64 decoding, get_image_content, size settings, the deprecated width/height arguments and their precedence, and the missing-image error path.

No new dependencies: the ollama package SK already depends on exposes image on
GenerateResponse, and width, height and steps on generate().

Contribution Checklist

Adds OllamaTextToImage, a TextToImageClientBase implementation backed by the
Ollama generate endpoint, which returns a base64 image payload for image
generation models such as x/z-image-turbo.

The service follows the existing per-modality layout of the Ollama connector:
a new OLLAMA_IMAGE_MODEL_ID setting, an OllamaTextToImagePromptExecutionSettings
class carrying width, height and steps, and exports from the connector package.
The deprecated width and height arguments of generate_image are forwarded to the
endpoint when the settings do not already specify them. A response without image
data raises ServiceInvalidResponseError rather than returning empty bytes.

Adds unit tests covering initialization, custom host and client, base64
decoding, get_image_content, size settings, the deprecated size arguments and
their precedence, and the missing-image error path.

Closes microsoft#13938

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation and tests are complete; only a minor documentation nit remains.

Pull request overview

Adds Ollama text-to-image support with configurable image generation settings and base64-decoded output.

Changes:

  • Adds OllamaTextToImage and public exports.
  • Adds image model configuration and generation settings.
  • Adds comprehensive unit tests.
File summaries
File Summary
python/tests/unit/connectors/ai/ollama/services/test_ollama_text_to_image.py Tests image generation behavior and error handling.
python/tests/unit/connectors/ai/ollama/conftest.py Adds image model test configuration.
python/semantic_kernel/connectors/ai/ollama/services/ollama_text_to_image.py Implements Ollama image generation.
python/semantic_kernel/connectors/ai/ollama/ollama_settings.py Adds the image model setting.
python/semantic_kernel/connectors/ai/ollama/ollama_prompt_execution_settings.py Adds image size and steps settings.
python/semantic_kernel/connectors/ai/ollama/__init__.py Exports the new service.
Review details

Suppressed comments (1)

python/semantic_kernel/connectors/ai/ollama/init.py:13

  • The connector index in python/semantic_kernel/connectors/ai/README.md lists each provider's public modality service, including the existing OpenAI and Azure text-to-image clients, but does not list this new Ollama client. Add OllamaTextToImage there so the exported service is discoverable and the index stays complete.
from semantic_kernel.connectors.ai.ollama.services.ollama_text_to_image import OllamaTextToImage
  • Files reviewed: 6/6 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Adds the new service to the modality table in connectors/ai/README.md, next to
the other Ollama services, so the exported client is discoverable alongside the
OpenAI and Azure text to image clients.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Feature: ollama text-to-image support

2 participants