Skip to content

fix(ollama): preserve multimodal images - #17663

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
lntutor:fix/ollama-multimodal-images
Aug 20, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
lntutor:fix/ollama-multimodal-images

Conversation

@lntutor

@lntutor lntutor commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Convert multimodal text blocks into Ollama message content.
  • Attach image references through Ollama native images arrays for synchronous and streaming chat requests.
  • Strip data-URI headers while preserving raw base64 and URL image values.
  • Add regression coverage for both request paths.

Closes #17332

Verification

  • CGO_ENABLED=0 go test -count=1 ./internal/entity/models
  • CGO_ENABLED=0 go vet ./internal/entity/models
  • git diff --check

The repository build.sh --test wrapper could not run locally because the required office_oxide native library is not installed; it exits before compiling the package.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Ollama requests now map multimodal messages to combined text and image fields. Regular and streaming chat paths use the Ollama-specific builder. HTTP-server tests validate payload mapping and response handling.

Changes

Ollama multimodal chat

Layer / File(s) Summary
Build Ollama multimodal payloads
internal/entity/models/ollama.go
The Ollama request builder combines text content, extracts image data from supported inputs, preserves image order, and serves regular and streaming chat requests.
Validate regular and streaming chat flows
internal/entity/models/ollama_test.go
Tests validate stream mode, combined text, ordered images, regular responses, and streaming completion.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: haruko386

Sequence Diagram(s)

sequenceDiagram
  participant ChatWithMessages
  participant ChatStreamlyWithSender
  participant buildOllamaRequestBody
  participant OllamaHTTPServer
  ChatWithMessages->>buildOllamaRequestBody: multimodal messages
  ChatStreamlyWithSender->>buildOllamaRequestBody: multimodal messages
  buildOllamaRequestBody->>OllamaHTTPServer: text and ordered images
  OllamaHTTPServer-->>ChatWithMessages: chat response
  OllamaHTTPServer-->>ChatStreamlyWithSender: streaming response
Loading

Poem

A rabbit packs pictures with care,
With text and bright images there.
Ollama reads each piece,
Streams answers in peace,
While tests check the payloads are fair.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes preserve multimodal images in synchronous and streaming Ollama requests as required by issue #17332.
Out of Scope Changes check ✅ Passed The code and test changes are limited to Ollama multimodal image mapping and directly support issue #17332.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and concisely describes preserving multimodal images in the Ollama driver.
Description check ✅ Passed The description includes the required Summary section and clearly explains the changes, regression coverage, and verification steps.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/entity/models/ollama_test.go`:
- Around line 46-74: Keep test failures in the httptest handler goroutines by
replacing t.Fatalf with t.Errorf and returning after each failed precondition.
In assertOllamaMultimodalRequest, return after failed message or image structure
checks; in the synchronous handler at internal/entity/models/ollama_test.go
lines 81-83 and streaming handler at lines 109-111, log the decoding failure
with t.Errorf, send an error response, and return.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b5351df6-ecd0-4815-8d38-e9785bde30e7

📥 Commits

Reviewing files that changed from the base of the PR and between 776b937 and 156c52e.

📒 Files selected for processing (2)
  • internal/entity/models/ollama.go
  • internal/entity/models/ollama_test.go

Comment thread internal/entity/models/ollama_test.go Resolved
@JinHai-CN
JinHai-CN requested a review from Haruko386 July 31, 2026 15:56
@lntutor

lntutor commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Current head 8c23152 is mergeable. The earlier CodeRabbit finding was addressed on this exact head, the thread is resolved, and I do not see any remaining contributor-side follow-up. The visible current-head automation is the skipped sep-tests workflow plus a successful CodeRabbit pass, so this looks ready for maintainer review if that check state is expected for this path.

@Haruko386
Haruko386 marked this pull request as draft August 1, 2026 13:03
@Haruko386
Haruko386 marked this pull request as ready for review August 1, 2026 13:03
@Haruko386 Haruko386 added the ci Continue Integration label Aug 1, 2026
@lntutor

lntutor commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

The current-head sep-tests rerun has now completed successfully on 8c23152e8b61aa376e9ddcfe9053ff7f5105b2b0: preflight, Elasticsearch, and Infinity jobs are all green, alongside the successful CodeRabbit review. No contributor-side follow-up remains on this head.

@Haruko386 Haruko386 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thank you for your contribution

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 3, 2026
@Haruko386 Haruko386 removed the ci Continue Integration label Aug 3, 2026
@Haruko386
Haruko386 marked this pull request as draft August 3, 2026 02:29
@Haruko386
Haruko386 marked this pull request as ready for review August 3, 2026 02:29
@Haruko386 Haruko386 added the ci Continue Integration label Aug 3, 2026
@JinHai-CN
JinHai-CN merged commit f420e47 into infiniflow:main Aug 20, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Go] Ollama: multimodal/vision requests drop images (no vision support)

3 participants