-
Notifications
You must be signed in to change notification settings - Fork 153
feat(backends): support Ollama adapter functions #1634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
planetf1
wants to merge
9
commits into
generative-computing:main
Choose a base branch
from
planetf1:feat/take-over-pr-1622
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7cbb9fb
feat: alora adapters for ollama
aanokh 9427b4f
feat(backends): support Ollama adapter functions
planetf1 aec57f9
docs: explain Ollama adapter cache trade-off
planetf1 cd2a2b0
fix(backends): support bundled Ollama adapter models
planetf1 8d2d572
fix: harden Ollama adapter provisioning
planetf1 7c3d494
test: provision Ollama adapter before pytest
planetf1 6fae19a
fix(backends): address Ollama adapter review findings (PR #1634)
planetf1 f9cf9b0
Merge remote-tracking branch 'upstream/main' into pr-1634
planetf1 203da8c
fix(backends): address second review round on Ollama adapter functions
planetf1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # pytest: e2e, ollama | ||
|
|
||
| """Example usage of the uncertainty/certainty intrinsic with Ollama. | ||
|
|
||
| Evaluates how certain the model is about its response to a user question. | ||
| The context should contain a user question followed by an assistant answer. | ||
|
|
||
| Ollama bundles one adapter per model. For this single-adapter example, the | ||
| uncertainty aLoRA tag is used for normal chat and the certainty helper, so | ||
| Ollama can retain one model identity. | ||
|
|
||
| Requires `mellea[switch]` to download the adapter's `io.yaml`. | ||
|
|
||
| To run this script from the root of the Mellea source tree, use the command: | ||
| ``` | ||
| uv run python docs/examples/intrinsics/uncertainty_ollama.py | ||
| ``` | ||
| """ | ||
|
|
||
| import os | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| from mellea import start_backend | ||
| from mellea.stdlib import functional as mfuncs | ||
| from mellea.stdlib.components.intrinsic import core | ||
|
|
||
| adapter_model = os.environ.get("MELLEA_OLLAMA_UNCERTAINTY_MODEL") | ||
| if adapter_model is None: | ||
| builder = ( | ||
| Path(__file__).parents[3] / "test/scripts/build_ollama_uncertainty_adapter.sh" | ||
| ) | ||
| adapter_model = subprocess.run( | ||
| [builder], check=True, stdout=subprocess.PIPE, text=True | ||
| ).stdout.strip() | ||
|
|
||
| ctx, backend = start_backend( | ||
| "ollama", | ||
| # Before its invocation tokens, this bundled aLoRA behaves as the base model. | ||
| model_id=adapter_model, | ||
| # The bundled tag cannot identify the Hugging Face adapter directory itself. | ||
| adapter_base_model_name="granite-4.1-3b", | ||
| context_type="chat", | ||
| # The certainty helper uses the same model identity. | ||
| adapter_models={"uncertainty": adapter_model}, | ||
| ) | ||
|
|
||
| # Add the exchange whose answer the adapter will score. | ||
| response, ctx = mfuncs.chat("What is 2 + 2?", ctx, backend) # type: ignore | ||
| print(f"Response: {response.content}") | ||
|
|
||
| # This call uses the mapped bundled adapter model, not the normal chat model. | ||
| result = core.check_certainty(ctx, backend) # type: ignore | ||
| print(f"Certainty score: {result}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.