legal_rag / ollama_initial.py
allenlsl's picture
Upload 10 files
8c37f9b verified
raw
history blame contribute delete
737 Bytes
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