Skip to content

refactor: remove unused contentToText helper from Ollama driver - #17639

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
iridescentWen:refactor/remove-unused-ollama-contenttotext
Jul 31, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
iridescentWen:refactor/remove-unused-ollama-contenttotext

Conversation

@iridescentWen

Copy link
Copy Markdown
Contributor

Summary

contentToText in internal/entity/models/ollama.go has no callers anywhere in the repository. This PR deletes it.

Both OllamaModel.ChatWithMessages and OllamaModel.ChatStreamlyWithSender build their request payload through the shared buildRequestBody → buildChatMessages path (internal/entity/models/base_model.go:324, :373), which copies Message.Content straight into the payload. Neither path reaches the helper.

staticcheck flags it as U1000. There is no Go linter wired into CI, which is presumably why it went unnoticed.

1 file, -20 lines. Pure deletion — no behavior change, no signature change, no test touched. strings is still used elsewhere in the file, so no import change either.

How I verified it's dead

$ grep -rn "contentToText" --include="*.go" .
internal/entity/models/ollama.go:36:// contentToText extracts a plain-text string from a Message.Content value.
internal/entity/models/ollama.go:40:func contentToText(content interface{}) string {

Only the declaration and its own doc comment. I also swept the package for unreferenced package-private functions with comments and string literals stripped first (so a name appearing only in prose doesn't count as a use), and cross-checked against staticcheck; both agree.

Verification

$ gofmt -l internal/entity/models/ollama.go
(no output)

$ go vet ./internal/entity/models/
(no output)

$ go test ./internal/entity/models/
ok  	ragflow/internal/entity/models	4.358s

$ staticcheck -checks=U1000 ./internal/entity/models/     # before
18 findings, including:
internal/entity/models/ollama.go:40:6: func contentToText is unused (U1000)

$ staticcheck -checks=U1000 ./internal/entity/models/     # after
17 findings, ollama.go entry gone, nothing else changed

I re-ran the package tests with the parent version of the file checked back in (git checkout 36ae39b -- internal/entity/models/ollama.go) and they pass identically, so the ok above isn't an artifact of the edit.

One caveat about my local setup, stated plainly: bash build.sh --test (the command CLAUDE.md prescribes) does not run on this machine — the native static libs it fetches ship as native-linux-x86_64 and I'm on darwin/arm64. I built librag_tokenizer_c_api.a from internal/binding/cpp locally and ran the one package directly instead. internal/entity/models has no office_oxide / pdfium / pdf_oxide / import "C" references, so I believe the direct package run is equivalent here, but CI is the authority on that, not me. For the same reason I did not try to produce a repo-wide U1000 count — several packages don't compile locally without those libs, so any total I quoted would be wrong.

Notes for the reviewer

Scope. There are 17 other U1000 findings in this same package: unused *ModelInfo / *ModelCatalogItem response types in avian.go, cometapi.go, futurmix.go, gpustack.go, groq.go, longcat.go, n1n.go, perplexity.go, ppio.go, togetherai.go, model.go, plus a test helper in model_test.go. I deliberately kept this PR to the single symbol rather than bundling them, because the response structs in particular may be intentional documentation of provider API shapes — that's your call, not mine. Happy to open follow-ups, or a wider sweep, if you'd like. Wiring golangci-lint/staticcheck into CI would stop this class from accumulating, if that's of interest.

Relationship to #17332. I found this while looking into that issue, but this PR does not fix it and I'm not claiming it. #17332 reports that Ollama vision requests drop images and points at contentToText as the mechanism, citing it as "used at :98, :218". On current main those two lines are the buildRequestBody call and the SSE-parsing loop respectively — not calls to the helper. My clone is shallow (2 commits), so I can't tell you when or in which commit the call sites went away, only that they aren't there now.

That means the mechanism described in #17332 is stale, but the symptom may well be real: buildChatMessages emits only role/content, so there is still no Ollama-native images field on either path. I didn't want to bundle a speculative vision feature into a dead-code deletion, so #17332 deserves a separate look by someone who can test against a real multimodal Ollama model.


I used an AI assistant (Claude Code) to help find and verify this change. I reviewed every line and ran the checks above myself.

contentToText has no callers anywhere in the repository. Both
ChatWithMessages and ChatStreamlyWithSender build their payload through
the shared buildRequestBody -> buildChatMessages path, which passes
Message.Content straight through, so the helper is never reached.

staticcheck reports it as U1000; there is no Go linter wired into CI,
which is why it went unnoticed.

Verified: gofmt clean, go vet clean, go test ./internal/entity/models/
passes, and staticcheck -checks=U1000 on the package drops from 18 to 17
findings with the ollama.go entry gone.

Co-Authored-By: Claude Opus 5 <[email protected]>
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code labels Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1a2d38dd-3b56-4d9e-ba20-5c54d61a423d

📥 Commits

Reviewing files that changed from the base of the PR and between 36ae39b and 6bfd4e7.

📒 Files selected for processing (1)
  • internal/entity/models/ollama.go
💤 Files with no reviewable changes (1)
  • internal/entity/models/ollama.go

📝 Walkthrough

Walkthrough

The Ollama model implementation removes the private contentToText helper and its handling of string and multimodal message content.

Changes

Ollama content handling

Layer / File(s) Summary
Remove content conversion helper
internal/entity/models/ollama.go
The private contentToText helper was removed, including support for raw strings and OpenAI-style multimodal text arrays.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Poem

A rabbit found some code to spare,
And tucked the helper in its lair.
No text arrays hop through the gate,
The Ollama path is lighter in weight.
“Less to parse,” the rabbit sings,
While clean code nibbles greens.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states that the unused contentToText helper was removed from the Ollama driver.
Description check ✅ Passed The description explains the purpose, scope, verification steps, limitations, and non-goals of the change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@JinHai-CN JinHai-CN added the ci Continue Integration label Jul 31, 2026
@JinHai-CN
JinHai-CN merged commit 80b2334 into infiniflow:main Jul 31, 2026
9 checks passed
JinHai-CN pushed a commit that referenced this pull request Aug 12, 2026
Second ragflow PR (#17639 merged 2026-07-31). Docstrings only, no
behavior change.

---

🤖 Written with [Claude Code](https://claude.com/claude-code). Each site
was opened and read, and
each description was checked against the line that consumes the value.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration ☯️ refactor Pull request that refactor/refine code size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants