-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdmodels.py
30 lines (27 loc) · 920 Bytes
/
updmodels.py
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
from ollama import Client, Model
import os, sys
import time
import subprocess
from rich import print as rprint
client = Client(host='http://localhost:11434')
models = client.list()
rprint(f'{len(models)} models')
try:
# Run ollama command and capture output
output, error = subprocess.run(['ollama'], capture_output=True)
except Exception as e:
rprint(f'{e}')
for model_data in models['models']:
try:
model = Model(name=model_data['name']) # Create a Model object for easier access
rprint(f'-> {model.name}')
res = model.delete()
rprint(f'delete: {res}')
rprint(f'downloading ', end='')
subprocess.run(['ollama', 'pull', model.name]) # Use subprocess to pull the model_name
for gen in model.pull(stream=True):
rprint(".", end='')
time.sleep(1)
except Exception as e:
rprint(f'exception: {e}')
rprint('done')