-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest_system.py
More file actions
153 lines (135 loc) · 5.54 KB
/
test_system.py
File metadata and controls
153 lines (135 loc) · 5.54 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
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
"""
Test script to test the game knowledge base system and some API endpoints
"""
import requests
import json
import time
# API base URL
BASE_URL = "http://127.0.0.1:8000"
def test_api_endpoint(endpoint, method="GET", data=None):
"""Test an API endpoint and return the response."""
url = f"{BASE_URL}{endpoint}"
try:
if method == "GET":
response = requests.get(url)
elif method == "POST":
response = requests.post(url, json=data)
else:
return {"error": f"Unsupported method: {method}"}
return {
"status_code": response.status_code,
"response": response.json() if response.headers.get('content-type', '').startswith('application/json') else response.text
}
except Exception as e:
return {"error": str(e)}
def main():
print("🎮 Game Knowledge Base System Test")
print("=" * 50)
# Test 1: Check if server is running
print("\n1. Testing server connection...")
result = test_api_endpoint("/games/list")
if result.get("status_code") == 200:
print("Server is running")
else:
print("Server is not running. Please start the server first:")
print("uv run run.py")
return
# Test 2: List available games
print("\n2. Testing game listing...")
result = test_api_endpoint("/games/list")
if result.get("status_code") == 200:
games = result["response"]
print(f"Available games:")
print(f"Detection games: {games.get('detection_games', [])}")
print(f"CSV games: {games.get('csv_games', [])}")
print(f"Vector games: {games.get('vector_games', [])}")
else:
print(f"Failed to list games: {result}")
# Test 3: Validate Minecraft CSV
print("\n3. Testing Minecraft CSV validation...")
result = test_api_endpoint("/games/minecraft/knowledge/validate")
if result.get("status_code") == 200:
validation = result["response"]
if validation.get("is_valid"):
print("Minecraft CSV is valid")
else:
print(f"Minecraft CSV validation failed: {validation.get('errors', [])}")
else:
print(f"Failed to validate CSV: {result}")
# Test 4: Process Minecraft knowledge
print("\n4. Processing Minecraft knowledge...")
print(" This may take a few minutes as it extracts content from URLs...")
result = test_api_endpoint("/games/minecraft/knowledge/process", "POST")
if result.get("status_code") == 200:
process_result = result["response"]
print(f"Successfully processed Minecraft knowledge")
print(f"Stats: {process_result.get('stats', {})}")
else:
print(f"Failed to process knowledge: {result}")
return
# Test 5: Search Minecraft knowledge
print("\n5. Testing knowledge search...")
search_queries = [
"How to make redstone circuits?",
"What are the best enchantments?",
"How to find villagers?"
]
for query in search_queries:
print(f"\n Searching: '{query}'")
search_data = {
"query": query,
"limit": 3,
"game_name":"Minecraft"
}
result = test_api_endpoint("/games/minecraft/knowledge/search", "POST", search_data)
if result.get("status_code") == 200:
search_result = result["response"]
print(f"Found {search_result.get('total_results', 0)} results")
for i, res in enumerate(search_result.get('results', [])[:2], 1):
print(f"{i}. {res.get('metadata', {}).get('title', 'Unknown')}")
print(f"Source: {res.get('metadata', {}).get('content_type', 'unknown')}")
print(f"Content: {res.get('content', '')[:100]}...")
else:
print(f"Search failed: {result}")
# Test 6: Test game detection
print("\n6. Testing game detection...")
test_messages = [
"I'm playing Minecraft and need help with redstone",
"How do I beat this boss in Dark Souls?",
"What's the best strategy for building in Minecraft?"
]
for message in test_messages:
print(f"\n Testing: '{message}'")
detect_data = {"message": message}
result = test_api_endpoint("/games/detect", "POST", detect_data)
if result.get("status_code") == 200:
detect_result = result["response"]
detected_game = detect_result.get("detected_game")
print(f"Detected game: {detected_game}")
else:
print(f"Detection failed: {result}")
# Test 7: Test enhanced chat
print("\n7. Testing enhanced chat...")
chat_messages = [
"I need help with redstone in Minecraft",
"What are the best enchantments for my sword?",
"How do I build an automatic farm?"
]
for message in chat_messages:
print(f"\n Chat: '{message}'")
chat_data = {"message": message}
result = test_api_endpoint("/chat", "POST", chat_data)
if result.get("status_code") == 200:
chat_result = result["response"]
response_text = chat_result.get("response", "")
print(f"Response: {response_text[:200]}...")
else:
print(f"Chat failed: {result}")
print("\n" + "=" * 50)
print("🎉 Testing completed!")
print("\nTo test manually:")
print("1. Start the server: python -m backend.backend")
print("2. Use the API endpoints or test with the overlay interface")
print("3. Check the vector_db folder for stored embeddings")
if __name__ == "__main__":
main()