Skip to content

Commit 29a20aa

Browse files
author
Victor Goubet
committed
Check if ollama is running
1 parent 5f63f79 commit 29a20aa

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ configure-sage
5555

5656
After setting up, launch the script with admin rights. If no configuration is provided, the default configuration will be used:
5757

58+
5859
```sh
5960
launch-sage
6061
```
6162

63+
**Note**: Be sure to have **ollama running** if you intend to use local models
64+
6265
### Launch Options:
6366

6467
- `--streamlit <true or false>`: If `true`, the Streamlit interface will be used; otherwise, a shell interface will appear.

poetry.lock

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ duckduckgo-search = "^6.1.6"
1717
httpcore = "^1.0.5"
1818
httpx = "^0.27.0"
1919
openai = "^1.34.0"
20+
psutil = "^6.0.0"
2021
[build-system]
2122
requires = ["poetry-core"]
2223
build-backend = "poetry.core.masonry.api"

techsage/configure.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Optional
77

88
import click
9+
import psutil
910

1011
from techsage.utils.constants import APP_FOLDER, DEFAULT_CONFIG
1112

@@ -18,6 +19,23 @@ def create_app_folder() -> None:
1819
os.makedirs(f"{APP_FOLDER}/models", exist_ok=True)
1920

2021

22+
def check_ollama_running() -> None:
23+
"""
24+
Check if 'ollama' is currently running.
25+
26+
:raises RuntimeError: If 'ollama' is not running.
27+
"""
28+
try:
29+
for process in psutil.process_iter(["name"]):
30+
if process.info["name"].lower() == "ollama":
31+
print(" ✅ Ollama is running.")
32+
return
33+
raise RuntimeError("Ollama is not running.")
34+
except Exception as e:
35+
print(f" ❌ {str(e)}")
36+
sys.exit(1)
37+
38+
2139
def check_ollama_installed() -> None:
2240
"""
2341
Check if 'ollama' is installed.
@@ -43,14 +61,15 @@ def pull_model(model_name: str) -> None:
4361
"""
4462
try:
4563
output = None if VERBOSE else subprocess.DEVNULL
64+
print(" ⏳ Pulling model...")
4665
subprocess.check_call(
4766
["ollama", "pull", model_name],
4867
stdout=output,
4968
stderr=output,
5069
)
5170
print(" ✅ Base model is ready")
5271
except subprocess.CalledProcessError:
53-
print(f" ❌ Failed to pull model {model_name}, check if it exists and if ollama is launched")
72+
print(f" ❌ Failed to pull model {model_name}, check if it exists on ollama website")
5473
sys.exit(1)
5574

5675

@@ -175,6 +194,7 @@ def configure(
175194
create_app_folder()
176195
if local:
177196
check_ollama_installed()
197+
check_ollama_running()
178198
model_config_file_path = create_model_file(model, f"{APP_FOLDER}/models/")
179199
pull_model(model)
180200
crewai_model_name = create_model(f"{model}_crewai", model_config_file_path)

0 commit comments

Comments
 (0)