-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_basic.py
More file actions
353 lines (285 loc) · 11.1 KB
/
test_basic.py
File metadata and controls
353 lines (285 loc) · 11.1 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/usr/bin/env python3
"""
Basic tests for Ariv system without heavy dependencies
"""
import sys
import os
from pathlib import Path
# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent))
def test_config_syntax():
"""Test that config file syntax is valid"""
print("🧪 Testing config syntax...")
try:
# Read config file and check syntax
config_file = Path("config.py")
with open(config_file, 'r', encoding='utf-8') as f:
code = f.read()
import ast
ast.parse(code)
print("✅ Config syntax is valid")
return True
except SyntaxError as e:
print(f"❌ Config syntax error: {e}")
return False
def test_language_config():
"""Test language configuration"""
print("\n🧪 Testing language configuration...")
try:
# Import config without llama dependency
sys.modules['llama_cpp'] = type(sys)('llama_cpp')
sys.modules['llama_cpp'].Llama = type('Llama', (), {})
from config import INDIAN_LANGUAGES_22, get_supported_languages
# Test language count
lang_count = len(INDIAN_LANGUAGES_22)
print(f"📊 Total languages: {lang_count}")
# Test supported languages
supported = get_supported_languages()
print(f"📊 Supported languages: {len(supported)}")
# Show sample languages
sample_langs = ["hindi", "tamil", "bengali", "telugu", "marathi"]
for lang in sample_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
# Check for all 22 official languages
official_22 = [
"assamese", "bengali", "bodo", "dogri", "english", "gujarati", "hindi",
"kannada", "kashmiri", "konkani", "maithili", "malayalam", "manipuri",
"marathi", "nepali", "odia", "punjabi", "sanskrit", "santali", "sindhi",
"tamil", "telugu", "urdu"
]
missing = [lang for lang in official_22 if lang not in INDIAN_LANGUAGES_22]
if missing:
print(f"❌ Missing languages: {missing}")
return False
else:
print("✅ All 22 official Indian languages supported")
return True
except Exception as e:
print(f"❌ Language config test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_model_config():
"""Test model configuration"""
print("\n🧪 Testing model configuration...")
try:
from config import MODEL_CONFIG
print(f"📊 Total models: {len(MODEL_CONFIG)}")
# Check core models
core_models = ["translator", "reasoner", "critic", "bridge"]
for model in core_models:
if model in MODEL_CONFIG:
info = MODEL_CONFIG[model]
print(f"✅ {model}: {info['description']}")
else:
print(f"❌ {model} not found")
return False
# Check regional specialists
specialists = [k for k in MODEL_CONFIG.keys() if k.endswith("_specialist")]
print(f"✅ Regional specialists: {len(specialists)}")
for spec in specialists[:5]: # Show first 5
print(f" - {spec}")
return True
except Exception as e:
print(f"❌ Model config test failed: {e}")
return False
def test_tools_framework():
"""Test tool framework without heavy dependencies"""
print("\n🧪 Testing tool framework...")
try:
# Mock torch for tools
sys.modules['torch'] = type(sys)('torch')
sys.modules['torch'].cuda = type('cuda', (), {})
sys.modules['torch'].cuda.is_available = lambda: False
sys.modules['torch'].cuda.memory_allocated = lambda: 0
sys.modules['torch'].cuda.memory_reserved = lambda: 0
sys.modules['torch'].cuda.empty_cache = lambda: None
sys.modules['torch'].cuda.synchronize = lambda: None
sys.modules['torch'].cuda.get_device_properties = lambda x: type('props', (), {'total_memory': 16*1024**3})
from tools.registry import ToolRegistry
from tools.tools import CalculatorTool, KnowledgeBaseTool
# Test registry
registry = ToolRegistry()
tools = registry.get_available_tools()
print(f"✅ Tool registry: {len(tools)} tools")
# Test calculator
calc = CalculatorTool()
schema = calc.get_schema()
print(f"✅ Calculator: {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: {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:
content = prompts[prompt]
print(f"✅ {prompt}: {len(content)} chars")
else:
print(f"❌ {prompt} missing")
return False
return True
else:
print("⚠️ Prompts file not found")
return True
except Exception as e:
print(f"❌ Prompts test failed: {e}")
return False
def test_directory_structure():
"""Test that all required directories exist"""
print("\n🧪 Testing directory structure...")
required_dirs = [
"core", "models", "prompts", "tools", "benchmarks",
"languages", "deploy", "tests", "examples", "docs"
]
for dir_name in required_dirs:
dir_path = Path(dir_name)
if dir_path.exists() and dir_path.is_dir():
print(f"✅ {dir_name}/")
else:
print(f"❌ {dir_name}/ missing")
return False
# Check required files
required_files = [
"config.py", "maha_system.py", "requirements.txt",
"setup.py", "README.md", "prompts/meta_prompts.yaml"
]
for file_name in required_files:
file_path = Path(file_name)
if file_path.exists() and file_path.is_file():
print(f"✅ {file_name}")
else:
print(f"❌ {file_name} missing")
return False
return True
def test_dependencies():
"""Test optional dependencies"""
print("\n🧪 Testing optional dependencies...")
# Check if llama-cpp is available
try:
import llama_cpp
print("✅ llama-cpp-python: AVAILABLE")
llama_available = True
except ImportError:
print("⚠️ llama-cpp-python: NOT AVAILABLE (required for model inference)")
llama_available = False
# Check if torch is available
try:
import torch
print("✅ PyTorch: AVAILABLE")
torch_available = True
except ImportError:
print("⚠️ PyTorch: NOT AVAILABLE (required for GPU memory management)")
torch_available = False
# Check if yaml is available
try:
import yaml
print("✅ PyYAML: AVAILABLE")
except ImportError:
print("❌ PyYAML: NOT AVAILABLE (required for prompts)")
return False
# Check if numpy is available
try:
import numpy
print("✅ NumPy: AVAILABLE")
except ImportError:
print("⚠️ NumPy: NOT AVAILABLE (optional)")
return True
def create_install_script():
"""Create installation script"""
script_content = '''#!/bin/bash
# Ariv Installation Script
echo "🎵 Installing Ariv - The Indian AI Orchestra"
echo "="60
# Check Python version
python_version=$(python3 --version 2>&1 | awk '{print $2}')
echo "📊 Python version: $python_version"
# Install basic dependencies
echo "📦 Installing basic dependencies..."
pip3 install pyyaml numpy requests
# Install optional dependencies
echo "📦 Installing optional dependencies..."
pip3 install torch --index-url https://download.pytorch.org/whl/cpu
# Install llama-cpp-python (CPU version for testing)
echo "📦 Installing llama-cpp-python (CPU version)..."
pip3 install llama-cpp-python
echo "✅ Basic installation complete!"
echo ""
echo "💡 Next steps:"
echo " 1. Download models: python3 models/download_models.py core"
echo " 2. Test system: python3 test_basic.py"
echo " 3. Run interactive: python3 maha_system.py --interactive --lang hindi"
'''
with open("install.sh", "w") as f:
f.write(script_content)
os.chmod("install.sh", 0o755)
print("✅ Created installation script: install.sh")
def main():
"""Run all basic tests"""
print("🎵 Ariv Basic Test Suite")
print("=" * 60)
tests = [
("Config Syntax", test_config_syntax),
("Language Config", test_language_config),
("Model Config", test_model_config),
("Tools Framework", test_tools_framework),
("Prompts", test_prompts),
("Directory Structure", test_directory_structure),
("Dependencies", test_dependencies),
]
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("📊 BASIC TEST SUMMARY")
print("=" * 60)
print(f"✅ Passed: {passed}/{total}")
print(f"❌ Failed: {total - passed}/{total}")
if passed >= 5: # Allow some failures for optional components
print("\n🎉 Basic tests passed! System structure is ready.")
# Create installation script
create_install_script()
print("\n💡 Next steps:")
print(" 1. Install dependencies: pip install -r requirements.txt")
print(" 2. Or use script: ./install.sh")
print(" 3. Download models: python models/download_models.py core")
print(" 4. Test system: python maha_system.py --status")
print(" 5. Run interactive: python maha_system.py --interactive --lang hindi")
return 0
else:
print(f"\n⚠️ Multiple tests failed. Please check the errors above.")
return 1
if __name__ == "__main__":
import sys
sys.exit(main())