Skip to content

[Platform][Ollama] Add support for generation endpoint#1762

Open
Guikingone wants to merge 1 commit into
symfony:mainfrom
Guikingone:refactoring/ollama
Open

[Platform][Ollama] Add support for generation endpoint#1762
Guikingone wants to merge 1 commit into
symfony:mainfrom
Guikingone:refactoring/ollama

Conversation

@Guikingone

@Guikingone Guikingone commented Mar 13, 2026

Copy link
Copy Markdown
Contributor
Q A
Bug fix? no
New feature? yes
Docs? yes
Issues Suggested by @WebMamba on Slack
License MIT
  • Introduce support for /api/generate endpoint
  • Up PHPStan analysis to 10 (a few issues were detected)

@Guikingone Guikingone force-pushed the refactoring/ollama branch 2 times, most recently from f387b67 to 9d53fb5 Compare March 13, 2026 13:41
@Guikingone Guikingone marked this pull request as ready for review March 13, 2026 13:46
@carsonbot carsonbot added Feature New feature Platform Issues & PRs about the AI Platform component Status: Needs Review labels Mar 13, 2026
@chr-hertel

Copy link
Copy Markdown
Member

do the examples work for you?

that's what i'm currently getting after composer u && ../link:
image

@Guikingone

Copy link
Copy Markdown
Contributor Author

Was working perfectly yesterday, I'll take a look at it tomorrow

@Guikingone

Copy link
Copy Markdown
Contributor Author

Found the issue, the Capability::INPUT_TEXT is missing in ModelCatalog, IMHO, we should merge #1767 before this one, this way, we solve the issue for the hard-coded catalog and the generation capability.

@Guikingone

Copy link
Copy Markdown
Contributor Author

@chr-hertel Fixed, examples are working like a charm now thanks to the new INPUT_TEXT capability 😅

@Guikingone Guikingone force-pushed the refactoring/ollama branch 5 times, most recently from 30ef6c1 to f32de29 Compare March 29, 2026 17:00
@Guikingone Guikingone force-pushed the refactoring/ollama branch 3 times, most recently from 5fdce7f to 12b01f7 Compare April 5, 2026 15:16
Comment thread src/platform/CHANGELOG.md Outdated
Comment thread docs/components/platform/ollama.rst Outdated
Comment thread docs/components/platform/ollama.rst Outdated
Comment thread docs/components/platform/ollama.rst Outdated
Comment thread docs/components/platform/ollama.rst Outdated
Comment thread src/platform/src/Bridge/Ollama/Contract/AssistantMessageNormalizer.php Outdated
Comment thread src/platform/src/Bridge/Ollama/Tests/OllamaClientTest.php
Comment thread src/platform/src/Bridge/Ollama/composer.json Outdated
@Guikingone Guikingone requested a review from chr-hertel April 7, 2026 13:03
Comment thread src/platform/src/Bridge/Ollama/ModelCatalog.php
chr-hertel added a commit that referenced this pull request Apr 8, 2026
…kingone)

This PR was merged into the main branch.

Discussion
----------

[Platform][Ollama] Remove prefix for ScopingHttpClient

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Docs?         | yes
| Issues        | Discussed in #1762 (comment).
| License       | MIT

Commits
-------

7c1024a refactor(ollama): remove prefix for ScopingHttpClient
@Guikingone Guikingone force-pushed the refactoring/ollama branch from ea72901 to 7ebe685 Compare April 8, 2026 14:52
@Guikingone Guikingone requested a review from OskarStark April 8, 2026 15:25
@Guikingone Guikingone force-pushed the refactoring/ollama branch 2 times, most recently from 04b6699 to e56eb4a Compare April 9, 2026 09:04
@Guikingone

Copy link
Copy Markdown
Contributor Author

@chr-hertel I updated the PR following the one you merged, same for tests, ready for review when you have time 🙂

@Guikingone Guikingone force-pushed the refactoring/ollama branch 3 times, most recently from ff9a46f to a034898 Compare April 13, 2026 07:08
@Guikingone Guikingone force-pushed the refactoring/ollama branch 5 times, most recently from b1f52ec to 2476e26 Compare April 21, 2026 07:35
@OskarStark OskarStark requested a review from Copilot April 23, 2026 06:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the Platform’s Ollama bridge to support the /api/generate text-generation endpoint (including streaming), updates capability detection from the Ollama model catalog, and adds new documentation/examples while increasing PHPStan strictness for the bridge.

Changes:

  • Add /api/generate handling in the Ollama client and result converter (plus related tests).
  • Expand model capability mapping (including new Capability::OUTPUT_EMBEDDINGS) and adjust catalog tests.
  • Add Ollama-specific docs and runnable examples; raise Ollama bridge PHPStan level to 10.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
