File size: 9,600 Bytes
4cdaca5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0df1705
 
4cdaca5
0df1705
4cdaca5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0df1705
 
4cdaca5
0df1705
 
4cdaca5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0df1705
4cdaca5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0df1705
 
 
4cdaca5
 
 
 
 
0df1705
4cdaca5
 
 
 
 
 
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
"""Test script for AI Radio - Verify all components work"""
import sys

def test_imports():
    """Test that all required modules can be imported"""
    print("πŸ§ͺ Testing imports...")
    
    try:
        import gradio as gr
        print("  βœ… Gradio imported")
    except ImportError as e:
        print(f"  ❌ Gradio import failed: {e}")
        return False
    
    try:
        from openai import OpenAI
        print("  βœ… OpenAI (Nebius) imported")
    except ImportError as e:
        print(f"  ❌ OpenAI import failed: {e}")
        return False
    
    try:
        from elevenlabs import ElevenLabs
        print("  βœ… ElevenLabs imported")
    except ImportError as e:
        print(f"  ❌ ElevenLabs import failed: {e}")
        return False
    
    try:
        from llama_index.core import VectorStoreIndex
        print("  βœ… LlamaIndex imported")
    except ImportError as e:
        print(f"  ❌ LlamaIndex import failed: {e}")
        return False
    
    try:
        import feedparser
        print("  βœ… Feedparser imported")
    except ImportError as e:
        print(f"  ❌ Feedparser import failed: {e}")
        return False
    
    return True

def test_config():
    """Test configuration file"""
    print("\nβš™οΈ Testing configuration...")
    
    try:
        from config import get_config
        config = get_config()
        print("  βœ… Config loaded")
        
        if config.elevenlabs_api_key:
            print("  βœ… ElevenLabs API key present")
        else:
            print("  ⚠️  ElevenLabs API key missing")
        
        if config.nebius_api_key:
            print("  βœ… Nebius API key present")
        else:
            print("  ⚠️  Nebius API key missing (REQUIRED!)")
            print("     Please add your Nebius API key to config.py")
        
        if config.llamaindex_api_key:
            print("  βœ… LlamaIndex API key present")
        else:
            print("  ⚠️  LlamaIndex API key missing")
        
        return True
    except Exception as e:
        print(f"  ❌ Config test failed: {e}")
        return False

def test_mcp_servers():
    """Test MCP server imports and initialization"""
    print("\nπŸ”§ Testing MCP servers...")
    
    try:
        from mcp_servers import MusicMCPServer, NewsMCPServer, PodcastMCPServer
        print("  βœ… MCP servers imported")
        
        music_server = MusicMCPServer()
        print("  βœ… Music server initialized")
        
        news_server = NewsMCPServer()
        print("  βœ… News server initialized")
        
        podcast_server = PodcastMCPServer()
        print("  βœ… Podcast server initialized")
        
        # Test music server
        tracks = music_server.search_free_music("pop", "happy", 2)
        if tracks:
            print(f"  βœ… Music server returned {len(tracks)} tracks")
        else:
            print("  ⚠️  Music server returned no tracks")
        
        # Test news server
        news = news_server.fetch_news("technology", 2)
        if news:
            print(f"  βœ… News server returned {len(news)} items")
        else:
            print("  ⚠️  News server returned no items")
        
        # Test podcast server
        podcasts = podcast_server.get_trending_podcasts("technology", 2)
        if podcasts:
            print(f"  βœ… Podcast server returned {len(podcasts)} podcasts")
        else:
            print("  ⚠️  Podcast server returned no podcasts")
        
        return True
    except Exception as e:
        print(f"  ❌ MCP server test failed: {e}")
        import traceback
        traceback.print_exc()
        return False

def test_rag_system():
    """Test RAG system"""
    print("\nπŸ’Ύ Testing RAG system...")
    
    try:
        from rag_system import RadioRAGSystem
        from config import get_config
        
        config = get_config()
        rag = RadioRAGSystem(config.nebius_api_key, config.nebius_api_base, config.nebius_model)
        print("  βœ… RAG system initialized")
        
        # Test storing preferences
        test_prefs = {
            "name": "Test User",
            "favorite_genres": ["pop", "rock"],
            "interests": ["technology"]
        }
        rag.store_user_preferences(test_prefs)
        print("  βœ… Preferences stored")
        
        # Test retrieving preferences
        prefs = rag.get_user_preferences()
        if prefs:
            print(f"  βœ… Preferences retrieved: {prefs.get('name', 'Unknown')}")
        else:
            print("  ⚠️  No preferences found")
        
        # Test stats
        stats = rag.get_listening_stats()
        print(f"  βœ… Stats retrieved: {stats['total_sessions']} sessions")
        
        return True
    except Exception as e:
        print(f"  ❌ RAG system test failed: {e}")
        import traceback
        traceback.print_exc()
        return False

