Skip to content

feat(backends): support Ollama adapter functions - #1634

Open
planetf1 wants to merge 8 commits into
generative-computing:mainfrom
planetf1:feat/take-over-pr-1622
Open

feat(backends): support Ollama adapter functions#1634
planetf1 wants to merge 8 commits into
generative-computing:mainfrom
planetf1:feat/take-over-pr-1622

Conversation

@planetf1

@planetf1 planetf1 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Pull Request

Issue

Supersedes #1622. Related: #1633.

Description

This takes over the Ollama adapter-function work originally proposed in #1622. The original implementation commit remains in this branch history. The takeover rebases the feature onto the current composed-adapter API and adds a reproducible test model built from pinned official Granite artefacts instead of depending on a user-published model.

  • Route catalogue adapter functions through composed ServerMediatedBinding registration.
  • Support cold ALoraRequirement routing for configured catalogue adapter models.
  • Preserve the selected bundled model in generation metadata and logs.
  • Build the official uncertainty aLoRA as GGUF in the Ollama test harness; ordinary local pytest reuses or creates the generated model.
  • Document the supported catalogue and custom-adapter workflows, including the local build prerequisite.

For one adapter function, use its bundled aLoRA tag for both model_id and the adapter route, with adapter_base_model_name set to the matching Hugging Face base-model directory. Before its invocation tokens appear, the bundle behaves as the base model and retains one Ollama model identity. Applications that map several adapter functions to separate Ollama tags cannot share a KV cache across those tags; multi-adapter, single-model serving remains a Granite Switch use case.

The broader server-mediated lifecycle and telemetry design remains tracked in #1633.

Testing

  • Unit tests added for request rewriting, model selection, cold requirement routing, and the optional dependency error.
  • Live Ollama e2e uses the generated model from pinned official Granite artefacts.
  • Qualitative acceptance test confirms the aLoRA bundle materially changes the base model's certainty score for a fixed request.
  • ruff, mypy, Markdown lint, shell syntax, and whitespace checks pass.
  • Full local fast suite is blocked by unrelated PyTorch Inductor/OpenMP compilation failures on macOS; CI will provide the authoritative Linux result.

Attribution

  • AI coding assistants used

Adding a new component, requirement, sampling strategy, or tool?

  • Component
  • Requirement
  • Sampling Strategy
  • Tool

NOTE: This PR supersedes an already acknowledged contribution in #1622.

aanokh and others added 2 commits September 7, 2026 16:01
Signed-off-by: aanokh <alexander.g.anokhin@gmail.com>
Assisted-by: Codex
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
@github-actions github-actions Bot added the enhancement New feature or request label Sep 8, 2026
@planetf1 planetf1 mentioned this pull request Sep 8, 2026
8 tasks
Assisted-by: Codex
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Assisted-by: Codex
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Assisted-by: Codex
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
@planetf1 planetf1 self-assigned this Sep 8, 2026
@planetf1
planetf1 marked this pull request as ready for review September 8, 2026 09:52
@planetf1
planetf1 requested a review from a team as a code owner September 8, 2026 09:52
Assisted-by: Codex
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>

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

Review of the Ollama bundled-adapter path. The uncertainty/aLoRA flow this PR tests looks correct, but the generalization to the other adapter functions has gaps, and three of them fail silently with a schema-valid score rather than raising. Details inline; openai.py already has the correct version of most of these.

Comment thread mellea/backends/ollama.py
Comment thread mellea/backends/ollama.py
Comment thread mellea/backends/ollama.py Outdated
Comment thread mellea/backends/ollama.py Outdated
Comment thread mellea/backends/ollama.py
Comment thread docs/examples/intrinsics/uncertainty_ollama.py Outdated
Comment thread .github/workflows/quality.yml
Comment thread test/scripts/run_tests_with_ollama_and_vllm.sh Outdated
Comment thread test/backends/test_ollama.py Outdated
…computing#1634)

Fixes 8 findings from psschwei's review plus AngeloDanducci's suggestion:

- Fold extra_body.documents into a message in _generate_from_intrinsic;
  Ollama's chat SDK has no extra_body passthrough, so answerability,
  citations, hallucination_detection, clarify_query, and
  find_context_attributions were sending zero documents.
- resolve_adapter now raises if name has no adapter_models entry, instead
  of registering successfully and letting generation silently fall back
  to the base model.
- resolve_adapter picks LoRA vs aLoRA from the catalog's adapter_types
  instead of hardcoding aLoRA; restricted context-attribution, citations,
  and hallucination_detection to LoRA-only (verified against the Hub).
- reroute_to_alora now follows a new default_to_constraint_checking_alora
  flag (default True), matching OpenAIBackend/LocalHFBackend, instead of
  only firing for ALoraRequirement.
- _generate_from_context now awaits do_generate_walk before the
  Requirement/Intrinsic dispatch, matching the other backends.
- Fix Path(__file__).parents[2] -> parents[3] in the example script.
- Constrain granite4.1:3b's context in CI before the adapter build step;
  only granite4.2:3b was constrained, so the new bundled tag inherited
  the unconstrained default and reintroduced the CI-stall risk.
- Fix export VAR="$(cmd)" masking command-substitution failures under
  set -e in the test runner script, the build script's own usage
  comment, and docs/docs/advanced/intrinsics.md.
- test_ollama.py's adapter-build fixture now skips on build failure
  instead of erroring.

Added regression tests for the resolve_adapter and document-forwarding
fixes; updated two existing unit tests that had encoded the old
(buggy) unconditional-resolve behaviour.

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>

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

There's a conflict, but otherwise LGTM

Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
@planetf1

Copy link
Copy Markdown
Contributor Author

Will leave ready to merge so @jakelorocco can review on his return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants