-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull_model.py
More file actions
39 lines (34 loc) · 1.56 KB
/
pull_model.py
File metadata and controls
39 lines (34 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import httpx
import json
import sys
def pull_model():
print("Attempting to pull llama3.1 via API (since CLI is unavailable)...")
url = "http://localhost:11434/api/pull"
data = {"name": "llama3.1", "stream": True}
try:
with httpx.stream("POST", url, json=data, timeout=None) as response:
if response.status_code != 200:
print(f"Failed to connect to Ollama API. Status: {response.status_code}")
return
for line in response.iter_lines():
if line:
try:
json_response = json.loads(line)
if "status" in json_response:
# Print status, avoiding too much spam
status = json_response['status']
completed = json_response.get('completed', 0)
total = json_response.get('total', 1)
if total > 0 and 'completed' in json_response:
percent = (completed / total) * 100
sys.stdout.write(f"\r{status}: {percent:.1f}%")
else:
sys.stdout.write(f"\r{status} ")
except Exception:
pass
print("\nPull complete! You can now run the main script.")
except Exception as e:
print(f"\nError: {e}")
print("Please ensure Ollama is running in the background.")
if __name__ == "__main__":
pull_model()