Repository navigation
fix(ollama): preserve native API base URL in OllamaCV - #17013
Conversation
OllamaCV.__init__ passed the configured base_url through ensure_v1(),
which forces a trailing /v1 segment. That URL is then handed to the
official ollama-python Client, which targets Ollama's native REST API
(e.g. POST {host}/api/generate, POST {host}/api/chat) rather than an
OpenAI-compatible /v1 surface. With /v1 already baked into the host,
every request lands on {base_url}/v1/api/generate and Ollama returns
404, since that native API is not published there.
ensure_v1() exists for the OpenAI-compatible SDK clients used by the
other providers in this file (OpenAI, Azure, xAI, etc.), not for the
ollama-python client. Applying it to OllamaCV mixes the two protocols.
Symptom observed on a real deployment: every dataflow Parser step that
sends an image to an Ollama VLM (PDF/DOCX/etc. with 'Disable vision
model' off) got '**ERROR**: 404 page not found (status code: 404)'
back from describe()/describe_with_prompt(), and that literal error
string was ingested as chunk text alongside the real content.
Fix: use the base_url as configured (only strip a trailing slash),
matching how the ollama-python README documents Client(host=...).
Verified against a live RAGFlow + Ollama deployment: before the fix,
Ollama's access log showed repeated 404s on POST /v1/api/generate;
after patching this file into the running container and restarting,
the same dataflow run produced POST /api/generate requests returning
200 OK.
Drop the redundant `or ""` fallback: base_url is a required kwarg for
this provider, so coercing a missing/None value to an empty string
only masks a configuration error instead of surfacing it. Plain
.rstrip("/") matches how the other providers in this file normalize
their base_url.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthrough
ChangesOllama URL normalization
Estimated code review effort: 1 (Trivial) | ~2 minutes Merge Risk: ⚪ Minimal · up to This is a localized URL-handling fix for Ollama vision requests, and no actionable merge-blocking risk remains beyond normal checks and review. Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description clearly explains the problem, impact, fix, and testing results. It does not use the template's exact "### Summary" heading, but it provides the required summary information and is otherwise complete.
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
rag/llm/cv_model.py (1)
735-735: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd a focused regression test for the normalized Ollama host.
Assert that a base URL such as
http://localhost:11434/is passed toollama.Clientashttp://localhost:11434, and that no/v1segment is introduced. The official client builds native requests such as/api/generateand/api/chatrelative to this host. (raw.githubusercontent.com)As per coding guidelines, “Preserve valid behavior with focused tests.”
🤖 Prompt for 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. In `@rag/llm/cv_model.py` at line 735, Add a focused regression test for the initialization path that assigns self.base_url, passing a trailing-slash Ollama URL and asserting ollama.Client receives the slash-trimmed host without any /v1 suffix. Verify the existing native endpoint behavior remains based on this normalized host.Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@rag/llm/cv_model.py`:
- Line 735: Add a focused regression test for the initialization path that
assigns self.base_url, passing a trailing-slash Ollama URL and asserting
ollama.Client receives the slash-trimmed host without any /v1 suffix. Verify the
existing native endpoint behavior remains based on this normalized host.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a043bd7e-15bd-4640-9dc1-dc32bee73100
📒 Files selected for processing (1)
rag/llm/cv_model.py
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17013 +/- ##
==========================================
- Coverage 39.25% 39.07% -0.19%
==========================================
Files 54 54
Lines 14911 14911
Branches 117 117
==========================================
- Hits 5854 5827 -27
- Misses 9045 9058 +13
- Partials 12 26 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What
OllamaCV.__init__normalizesbase_urlwithensure_v1(), which forces a trailing/v1onto the URL. That's correct for the OpenAI-compatible SDK clients used by most other providers incv_model.py, butOllamaCVdoesn't use one — it hands the URL straight to the officialollama.Client, which targets Ollama's native REST API ({host}/api/generate,{host}/api/chat, ...), not an OpenAI-compatible/v1surface.With
/v1already baked intohost, every request lands on{base_url}/v1/api/generateand Ollama returns 404, since that path doesn't exist.Impact
Any dataflow Parser step that sends an image to an Ollama vision model (PDF/DOCX/Image/etc. with "Disable vision model" off) gets back
**ERROR**: 404 page not found (status code: 404)fromdescribe()/describe_with_prompt()/async_chat()/async_chat_streamly(). Because those methods return the error text as the "description" instead of raising, the literal error string gets ingested as chunk content alongside real document text.Fix
Use
base_urlas configured, only stripping a trailing slash — matching how theollama-pythonREADME documentsClient(host=...).Testing
Verified against a live RAGFlow + Ollama deployment (Ollama configured with a valid,
/v1-free base URL and a vision-capable model):404s onPOST /v1/api/generatefor every vision call made by a dataflow Parser step; the OCR/description output for each figure contained the literal**ERROR**: 404 page not found (status code: 404)string.POST /api/generaterequests returning200 OK, and the error string no longer appeared in the parsed output.No automated test is included; this is a one-line behavioral fix to a URL a real backend is sensitive to, not something a mock would catch. Happy to add a unit test around
OllamaCV.__init__(asserting theClientis constructed with the un-suffixed host) if useful.