Skip to content

Commit 87b5e5f

Browse files
committed
Enhance Ollama cache lookup
- Respect OLLAMA_MODELS environment variable for cache paths - Include organization in Ollama cache path resolution Signed-off-by: Roberto Majadas <[email protected]>
1 parent 33f5e9f commit 87b5e5f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ramalama/transports/ollama.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@
1111
from ramalama.transports.base import Transport
1212

1313

14-
def in_existing_cache(model_name, model_tag):
14+
def in_existing_cache(organization, model_name, model_tag):
1515
if not available("ollama"):
1616
return None
1717
default_ollama_caches = [
1818
os.path.expanduser('~/.ollama/models'),
1919
'/usr/share/ollama/.ollama/models',
2020
]
21+
if ollama_models_env := os.environ.get("OLLAMA_MODELS"):
22+
default_ollama_caches.insert(0, ollama_models_env)
2123

2224
for cache_dir in default_ollama_caches:
23-
manifest_path = os.path.join(cache_dir, 'manifests', 'registry.ollama.ai', model_name, model_tag)
25+
manifest_path = os.path.join(cache_dir, 'manifests', 'registry.ollama.ai', organization, model_name, model_tag)
2426
if os.access(manifest_path, os.R_OK):
2527
with open(manifest_path, 'r') as file:
2628
manifest_data = json.load(file)
@@ -180,7 +182,7 @@ def pull(self, args) -> None:
180182

181183
ollama_repo = OllamaRepository(name, organization)
182184
manifest = ollama_repo.fetch_manifest(tag)
183-
ollama_cache_path = in_existing_cache(self.model_name, tag)
185+
ollama_cache_path = in_existing_cache(organization, self.model_name, tag)
184186
is_model_in_ollama_cache = ollama_cache_path is not None
185187
files: list[SnapshotFile] = ollama_repo.get_file_list(tag, cached_files, is_model_in_ollama_cache)
186188

0 commit comments

Comments
 (0)