Skip to content

Commit d295778

Browse files
authored
Merge pull request #1725 from engelmi/add-temp-migration-for-ollama-nonnamespace
Added temporary migration routine for non-namespaced ollama models
2 parents 62d74a2 + 0575f11 commit d295778

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

ramalama/ollama.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
import shutil
34
import urllib.error
45
from typing import Optional
56

@@ -42,7 +43,7 @@ class OllamaRepository:
4243
def __init__(self, name: str, namespace: str = "library"):
4344
self.name = name
4445
self.namespace = namespace
45-
self.registry_head = f"{OllamaRepository.REGISTRY_URL}/{namespace}/{name}"
46+
self.registry_head = f"{OllamaRepository.REGISTRY_URL}/{self.namespace}/{self.name}"
4647
self.blob_url = f"{self.registry_head}/blobs"
4748
self.headers = {"Accept": OllamaRepository.ACCEPT}
4849

@@ -159,6 +160,20 @@ def pull(self, args):
159160
perror(f"Using cached ollama://{organization}/{name}:{tag} ...")
160161
return
161162

163+
#
164+
# Temporary migration routine to prevent pulling non-namespaced models again due to
165+
# https://github.com/containers/ramalama/pull/1721
166+
#
167+
_, _, org = super().extract_model_identifiers()
168+
if not org:
169+
o = Ollama(f"{self.model_name}/{self.model_name}", self._model_store_path)
170+
if o.exists():
171+
try:
172+
shutil.move(o.model_store.model_base_directory, self.model_store.model_base_directory)
173+
return
174+
except Exception:
175+
pass
176+
162177
ollama_repo = OllamaRepository(name, organization)
163178
manifest = ollama_repo.fetch_manifest(tag)
164179
ollama_cache_path = in_existing_cache(self.model_name, tag)

0 commit comments

Comments
 (0)