File size: 737 Bytes
8c37f9b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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): # wait up to ~10 seconds
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 |