Skip to content

Commit a797744

Browse files
committed
fix: remote model pulling + ollama path after install
Model pulling: - Changed from CLI (ollama pull) to Ollama HTTP API (/api/pull). This works for both local AND remote Ollama — the pull runs on whatever machine Ollama is running on, not the local machine. - Pull buttons now send the correct Ollama URL (local or remote) - Status shows which URL the download is targeting Remote install fix: - Use /usr/local/bin/ollama for version check after install (PATH not refreshed in same SSH session) - Added sleep after service start for stability https://claude.ai/code/session_018kEJ1dG42MJkBYbrK68h79
1 parent 42bcb8f commit a797744

3 files changed

Lines changed: 29 additions & 15 deletions

File tree

clanker/setup/ollama.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ def install_ollama_remote(ssh_host: str) -> dict[str, Any]:
207207
*ssh_args,
208208
"curl -fsSL https://ollama.com/install.sh | sh && "
209209
"systemctl start ollama 2>/dev/null; "
210-
"ollama --version",
210+
"sleep 2; "
211+
"/usr/local/bin/ollama --version 2>/dev/null || ollama --version",
211212
],
212213
capture_output=True, text=True, timeout=300,
213214
)
@@ -229,17 +230,28 @@ def install_ollama_remote(ssh_host: str) -> dict[str, Any]:
229230
def pull_model(
230231
model: str, base_url: str = "http://localhost:11434"
231232
) -> dict[str, Any]:
232-
"""Pull a model via Ollama CLI (shows progress)."""
233+
"""Pull a model via Ollama API (works for both local and remote)."""
234+
url = base_url.rstrip("/")
233235
try:
234-
result = subprocess.run(
235-
["ollama", "pull", model],
236-
capture_output=True, text=True, timeout=600,
237-
)
238-
if result.returncode == 0:
239-
return {"ok": True, "message": f"Pulled {model}"}
240-
return {"ok": False, "message": result.stderr[:500]}
241-
except subprocess.TimeoutExpired:
242-
return {"ok": False, "message": f"Pull of {model} timed out"}
236+
# Use the Ollama API instead of CLI — works for remote too
237+
with httpx.Client(timeout=600.0) as client:
238+
resp = client.post(
239+
f"{url}/api/pull",
240+
json={"name": model, "stream": False},
241+
)
242+
if resp.status_code == 200:
243+
return {"ok": True, "message": f"Pulled {model}"}
244+
return {
245+
"ok": False,
246+
"message": f"Pull failed: HTTP {resp.status_code}",
247+
}
248+
except httpx.ReadTimeout:
249+
return {"ok": False, "message": f"Pull of {model} timed out (large download)"}
250+
except httpx.ConnectError:
251+
return {
252+
"ok": False,
253+
"message": f"Cannot connect to Ollama at {url}. Is it running?",
254+
}
243255
except Exception as exc:
244256
return {"ok": False, "message": str(exc)}
245257

clanker/setup/static/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,12 +942,13 @@ <h2>Setup Complete!</h2>
942942
}
943943

944944
async function pullModel(model) {
945-
setStatus('ollama-pull-status', 'loading', 'Downloading ' + model + ' (this may take a few minutes)...');
946-
const r = await api('/api/ollama/pull', {model: model});
945+
const url = getOllamaUrl();
946+
setStatus('ollama-pull-status', 'loading', 'Downloading ' + model + ' to ' + url + ' (this may take a few minutes)...');
947+
const r = await api('/api/ollama/pull', {model: model, base_url: url});
947948
if (r.ok) {
948949
setStatus('ollama-pull-status', 'ok', 'Downloaded ' + model);
949950
// Refresh model list
950-
const r2 = await api('/api/test/ollama', {base_url: getOllamaUrl()});
951+
const r2 = await api('/api/test/ollama', {base_url: url});
951952
if (r2.ok && r2.models) populateSelect('ollama-model', r2.models, model);
952953
} else {
953954
setStatus('ollama-pull-status', 'err', r.message);

clanker/setup/web.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ def _handle_ollama_pull(self, body: dict[str, Any]) -> None:
132132
from clanker.setup.ollama import pull_model
133133

134134
model = body.get("model", "llama3.2")
135-
self._json_response(pull_model(model))
135+
base_url = body.get("base_url", "http://localhost:11434")
136+
self._json_response(pull_model(model, base_url=base_url))
136137

137138
def _handle_ollama_optimize(self, body: dict[str, Any]) -> None:
138139
from clanker.setup.ollama import apply_systemd_env, get_optimization_advice

0 commit comments

Comments
 (0)