src/platform/src/Capability.php Adds OUTPUT_EMBEDDINGS capability; minor comment normalization.
src/platform/src/Bridge/Ollama/phpstan.dist.neon Raises PHPStan level from 6 to 10 for the Ollama bridge.
src/platform/src/Bridge/Ollama/TokenUsageExtractor.php Tightens token usage extraction to require integer counts.
src/platform/src/Bridge/Ollama/OllamaResultConverter.php Routes conversion based on endpoint URL; adds generate + improved streaming handling.
src/platform/src/Bridge/Ollama/OllamaClient.php Introduces generation requests and refactors chat/embed request payload construction.
src/platform/src/Bridge/Ollama/OllamaPayload.php New helper for distinguishing generation vs completion payload shapes.
src/platform/src/Bridge/Ollama/ModelCatalog.php Revises mapping from Ollama API “capabilities” to Platform Capability set.
src/platform/src/Bridge/Ollama/Tests/OllamaResultConverterTest.php Adds generation + endpoint-aware conversion tests; adjusts streaming/vector tests.
src/platform/src/Bridge/Ollama/Tests/OllamaClientTest.php Updates request URL expectations and adds generation coverage.
src/platform/src/Bridge/Ollama/Tests/ModelCatalogTest.php Updates/expands expected capabilities and renames the test class.
src/platform/src/Bridge/Ollama/CHANGELOG.md Documents /api/generate support under 0.9.
examples/ollama/text-generation.php New basic text generation example.
examples/ollama/text-generation-as-stream.php New streaming text generation example.
examples/ollama/text-generation-structured-output-math.php New structured output example for generation.
docs/components/platform/ollama.rst New end-user documentation page for the Ollama bridge.

Comment thread src/platform/src/Bridge/Ollama/OllamaClient.php
Comment thread src/platform/src/Bridge/Ollama/ModelCatalog.php
Comment thread docs/components/platform/ollama.rst Outdated
Comment thread docs/components/platform/ollama.rst Outdated
Comment thread docs/components/platform/ollama.rst Outdated
Comment thread src/platform/src/Bridge/Ollama/OllamaClient.php Outdated
Comment thread src/platform/src/Bridge/Ollama/ModelCatalog.php Outdated
Comment thread docs/components/platform/ollama.rst Outdated
Comment thread docs/components/platform/ollama.rst Outdated
Comment thread src/platform/src/Bridge/Ollama/OllamaPayload.php Outdated
@Guikingone

Copy link
Copy Markdown
Contributor Author

@OskarStark Fixes applied on Copilot review, totally forgot about the new public API for the platform, sorry 😅

taffy-41-split-app Bot pushed a commit to taffy41/ai-platform that referenced this pull request Apr 28, 2026
…kingone)

This PR was merged into the main branch.

Discussion
----------

[Platform][Ollama] Remove prefix for ScopingHttpClient

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Docs?         | yes
| Issues        | Discussed in symfony/ai#1762 (comment).
| License       | MIT

Commits
-------

7c1024a0 refactor(ollama): remove prefix for ScopingHttpClient
@Guikingone Guikingone force-pushed the refactoring/ollama branch from 2cb53f5 to fa47ad7 Compare May 5, 2026 13:27
@chr-hertel

Copy link
Copy Markdown
Member

This really got me thinking ... do we want to provide all kind of endpoint per provider/bridge? yes, i agree nowadays on that :D

with all bridges, and especially ModelClient implementations, that gets messy tho. i was tinkering around a bit with claude about that topic, and we ended up with #2029

don't think all the naming is great, and the PR needs slicing down, but was curious what you think about that?

@Guikingone

Guikingone commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Hi @chr-hertel

#2029 make sense, especially the "per endpoint split" plus it could open the door for a better separation between HTTP handling and websockets (huge part for certain bridges), it could also ease the maintenance of "per endpoint" bugs / improvements, a huge win for future bridges / features IMHO 🤔

@Guikingone Guikingone force-pushed the refactoring/ollama branch from fa47ad7 to ad18673 Compare May 16, 2026 09:57
@Guikingone

Copy link
Copy Markdown
Contributor Author

@chr-hertel Saw that 0.9 is out, don't know if we should wait for #2029 for this one, if so, let me know once it's merged, I'd rework this branch to support the new architecture 🙂

@Guikingone Guikingone force-pushed the refactoring/ollama branch from ad18673 to 55ada32 Compare June 8, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New feature Platform Issues & PRs about the AI Platform component Status: Needs Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants