AI-Life-Coach-Streamlit2 / quick_system_test.py
rdune71's picture
Fix session management serialization and update Ollama URL
196ee96
import sys
from pathlib import Path
# Add project root to path
project_root = Path(__file__).parent
sys.path.append(str(project_root))
from core.redis_client import redis_client
import requests
import json
def quick_test():
"""Quick test of core components"""
print("=== Quick System Test ===")
print()
# Test 1: Redis
print("1. Testing Redis...")
try:
client = redis_client.get_client()
if client and client.ping():
print("βœ… Redis connection successful")
# Test data storage
test_data = {
"name": "test_user",
"messages": json.dumps([]), # Convert list to string
"created_at": "2025-09-08"
}
result = client.hset("test:user:123", mapping=test_data)
retrieved = client.hgetall("test:user:123")
client.delete("test:user:123")
if retrieved:
print("βœ… Redis data storage working")
else:
print("❌ Redis data storage failed")
else:
print("❌ Redis connection failed")
except Exception as e:
print(f"❌ Redis test failed: {e}")
print()
# Test 2: Ollama
print("2. Testing Ollama...")
try:
ollama_url = "https://7bcc180dffd1.ngrok-free.app"
headers = {
"ngrok-skip-browser-warning": "true",
"User-Agent": "AI-Life-Coach-Test"
}
# Test model listing
response = requests.get(f"{ollama_url}/api/tags", headers=headers, timeout=10)
if response.status_code == 200:
print("βœ… Ollama model listing successful")
# Test chat
payload = {
"model": "mistral:latest",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": False
}
chat_response = requests.post(
f"{ollama_url}/api/chat",
headers=headers,
json=payload,
timeout=30
)
if chat_response.status_code == 200:
print("βœ… Ollama chat successful")
else:
print(f"❌ Ollama chat failed: {chat_response.status_code}")
else:
print(f"❌ Ollama connection failed: {response.status_code}")
except Exception as e:
print(f"❌ Ollama test failed: {e}")
print()
print("πŸŽ‰ Quick test completed!")
if __name__ == "__main__":
quick_test()