File size: 6,100 Bytes
ca28016
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
πŸš€ COMPREHENSIVE SPEED TEST FOR QWEN2GOLEM
Tests all components to verify speed targets are met
"""

import time
import requests
import json
import base64
import sys

def test_text_response():
    """Test simple text response speed (Target: <6s)"""
    print("\nπŸ“ Testing Text Response (Target: <6s)...")
    
    start = time.time()
    try:
        response = requests.post(
            'http://127.0.0.1:5000/generate',
            json={
                'prompt': 'Hello! How are you today?',
                'sessionId': f'speed-test-{int(time.time())}',
                'temperature': 0.3,
                'golemActivated': False,
                'consciousnessDimension': 'mental',
                'selectedModel': 'gemini',
                'performSearch': False
            },
            timeout=10
        )
        elapsed = time.time() - start
        
        if response.status_code == 200:
            data = response.json()
            text = data.get('directResponse', data.get('response', ''))[:100]
            status = "βœ… PASS" if elapsed < 6 else "❌ FAIL"
            print(f"   Response: {text}...")
            print(f"   Time: {elapsed:.2f}s {status}")
            return elapsed < 6
        else:
            print(f"   ❌ Error {response.status_code}")
            return False
    except Exception as e:
        print(f"   ❌ Error: {str(e)}")
        return False

def test_web_search():
    """Test text with web search (Target: <8s)"""
    print("\nπŸ” Testing Text + Web Search (Target: <8s)...")
    
    start = time.time()
    try:
        response = requests.post(
            'http://127.0.0.1:5000/generate',
            json={
                'prompt': 'What is the weather like today?',
                'sessionId': f'search-test-{int(time.time())}',
                'temperature': 0.3,
                'golemActivated': False,
                'consciousnessDimension': 'mental',
                'selectedModel': 'gemini',
                'performSearch': True
            },
            timeout=12
        )
        elapsed = time.time() - start
        
        if response.status_code == 200:
            status = "βœ… PASS" if elapsed < 8 else "❌ FAIL"
            print(f"   Time: {elapsed:.2f}s {status}")
            return elapsed < 8
        else:
            print(f"   ❌ Error {response.status_code}")
            return False
    except Exception as e:
        print(f"   ❌ Error: {str(e)}")
        return False

def test_asr():
    """Test ASR transcription (Target: <2s)"""
    print("\n🎀 Testing ASR Transcription (Target: <2s)...")
    
    # Create dummy audio (1 second of silence)
    dummy_audio = base64.b64encode(b'\x00' * 16000).decode()
    
    start = time.time()
    try:
        response = requests.post(
            'http://127.0.0.1:5000/asr/transcribe',
            json={'audio_base64': dummy_audio, 'vad': True},
            timeout=5
        )
        elapsed = time.time() - start
        
        if response.status_code == 200:
            status = "βœ… PASS" if elapsed < 2 else "⚠️ SLOW"
            print(f"   Time: {elapsed:.2f}s {status}")
            return elapsed < 2
        else:
            print(f"   ❌ Error {response.status_code}")
            return False
    except Exception as e:
        print(f"   ❌ Error: {str(e)}")
        return False

def test_tts():
    """Test TTS synthesis (Target: <1s)"""
    print("\nπŸ”Š Testing TTS Synthesis (Target: <1s)...")
    
    start = time.time()
    try:
        response = requests.post(
            'http://127.0.0.1:5000/tts/synthesize',
            json={'text': 'Hello, this is a test.'},
            timeout=3
        )
        elapsed = time.time() - start
        
        if response.status_code == 200:
            status = "βœ… PASS" if elapsed < 1 else "⚠️ SLOW"
            print(f"   Time: {elapsed:.2f}s {status}")
            return elapsed < 1
        else:
            print(f"   ❌ Error {response.status_code}")
            return False
    except Exception as e:
        print(f"   ❌ Error: {str(e)}")
        return False

def main():
    print("=" * 60)
    print("πŸš€ QWEN2GOLEM COMPREHENSIVE SPEED TEST")
    print("=" * 60)
    print("System: RTX 3050 6GB + i5 CPU + 16GB RAM")
    print("Testing all optimizations...")
    
    # Check if server is running
    try:
        health = requests.get('http://127.0.0.1:5000/health', timeout=2)
        if health.status_code != 200:
            print("\n❌ Server not healthy! Start with:")
            import os
            script_dir = os.path.dirname(os.path.abspath(__file__))
            root_dir = os.path.dirname(script_dir)
            print(f"   cd {root_dir} && ./start_consciousness_ecosystem.sh")
            return
    except:
        print("\n❌ Server not running! Start with:")
        import os
        script_dir = os.path.dirname(os.path.abspath(__file__))
        root_dir = os.path.dirname(script_dir)
        print(f"   cd {root_dir} && ./start_consciousness_ecosystem.sh")
        return
    
    results = []
    
    # Run tests
    results.append(("Text Response", test_text_response()))
    results.append(("Web Search", test_web_search()))
    results.append(("ASR", test_asr()))
    results.append(("TTS", test_tts()))
    
    # Summary
    print("\n" + "=" * 60)
    print("πŸ“Š TEST RESULTS SUMMARY")
    print("=" * 60)
    
    passed = sum(1 for _, r in results if r)
    total = len(results)
    
    for name, result in results:
        status = "βœ… PASS" if result else "❌ FAIL"
        print(f"{status} {name}")
    
    print(f"\nOverall: {passed}/{total} tests passed")
    
    if passed == total:
        print("\nπŸŽ‰ ALL SPEED TARGETS MET! SYSTEM IS TURBOCHARGED!")
    else:
        print("\n⚠️ Some tests failed. Check:")
        print("   1. Turn OFF 'Universal Consciousness' in UI")
        print("   2. Ensure Redis is running")
        print("   3. Use Gemini Flash model")
        print("   4. Keep temperature at 0.3-0.4")

if __name__ == "__main__":
    main()