-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest-api.sh
More file actions
executable file
Β·111 lines (94 loc) Β· 3.16 KB
/
test-api.sh
File metadata and controls
executable file
Β·111 lines (94 loc) Β· 3.16 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
#!/bin/bash
#
# Copyright 2024-2026 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Mem4j Example API Test Script
API_BASE="http://localhost:9090/api/chat"
echo "π§ͺ Mem4j Example API Test Script"
echo "================================"
# Check if server is running
echo "π Checking if server is running..."
if ! curl -s "$API_BASE/memories/test-user" > /dev/null 2>&1; then
echo "β Error: Server is not running on http://localhost:9090"
echo " Please start the server first:"
echo " ./start-example.sh"
exit 1
fi
echo "β
Server is running"
echo ""
# Test 1: Send first message
echo "π Test 1: Sending first message..."
response1=$(curl -s -X POST "$API_BASE/send" \
-H "Content-Type: application/json" \
-d '{
"userId": "test-user",
"message": "Hi, I am John. I love playing basketball and I am from New York."
}')
echo "Response: $response1"
echo ""
# Test 2: Send second message
echo "π Test 2: Sending second message..."
response2=$(curl -s -X POST "$API_BASE/send" \
-H "Content-Type: application/json" \
-d '{
"userId": "test-user",
"message": "What do you know about me?"
}')
echo "Response: $response2"
echo ""
# Test 3: Get memories
echo "π Test 3: Getting user memories..."
memories=$(curl -s "$API_BASE/memories/test-user")
echo "Memories: $memories"
echo ""
# Test 4: Send message in Chinese
echo "π Test 4: Testing Chinese message..."
response3=$(curl -s -X POST "$API_BASE/send" \
-H "Content-Type: application/json" \
-d '{
"userId": "test-user-cn",
"message": "δ½ ε₯½οΌζζ―εΌ δΈοΌζδ½ε¨εδΊ¬οΌεζ¬’εη«ι
γ"
}')
echo "Response: $response3"
echo ""
# Test 5: Query in Chinese
echo "π Test 5: Querying in Chinese..."
response4=$(curl -s -X POST "$API_BASE/send" \
-H "Content-Type: application/json" \
-d '{
"userId": "test-user-cn",
"message": "ζεζ¬’δ»δΉοΌ"
}')
echo "Response: $response4"
echo ""
# Test 6: Get Chinese user memories
echo "π Test 6: Getting Chinese user memories..."
memories_cn=$(curl -s "$API_BASE/memories/test-user-cn")
echo "Memories: $memories_cn"
echo ""
# Cleanup option
echo "π§Ή Clean up test data? (y/N)"
read -r cleanup
if [[ $cleanup =~ ^[Yy]$ ]]; then
echo "Clearing test-user memories..."
curl -s -X DELETE "$API_BASE/memories/test-user"
echo "Clearing test-user-cn memories..."
curl -s -X DELETE "$API_BASE/memories/test-user-cn"
echo "β
Cleanup completed"
fi
echo ""
echo "β
API tests completed!"
echo " You can now test the API manually with:"
echo " curl -X POST '$API_BASE/send' -H 'Content-Type: application/json' -d '{\"userId\": \"your-user\", \"message\": \"your message\"}'"