Skip to content

Add image generation model and update provider to support it#30

Merged
dkotter merged 12 commits into
Fueled:developfrom
milindmore22:feat/image-generation
Apr 21, 2026
Merged

Add image generation model and update provider to support it#30
dkotter merged 12 commits into
Fueled:developfrom
milindmore22:feat/image-generation

Conversation

@milindmore22
Copy link
Copy Markdown
Contributor

@milindmore22 milindmore22 commented Mar 24, 2026

Description of the Change

This PR adds support for Image generation model based on experimental feature of ollama please refer blog

This pull request adds support for image generation models to the Ollama provider integration. The most significant changes include the introduction of a new OllamaImageGenerationModel class, updates to model metadata detection to identify image generation capabilities, and enhancements to provider logic to instantiate the correct model type based on capabilities.

Image Generation Model Support:

  • Added a new OllamaImageGenerationModel class that implements image generation using the Ollama /api/generate endpoint, including prompt extraction, response parsing, and custom timeout handling.
  • Updated the provider logic in OllamaProvider to instantiate OllamaImageGenerationModel when a model supports image generation, based on its capabilities. [1] [2]

Model Metadata Detection:

  • Enhanced OllamaModelMetadataDirectory to detect image generation models by checking for the 'image' capability, and to construct appropriate ModelMetadata for such models with relevant options and output types. [1] [2] [3] [4]

Tooling and Static Analysis:

  • Updated phpstan.neon.dist to temporarily ignore the new OllamaImageGenerationModel.php file for static analysis, consistent with other files depending on unreleased WordPress core AI Client classes.

Warning

Supported only on MacOS (because experiments are only avilable on MacOS) Tested with x/flux2-klein and x/z-image-turbo

Screenshots

  1. Verify the model is ready by visiting Settings->Ollama Settings
Screenshot 2026-03-24 at 4 16 23 PM
  1. Visit Media->Generate Image, Enter prompt
Screenshot 2026-03-24 at 4 17 19 PM
  1. Generate Image
Screenshot 2026-03-24 at 4 21 28 PM
  1. Image in Media Gallery After saving it.
Screenshot 2026-03-24 at 4 25 41 PM

Closes #

How to test the Change

Download Model

ollama pull x/flux2-klein

Test Model

ollama run x/flux2-klein "a cat holding a sign that says hello world"

Test Curl

curl http://localhost:11434/api/generate -d '{
  "model": "x/flux2-klein",
  "prompt": "a cat holding a sign that says hello world",
  "stream": false
}'

Now you can try generate Image in WordPress

Changelog Entry

Added - support Image generation model

Credits

Props @milindmore22

Checklist:

Open WordPress Playground Preview

@dkotter dkotter added this to the 1.1.0 milestone Mar 24, 2026
@jeffpaul jeffpaul requested a review from dkotter March 27, 2026 15:50
@dkotter
Copy link
Copy Markdown
Collaborator

dkotter commented Mar 30, 2026

@milindmore22 Thanks for the PR. We use develop as our base branch and main for our release branch. Can you open this PR against develop?

@dkotter dkotter changed the base branch from main to develop March 31, 2026 18:53
Copy link
Copy Markdown
Collaborator

@dkotter dkotter left a comment

Choose a reason for hiding this comment

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

Few minor comments but otherwise this looks good to me and tests well!

Comment thread includes/Metadata/OllamaModelMetadataDirectory.php Outdated
Comment thread includes/Models/OllamaImageGenerationModel.php Outdated
Comment thread includes/Models/OllamaImageGenerationModel.php Outdated
Comment thread includes/Models/OllamaImageGenerationModel.php Outdated
Comment thread includes/Models/OllamaImageGenerationModel.php Outdated
Comment thread includes/Models/OllamaImageGenerationModel.php Outdated
Comment thread includes/Models/OllamaImageGenerationModel.php Outdated
Comment thread includes/Metadata/OllamaModelMetadataDirectory.php Outdated
@sentry
Copy link
Copy Markdown

sentry Bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 99.03846% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@4550eeb). Learn more about missing BASE report.

Files with missing lines Patch % Lines
includes/Metadata/OllamaModelMetadataDirectory.php 96.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop      #30   +/-   ##
==========================================
  Coverage           ?   61.68%           
  Complexity         ?      100           
==========================================
  Files              ?        7           
  Lines              ?      462           
  Branches           ?        0           
==========================================
  Hits               ?      285           
  Misses             ?      177           
  Partials           ?        0           
Flag Coverage Δ
unit 61.68% <99.03%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Collaborator

@dkotter dkotter left a comment

Choose a reason for hiding this comment

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

Would also be great to get unit tests added to cover these new changes

Copy link
Copy Markdown

@TylerB24890 TylerB24890 left a comment

Choose a reason for hiding this comment

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

All looks good to me!

Is there ever a case where the model would have the image capability but not be an image generation model? If not, I would propose updating the name of the isLikelyImageGenerationModel() method to isImageGenerationModel() -- less misleading and it matches the variable name it's being applied to

@milindmore22
Copy link
Copy Markdown
Contributor Author

milindmore22 commented Apr 10, 2026

Renamed isLikelyImageGenerationModel to isImageGenerationModel, but unable to test locally due to an Ollama environment error (failing to initialize MLX due to missing libmlxc.dylib). with latest version of Ollama, l need to resolve that environment issue before I can verify the change.

[Update]
ollama/ollama#15471

@jeffpaul jeffpaul requested a review from dkotter April 14, 2026 19:17
@dkotter
Copy link
Copy Markdown
Collaborator

dkotter commented Apr 14, 2026

Renamed isLikelyImageGenerationModel to isImageGenerationModel, but unable to test locally due to an Ollama environment error (failing to initialize MLX due to missing libmlxc.dylib). with latest version of Ollama, l need to resolve that environment issue before I can verify the change.

[Update] ollama/ollama#15471

Yeah, I'm getting the same error now. Going to hold on merging this until they get that resolved (hopefully soon)

@jeffpaul
Copy link
Copy Markdown
Collaborator

According to ollama/ollama#15433 the related PR ollama/ollama#15443 was in the v0.20.5 release so perhaps a local Ollama update will see this working again?

@dkotter
Copy link
Copy Markdown
Collaborator

dkotter commented Apr 14, 2026

According to ollama/ollama#15433 the related PR ollama/ollama#15443 was in the v0.20.5 release so perhaps a local Ollama update will see this working again?

Yeah, I pulled the latest version (0.27.0) and still seeing the same issue. Reading through that thread, sounds like most people are still having the same problem (and would be ideal if the issue was opened back up). There is a "fix" detailed on the thread for those running it through Homebrew but I have it installed as a normal package so wasn't able to test that.

@milindmore22
Copy link
Copy Markdown
Contributor Author

The issue has been resolved in the latest Ollama version 0.21.0, as reported in the pull request ollama/ollama#15588.
I have successfully tested the changes and they are working as expected at my end. 👍🏼

@dkotter dkotter merged commit ce147b8 into Fueled:develop Apr 21, 2026
13 checks passed
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.

4 participants