-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathutils.py
34 lines (30 loc) · 1.21 KB
/
utils.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
import subprocess
def run_ollama_list_command():
try:
result = subprocess.run(['ollama', 'list'], capture_output=True, text=True)
if result.returncode == 0:
print(result.stdout)
else:
print(f"Error running 'ollama list': {result.stderr}")
return
except FileNotFoundError:
print("Error: 'ollama' command not found. Please make sure to download ollama from ollama.com")
return
except Exception as e:
print(f"An error occurred while running 'ollama list': {e}")
return
def get_ollama_models() -> list[str]:
try:
result = subprocess.run(['ollama', 'list'], capture_output=True, text=True)
if result.returncode != 0:
print(f"Error running 'ollama list': {result.stderr}")
return []
lines = result.stdout.splitlines()
models = [line.split()[0] for line in lines[1:] if line.strip()]
return models
except FileNotFoundError:
print("Error: 'ollama' command not found. Please make sure to download ollama from ollama.com")
return []
except Exception as e:
print(f"An error occurred while running 'ollama list': {e}")
return []