|
import subprocess
|
|
import time
|
|
import requests
|
|
|
|
def is_ollama_running():
|
|
try:
|
|
r = requests.get("http://localhost:11434")
|
|
return r.status_code == 200
|
|
except Exception:
|
|
return False
|
|
|
|
def start_ollama_model(model_name="llama3"):
|
|
print(f"π Starting Ollama model: {model_name}")
|
|
subprocess.Popen(["ollama", "run", model_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
print("β³ Waiting for Ollama to be ready...")
|
|
for _ in range(20):
|
|
if is_ollama_running():
|
|
print("β
Ollama is up!")
|
|
return True
|
|
time.sleep(0.5)
|
|
print("β Ollama failed to start or is not responding.")
|
|
return False |