aiagent / init_ollama.py
jdewitte's picture
Fix call issue
5cc5bf3
Raw
History Blame Contribute Delete
1.12 kB
#!/usr/bin/env python3
"""
Initialize Ollama with a lightweight model for function calling
"""
import subprocess
import time
import logging
import ollama
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def init_ollama():
"""Initialize Ollama and pull a lightweight model"""
try:
# Start Ollama service in background
logger.info("Starting Ollama service...")
subprocess.Popen(['ollama', 'serve'],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
# Wait for service to start
time.sleep(5)
# Pull a lightweight model - llama3.2:1b is very small (~1GB)
logger.info("Pulling llama3.2:1b model (lightweight, ~1GB)...")
subprocess.run(['ollama', 'pull', 'llama3.2:1b'], check=True)
logger.info("✅ Ollama initialized successfully with llama3.2:1b")
return True
except Exception as e:
logger.error(f"❌ Failed to initialize Ollama: {e}")
return False
if __name__ == "__main__":
init_ollama()