Python: Add Ollama text to image service - #14437
Open
Shoumik Chakravarty (shoumikchakravarty-dev) wants to merge 2 commits into
Open
Python: Add Ollama text to image service#14437Shoumik Chakravarty (shoumikchakravarty-dev) wants to merge 2 commits into
Shoumik Chakravarty (shoumikchakravarty-dev) wants to merge 2 commits into
Conversation
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
Shoumik Chakravarty (shoumikchakravarty-dev)
requested a review
from a team
as a code owner
September 13, 2026 02:35
Shoumik Chakravarty (shoumikchakravarty-dev)
had a problem deploying
to
github-app-auth
September 13, 2026 02:35 — with
GitHub Actions
Failure
Shoumik Chakravarty (shoumikchakravarty-dev)
had a problem deploying
to
github-app-auth
September 13, 2026 02:35 — with
GitHub Actions
Failure
Contributor
There was a problem hiding this comment.
🟢 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
OllamaTextToImageand 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.mdlists each provider's public modality service, including the existing OpenAI and Azure text-to-image clients, but does not list this new Ollama client. AddOllamaTextToImagethere 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.
Shoumik Chakravarty (shoumikchakravarty-dev)
had a problem deploying
to
github-app-auth
September 13, 2026 02:43 — with
GitHub Actions
Failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Closes #13938
Ollama supports image generation https://ollama.com/blog/image-generation through
POST /api/generate, which returns a base64-encodedimagefield for image models. Semantic Kernel has no Ollama text-to-image service, so these models cannot be used through theTextToImageClientBaseabstraction.Description
Adds
OllamaTextToImage, following the connector's existing one-service-per-modalityollama_text_to_image.pyimplementinggenerate_image()viaAsyncClient.generate()and returning thedecoded image bytes
OLLAMA_IMAGE_MODEL_IDsetting onOllamaSettings, matching the existing chat, text and embedding model IDs.OllamaTextToImagePromptExecutionSettingscarryingwidth,heightandsteps.connectors/ai/ollama/__init__.py.No new dependencies: the
ollamapackage SK already depends on exposesimageonGenerateResponse, andwidth,heightandstepsongenerate().Contribution Checklist