forked from AaronFeng753/Ollama-Model-Dumper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdate_ALL_Models.py
36 lines (29 loc) · 1.2 KB
/
Update_ALL_Models.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
31
32
33
34
35
36
# This Python script utilizes the pull command of ollama to simultaneously update all models downloaded from ollama.com
import subprocess
import re
import os
import shutil
def run_command(command):
"""
Executes a shell command and returns the output.
"""
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, text=True, creationflags=subprocess.CREATE_NO_WINDOW, encoding='utf-8')
# Capture the output and error
output_text, error_text = process.communicate()
# Trim the output text
return output_text.strip()
def process_models(model_names):
for model_name in model_names:
model_name = model_name.strip()
print(model_name)
parameters_command = f'ollama pull {model_name}'
subprocess.run(parameters_command, shell=True)
def extract_names(data):
lines = data.strip().split('\n')
names = [line.split()[0] for line in lines[1:]]
return ';;;'.join(names)
data = run_command("ollama list")
# Call the function and print the result
model_names_string = extract_names(data)
model_names = model_names_string.split(";;;")
process_models(model_names)