-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_streaming.py
More file actions
executable file
·54 lines (41 loc) · 1.67 KB
/
Copy pathtest_streaming.py
File metadata and controls
executable file
·54 lines (41 loc) · 1.67 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
#!/usr/bin/env python3
"""Test script for streaming agent functionality."""
import asyncio
import sys
import os
# Add the project root to the Python path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from streaming_agent import StreamingChatbot, EventType
async def test_basic_streaming():
"""Test basic streaming functionality."""
print("🧪 Testing Streaming Agent...")
print("=" * 50)
try:
# Create streaming chatbot
chatbot = StreamingChatbot(verbose=False, mode="react")
# Simple test query
query = "What is 2 + 2?"
print(f"📤 Query: {query}")
print("-" * 30)
events_received = 0
async for event in chatbot.chat_stream(query):
events_received += 1
print(f"[{events_received}] {event.type.value}: {event.data}")
if event.type == EventType.COMPLETE:
response = event.data.get("response", {})
print(f"\n✅ Final Response: {response.get('output', 'No output')}")
break
elif event.type == EventType.ERROR:
print(f"\n❌ Error: {event.data.get('error', 'Unknown error')}")
break
elif events_received > 20: # Safety limit
print("\n⚠️ Too many events, stopping...")
break
print(f"\n📊 Total events received: {events_received}")
print("✅ Test completed successfully!")
except Exception as e:
print(f"❌ Test failed: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
asyncio.run(test_basic_streaming())