File size: 2,639 Bytes
196ee96 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
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()
|