File size: 4,354 Bytes
66dbebd |
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# test_setup.py
"""
Test script to verify installation and basic functionality
"""
def test_imports():
"""Test all critical imports"""
print("Testing imports...")
try:
import gradio
print(f"β Gradio version: {gradio.__version__}")
import transformers
print(f"β Transformers version: {transformers.__version__}")
import torch
print(f"β PyTorch version: {torch.__version__}")
import faiss
print("β FAISS imported successfully")
import numpy as np
print(f"β NumPy version: {np.__version__}")
import pandas as pd
print(f"β Pandas version: {pd.__version__}")
print("\nβ All imports successful!")
return True
except ImportError as e:
print(f"β Import failed: {e}")
return False
def test_embedding_model():
"""Test embedding model loading"""
print("\nTesting embedding model...")
try:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
print("β Embedding model loaded successfully")
# Test embedding generation
test_text = "This is a test sentence."
embedding = model.encode(test_text)
print(f"β Embedding generated: shape {embedding.shape}")
return True
except Exception as e:
print(f"β Embedding model test failed: {e}")
return False
def test_llm_router():
"""Test LLM router initialization"""
print("\nTesting LLM Router...")
try:
from llm_router import LLMRouter
import os
hf_token = os.getenv("HF_TOKEN", "")
router = LLMRouter(hf_token)
print("β LLM Router initialized successfully")
return True
except Exception as e:
print(f"β LLM Router test failed: {e}")
return False
def test_context_manager():
"""Test context manager initialization"""
print("\nTesting Context Manager...")
try:
from context_manager import EfficientContextManager
cm = EfficientContextManager()
print("β Context Manager initialized successfully")
return True
except Exception as e:
print(f"β Context Manager test failed: {e}")
return False
def test_cache():
"""Test cache implementation"""
print("\nTesting Cache...")
try:
from cache_implementation import SessionCache
cache = SessionCache()
# Test basic operations
cache.set("test_session", {"data": "test"}, ttl=3600)
result = cache.get("test_session")
if result is not None:
print("β Cache operations working correctly")
return True
else:
print("β Cache retrieval failed")
return False
except Exception as e:
print(f"β Cache test failed: {e}")
return False
def test_config():
"""Test configuration loading"""
print("\nTesting Configuration...")
try:
from config import settings
print(f"β Default model: {settings.default_model}")
print(f"β Embedding model: {settings.embedding_model}")
print(f"β Max workers: {settings.max_workers}")
print(f"β Cache TTL: {settings.cache_ttl}")
return True
except Exception as e:
print(f"β Configuration test failed: {e}")
return False
def run_all_tests():
"""Run all tests"""
print("=" * 50)
print("Running Setup Tests")
print("=" * 50)
tests = [
test_imports,
test_embedding_model,
test_llm_router,
test_context_manager,
test_cache,
test_config
]
results = []
for test in tests:
try:
result = test()
results.append(result)
except Exception as e:
print(f"β Test crashed: {e}")
results.append(False)
print("\n" + "=" * 50)
print(f"Test Results: {sum(results)}/{len(results)} passed")
print("=" * 50)
if all(results):
print("\nβ All tests passed!")
return 0
else:
print("\nβ Some tests failed")
return 1
if __name__ == "__main__":
exit(run_all_tests())
|