def test_radio_agent():
    """Test radio agent"""
    print("\nπŸ€– Testing radio agent...")
    
    try:
        from radio_agent import RadioAgent
        from config import get_config
        
        config = get_config()
        agent = RadioAgent(config)
        print("  βœ… Radio agent initialized")
        
        # Test show planning
        test_prefs = {
            "name": "Test User",
            "favorite_genres": ["pop"],
            "interests": ["technology"],
            "podcast_interests": ["technology"],
            "mood": "happy"
        }
        
        show_plan = agent.plan_radio_show(test_prefs, duration_minutes=10)
        if show_plan:
            print(f"  βœ… Show planned with {len(show_plan)} segments")
            
            # Check segment types
            segment_types = [seg['type'] for seg in show_plan]
            print(f"     Segment types: {', '.join(set(segment_types))}")
        else:
            print("  ⚠️  Show planning returned empty plan")
        
        # Test MCP tools
        tools = agent.get_all_mcp_tools()
        print(f"  βœ… Agent has {len(tools)} MCP tools available")
        
        return True
    except Exception as e:
        print(f"  ❌ Radio agent test failed: {e}")
        import traceback
        traceback.print_exc()
        return False

def test_tts_service():
    """Test TTS service"""
    print("\nπŸ”Š Testing TTS service...")
    
    try:
        from tts_service import TTSService
        from config import get_config
        
        config = get_config()
        tts = TTSService(config.elevenlabs_api_key)
        print("  βœ… TTS service initialized")
        
        if tts.client:
            print("  βœ… ElevenLabs client connected")
            # Note: Not actually generating audio to save API calls
            print("  ℹ️  Skipping actual TTS generation to save API credits")
        else:
            print("  ⚠️  ElevenLabs client not initialized (check API key)")
        
        return True
    except Exception as e:
        print(f"  ❌ TTS service test failed: {e}")
        import traceback
        traceback.print_exc()
        return False

def test_app_structure():
    """Test that app file is valid"""
    print("\nπŸ“± Testing app structure...")
    
    try:
        # Try importing without running
        import app
        print("  βœ… App file is valid Python")
        
        # Check for key functions
        if hasattr(app, 'save_preferences'):
            print("  βœ… save_preferences function found")
        
        if hasattr(app, 'start_radio_stream'):
            print("  βœ… start_radio_stream function found")
        
        if hasattr(app, 'play_next_segment'):
            print("  βœ… play_next_segment function found")
        
        if hasattr(app, 'demo'):
            print("  βœ… Gradio demo object found")
        
        return True
    except Exception as e:
        print(f"  ❌ App structure test failed: {e}")
        import traceback
        traceback.print_exc()
        return False

def main():
    """Run all tests"""
    print("🎡 AI Radio - Component Test Suite\n")
    print("=" * 50)
    
    results = []
    
    # Run tests
    results.append(("Imports", test_imports()))
    results.append(("Configuration", test_config()))
    results.append(("MCP Servers", test_mcp_servers()))
    results.append(("RAG System", test_rag_system()))
    results.append(("Radio Agent", test_radio_agent()))
    results.append(("TTS Service", test_tts_service()))
    results.append(("App Structure", test_app_structure()))
    
    # Print summary
    print("\n" + "=" * 50)
    print("πŸ“Š Test Summary\n")
    
    passed = sum(1 for _, result in results if result)
    total = len(results)
    
    for test_name, result in results:
        status = "βœ… PASS" if result else "❌ FAIL"
        print(f"  {status} - {test_name}")
    
    print(f"\nResults: {passed}/{total} tests passed")
    
    if passed == total:
        print("\nπŸŽ‰ All tests passed! Your AI Radio is ready to launch! πŸŽ‰")
        print("\nNext steps:")
        print("  1. Make sure you've added your Nebius API key to config.py")
        print("  2. Run: python run.py")
        print("  3. Open: http://localhost:7867")
        return 0
    else:
        print("\n⚠️  Some tests failed. Please fix the issues above.")
        print("\nCommon fixes:")
        print("  - Run: pip install -r requirements.txt")
        print("  - Add your Nebius API key to config.py")
        print("  - Check that all files are in the correct location")
        return 1

if __name__ == "__main__":
    sys.exit(main())