-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_system.py
More file actions
257 lines (203 loc) · 7.77 KB
/
test_system.py
File metadata and controls
257 lines (203 loc) · 7.77 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/usr/bin/env python3
"""
Test script for Ariv system
Tests basic functionality without requiring models
"""
import sys
import os
from pathlib import Path
# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent))
def test_imports():
"""Test that all modules can be imported"""
print("🧪 Testing imports...")
try:
from core.orchestrator import JugaadOrchestrator
from core.trv_pipeline import TRVPipeline
from core.vram_manager import VRAMManager, MemoryStats
from tools.registry import ToolRegistry
from config import get_model_paths, get_supported_languages, INDIAN_LANGUAGES_22
print("✅ All imports successful")
return True
except Exception as e:
print(f"❌ Import failed: {e}")
import traceback
traceback.print_exc()
return False
def test_config():
"""Test configuration loading"""
print("\n🧪 Testing configuration...")
try:
from config import INDIAN_LANGUAGES_22, MODEL_CONFIG, PIPELINE_CONFIG
# Test language count
lang_count = len(INDIAN_LANGUAGES_22)
print(f"📊 Loaded {lang_count} languages")
# Test model config
model_count = len(MODEL_CONFIG)
print(f"📊 Loaded {model_count} model configurations")
# Test pipeline config
assert "max_critic_iterations" in PIPELINE_CONFIG
print(f"✅ Pipeline config loaded (max iterations: {PIPELINE_CONFIG['max_critic_iterations']})")
# Test specific languages
test_langs = ["hindi", "tamil", "bengali", "telugu"]
for lang in test_langs:
if lang in INDIAN_LANGUAGES_22:
info = INDIAN_LANGUAGES_22[lang]
print(f"✅ {lang}: {info['native_name']} ({info['script']})")
else:
print(f"❌ {lang} not found")
return False
return True
except Exception as e:
print(f"❌ Config test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_model_paths():
"""Test model path configuration"""
print("\n🧪 Testing model paths...")
try:
from config import get_model_paths
paths = get_model_paths()
print(f"📊 Found {len(paths)} model roles")
for role, path in list(paths.items())[:3]: # Show first 3
print(f" {role}: {path}")
return True
except Exception as e:
print(f"❌ Model paths test failed: {e}")
return False
def test_tools():
"""Test tool framework"""
print("\n🧪 Testing tool framework...")
try:
from tools.registry import ToolRegistry
from tools.tools import CalculatorTool, KnowledgeBaseTool
# Test registry
registry = ToolRegistry()
tools = registry.get_available_tools()
print(f"✅ Tool registry loaded with {len(tools)} tools: {', '.join(tools)}")
# Test calculator
calc = CalculatorTool()
schema = calc.get_schema()
print(f"✅ Calculator schema: {schema['name']}")
result = calc.execute("2 + 2")
print(f"✅ Calculator test: 2 + 2 = {result}")
assert result == 4
# Test knowledge base
kb = KnowledgeBaseTool()
result = kb.execute("capital of India")
print(f"✅ Knowledge base test: capital of India = {result}")
return True
except Exception as e:
print(f"❌ Tools test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_prompts():
"""Test prompt loading"""
print("\n🧪 Testing prompts...")
try:
import yaml
prompts_file = Path("prompts/meta_prompts.yaml")
if prompts_file.exists():
with open(prompts_file, 'r', encoding='utf-8') as f:
prompts = yaml.safe_load(f)
required_prompts = ["ingestion", "reasoning", "critic", "synthesis"]
for prompt in required_prompts:
if prompt in prompts:
print(f"✅ {prompt} prompt loaded ({len(prompts[prompt])} chars)")
else:
print(f"❌ {prompt} prompt missing")
return False
return True
else:
print("⚠️ Prompts file not found, using defaults")
return True
except Exception as e:
print(f"❌ Prompts test failed: {e}")
return False
def test_vram_manager():
"""Test VRAM manager"""
print("\n🧪 Testing VRAM manager...")
try:
from core.vram_manager import VRAMManager, MemoryProfiler
manager = VRAMManager()
# Test memory stats
stats = manager.get_memory_stats()
print(f"✅ VRAM stats: {stats.total_gb:.1f}GB total")
# Test flush
flush_result = manager.flush()
print(f"✅ Flush completed, freed: {flush_result['freed_gb']:.2f}GB")
# Test optimization
opt = manager.optimize_for_model(5.0) # 5GB model
print(f"✅ Optimization recommendation: {opt['recommended_gpu_layers']} GPU layers")
return True
except Exception as e:
print(f"❌ VRAM manager test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_dummy_orchestrator():
"""Test orchestrator initialization without models"""
print("\n🧪 Testing orchestrator (dummy)...")
try:
from core.orchestrator import JugaadOrchestrator
# Create dummy model config
dummy_models = {
"translator": "/tmp/dummy_translator.gguf",
"reasoner": "/tmp/dummy_reasoner.gguf",
"critic": "/tmp/dummy_critic.gguf"
}
# Test initialization
orch = JugaadOrchestrator(dummy_models)
print("✅ Orchestrator initialized")
# Test stats
stats = orch.get_stats()
print(f"✅ Stats: {stats['models_loaded']} models loaded")
return True
except Exception as e:
print(f"❌ Orchestrator test failed: {e}")
import traceback
traceback.print_exc()
return False
def main():
"""Run all tests"""
print("🎵 Ariv System Test Suite")
print("=" * 60)
tests = [
("Imports", test_imports),
("Configuration", test_config),
("Model Paths", test_model_paths),
("Tools", test_tools),
("Prompts", test_prompts),
("VRAM Manager", test_vram_manager),
("Orchestrator", test_dummy_orchestrator),
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
print(f"\n🔍 Running: {test_name}")
print("-" * 40)
if test_func():
passed += 1
print(f"✅ {test_name} PASSED")
else:
print(f"❌ {test_name} FAILED")
# Summary
print("\n" + "=" * 60)
print("📊 TEST SUMMARY")
print("=" * 60)
print(f"✅ Passed: {passed}/{total}")
print(f"❌ Failed: {total - passed}/{total}")
if passed == total:
print("\n🎉 All tests passed! System is ready.")
print("\n💡 Next steps:")
print(" 1. Download models: python models/download_models.py core")
print(" 2. Test with: python maha_system.py --status")
print(" 3. Run interactive: python maha_system.py --interactive --lang hindi")
return 0
else:
print(f"\n⚠️ {total - passed} tests failed. Please check the errors above.")
return 1
if __name__ == "__main__":
sys.exit(main())