feat(ollama): detect and advertise vision capability with live E2E#1892
Merged
Conversation
Ollama's image wire path (OllamaImagesField) has always existed, but the backend never advertised it and nothing tested it. Detect the per-model vision capability from /api/show's capabilities: ["vision", ...] list at load time, surface it via OllamaBackend.isVisionModel, and route it through a new central BackendVisionCapability.ollamaSupportsImageInput(probedVision:) gate so capabilities.supportsVision reflects reality. Wire a real multimodal request path: OllamaBackend now conforms to StructuredHistoryReceiver and lifts MessagePart.image payloads onto Ollama's message-level images: [base64] field (snapshot-and-cleared like toolAwareHistory; text-only turns still use the existing plain-string path, preserving wire-shape assertions). Tests: deterministic OllamaManifestProbeTests for vision detection (mocked /api/show, no live server) + BackendVisionCapability unit coverage, and a live OllamaVisionE2ETests that generates a solid-color PNG in code, attaches it, and asserts grounded output from a real vision model (qwen2.5vl/moondream/llava), auto-skipping when none is installed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Closes the #1 vision gap: the Ollama backend has always had the image wire path (
OllamaImagesField), but it never advertisedsupportsVisionand nothing tested image input. This detects, advertises, wires, and tests it end-to-end.Changes
OllamaModelProbereads the per-modelvisionflag from/api/show'scapabilities: ["vision", ...]list (qwen2.5vl / moondream / llava), alongside the existingthinkingdetection. No template fallback — vision is advertised-only.OllamaBackend.isVisionModel(state-lock-guarded, mirrors_isThinkingModel) drivescapabilities.supportsVision, routed through a new centralBackendVisionCapability.ollamaSupportsImageInput(probedVision:)gate (matches the cloud families' pattern).OllamaBackendnow conforms toStructuredHistoryReceiverand liftsMessagePart.imagepayloads onto Ollama's message-levelimages: [base64]field. Snapshot-and-cleared liketoolAwareHistory; text-only turns keep the existing plain-string path, preserving every existing wire-shape assertion.Tests
OllamaManifestProbeTests(+91): deterministic vision detection via mocked/api/show— no live server.BackendVisionCapabilityTests(+11): gate unit coverage.OllamaVisionE2ETests(new): live E2E — generates a solid-color PNG in code, attaches it viasetStructuredHistory, asserts grounded output from a real vision model. Cross-platform-gated (CoreGraphics/ImageIO); auto-skips when no vision model is installed.Verification
swift build --build-tests— exit 0 (clean).swift test --filter OllamaVisionE2ETestsagainst local Ollama — orchestrator to run before marking ready.Relates to the multimodal token-accounting gap (#1885): images now flow through a real path that the token estimator must account for.
Draft — orchestrator will run live verification + watch CI before merge. One of a 3-PR set (#1890 tool discovery + docs, #1891 cancellation E2E).