Skip to content

refactor(go-models): harden Ollama ListModels and route through ParseListModel (#15853) - #15955

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
hunnyboy1217:feat/go-listmodels-ollama-15853
Jun 17, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
hunnyboy1217:feat/go-listmodels-ollama-15853

Conversation

@hunnyboy1217

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Part of #15853 (provider model-list refactor).

Refactors Ollama ListModels onto the shared ParseListModel pattern and fixes two correctness issues:

  • Endpoint: switch the models suffix from api/ps (only currently-running models) to api/tags (all installed models) — the latter is what a model picker should show.
  • Parsing: Ollama returns {"models":[{"name","model"}]}, a non-OpenAI shape. Decode it into a typed struct, map the names into ModelList, then enrich through ParseListModel. This removes the previous unchecked type assertions (result["models"].([]interface{}) / .(map[string]interface{}) / .(string)) that panicked when the body was missing the models array or any field, and adds a fallback to the model field when name is blank.
  • Drops the no-op GET request body and a dead base-URL reassignment.

Drive-by fix

Shared gitee_test.go DSModelList -> ModelList compile fix (renamed in #15900) so the models test package builds; auto-resolves against the sibling #15853 PRs.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • Refactoring

How has this been tested?

  • go build ./internal/entity/models/... — clean
  • go vet ./internal/entity/models/... — clean
  • New httptest unit tests: happy path (/api/tags), model-field fallback + blank-name skipping, HTTP error, missing-base-URL guard. Non-network guard test passes locally; httptest cases run in CI.

…ListModel (infiniflow#15853)

- Point the Ollama models endpoint at /api/tags (all installed models) instead
  of /api/ps (only currently-running models), which is what a model picker
  needs.
- Decode the Ollama {"models":[{"name","model"}]} shape into a typed struct,
  map names into ModelList, and enrich through the shared ParseListModel helper
  (issue infiniflow#15853). This removes the previous unchecked type assertions
  (result["models"].([]interface{}) etc.) that panicked on a missing or
  malformed body, and falls back to the "model" field when "name" is blank.
- Drop the pointless GET request body and the dead base-URL reassignment.
- Add unit tests (httptest) covering the happy path, the model-field fallback,
  HTTP errors, and the missing-base-URL guard.

Also includes the shared gitee_test.go DSModelList->ModelList compile fix
(infiniflow#15900 rename) so the models test package builds; it auto-resolves against the
sibling infiniflow#15853 PRs. go build and go vet are clean.
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code 🐞 bug Something isn't working, pull request that fix bug. labels Jun 11, 2026
@coderabbitai

coderabbitai Bot commented Jun 11, 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

Run ID: dc750313-c8b9-4830-ae7b-028da855844b

📥 Commits

Reviewing files that changed from the base of the PR and between bde2b1f and 9ec3ad3.

📒 Files selected for processing (4)
  • conf/models/ollama.json
  • internal/entity/models/gitee_test.go
  • internal/entity/models/ollama.go
  • internal/entity/models/ollama_test.go

📝 Walkthrough

Walkthrough

This PR updates the Ollama model listing implementation to use the correct /api/tags endpoint with typed response parsing. Configuration, test alignment, core logic, and test coverage are coordinated to migrate away from untyped map assertions and align the response contract across model providers.

Changes

Ollama /api/tags Migration

Layer / File(s) Summary
Configuration and response contract alignment
conf/models/ollama.json, internal/entity/models/gitee_test.go
Ollama endpoint configuration updates from api/ps to api/tags. Gitee model test response type aligns from DSModelList to ModelList, establishing the shared contract.
Ollama ListModels typed implementation and test coverage
internal/entity/models/ollama.go, internal/entity/models/ollama_test.go
ListModels refactors from untyped map[string]interface{} assertions to typed struct decoding of /api/tags response. Field normalization derives model ID from name with fallback to model, skips empty entries, assembles ModelList, and returns via shared ParseListModel helper. Test coverage validates correct GET request path, response parsing with name/model fallback, blank-entry skipping, HTTP error rejection, and required configuration validation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • infiniflow/ragflow#15885: Updates Gitee ListModels test metadata, directly related to the gitee_test.go response type alignment in this PR.

Suggested labels

☯️ refactor, size:M

Poem

🐰 From api/ps to api/tags, the models now flow,
Typed and gentle through the rabbit's code below,
No more map assertions cause a panic fright,
Each name falls back to model—parsing done right,
Tests hop through endpoints, errors caught with care! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main purpose: refactoring Ollama ListModels to use the shared ParseListModel pattern while hardening it, with reference to the related issue #15853.
Description check ✅ Passed The description comprehensively addresses all required template sections: clearly explains the problem being solved, explicitly marks the change types (Bug Fix and Refactoring), and details testing methodology.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

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

Comment thread conf/models/ollama.json

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.

what this for?

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

@hunnyboy1217 please show your output in RAGFlow CLI for your code tests

@Haruko386 Haruko386 removed 🐞 bug Something isn't working, pull request that fix bug. ☯️ refactor Pull request that refactor/refine code labels Jun 12, 2026

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

@hunnyboy1217 LGTM
It would be better if you could provider your test output in RAGFlow CLI

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 16, 2026
@Haruko386 Haruko386 added the ci Continue Integration label Jun 16, 2026
@Haruko386
Haruko386 marked this pull request as draft June 16, 2026 09:28
@Haruko386
Haruko386 marked this pull request as ready for review June 16, 2026 09:28
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (a15e667) to head (62699da).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15955   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit e178c81 into infiniflow:main Jun 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants