-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_session.py
More file actions
94 lines (77 loc) · 3.27 KB
/
test_session.py
File metadata and controls
94 lines (77 loc) · 3.27 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
#!/usr/bin/env python3
"""
간단한 세션 기반 메모리 테스트
"""
import requests
import time
def test_session_memory():
base_url = "http://localhost:8000"
print("🧪 세션 기반 메모리 테스트 시작")
print("=" * 50)
# 1. 새 세션 생성
print("\n1️⃣ 새 세션 생성...")
session_resp = requests.post(f"{base_url}/sessions")
if session_resp.status_code == 200:
session_id = session_resp.json()["session_id"]
print(f"✅ 세션 생성: {session_id}")
else:
print("❌ 세션 생성 실패")
return
# 2. 연속 대화 테스트
print("\n2️⃣ 연속 대화 테스트...")
messages = [
"안녕하세요! 제 이름은 김철수입니다.",
"오늘 날씨가 정말 좋네요!",
"아까 제가 이름을 말했는데 기억하시나요?", # 메모리 테스트
"처음에 뭐라고 인사했는지 기억하세요?" # 메모리 테스트
]
for i, message in enumerate(messages, 1):
print(f"\n💬 메시지 {i}: {message}")
resp = requests.post(f"{base_url}/answer", json={
"prompt": message,
"session_id": session_id
})
if resp.status_code == 200:
answer = resp.json()["answer"]
print(f"🤖 유재석: {answer}")
# 메모리 테스트 결과 확인
if i == 3 and "김철수" in answer:
print("✅ 이름 기억 성공!")
elif i == 4 and "안녕" in answer:
print("✅ 첫 인사 기억 성공!")
else:
print(f"❌ 오류: {resp.status_code}")
time.sleep(1)
# 3. 채팅 기록 확인
print("\n3️⃣ 채팅 기록 확인...")
history_resp = requests.get(f"{base_url}/sessions/{session_id}/history")
if history_resp.status_code == 200:
history = history_resp.json()
print(f"📝 총 메시지: {history['count']}개")
for i, msg in enumerate(history["messages"][-4:], 1):
role = "👤" if msg["role"] == "user" else "🤖"
print(f" {i}. {role} {msg['content'][:50]}...")
# 4. 세션 정보 확인
print("\n4️⃣ 세션 정보 확인...")
sessions_resp = requests.get(f"{base_url}/sessions")
if sessions_resp.status_code == 200:
info = sessions_resp.json()
print(f"📊 총 세션: {info['total_sessions']}개")
print(f"📊 총 메시지: {info['total_messages']}개")
# 5. 세션 없이 대화 테스트 (자동 생성)
print("\n5️⃣ 세션 자동 생성 테스트...")
auto_resp = requests.post(f"{base_url}/answer", json={
"prompt": "세션 ID 없이 대화해요!"
})
if auto_resp.status_code == 200:
data = auto_resp.json()
print(f"✅ 자동 세션 생성: {data['session_id']}")
print(f"🤖 응답: {data['answer']}")
print("\n🎉 테스트 완료!")
if __name__ == "__main__":
try:
test_session_memory()
except requests.exceptions.ConnectionError:
print("❌ 서버 연결 실패. http://localhost:8000 에서 서버가 실행 중인지 확인하세요.")
except Exception as e:
print(f"❌ 테스트 중 오류: {e}")