File size: 1,011 Bytes
6ca2339
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests, json, time

# 1. Send a chat message
sess = "history_test_123"
r = requests.post("http://localhost:8000/chat/stream",
    json={"session_id": sess, "user_message": "What is StackLogix?"},
    stream=True, timeout=60)
for line in r.iter_lines():
    if line and b"done" in line:
        break
print("Chat sent OK")

# 2. Get chat history
time.sleep(0.5)
r2 = requests.get(f"http://localhost:8000/chats/{sess}", timeout=10)
data = r2.json()
print(f"\n--- GET /chats/{sess} ---")
print(f"Status: {r2.status_code}")
print(f"Message count: {data.get('message_count')}")
for msg in data.get("messages", []):
    content_preview = msg["content"][:80]
    print(f"  {msg['role']}: {content_preview}...")

# 3. List all sessions
r3 = requests.get("http://localhost:8000/chats", timeout=10)
print(f"\n--- GET /chats ---")
sessions = r3.json()
print(f"Total sessions: {sessions.get('total')}")
for s in sessions.get("sessions", [])[:5]:
    print(f"  {s['session_id'][:16]}... msgs={s['message_count']}")