-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.js
More file actions
47 lines (40 loc) · 1.44 KB
/
Copy pathtest-api.js
File metadata and controls
47 lines (40 loc) · 1.44 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
(async () => {
const { default: fetch } = await import('node-fetch');
async function testChatbot() {
try {
// Test the languages endpoint
const languagesResponse = await fetch('http://localhost:3000/api/languages');
const languagesData = await languagesResponse.json();
console.log('Supported languages:', languagesData);
// Test the chat endpoint with a sample message in English
const chatResponse = await fetch('http://localhost:3000/api/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
message: "What are my rights as a Nigerian citizen?",
language: "english"
})
});
const chatData = await chatResponse.json();
console.log('Chat response (English):', chatData);
// Test the chat endpoint with a sample message in Pidgin
const pidginResponse = await fetch('http://localhost:3000/api/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
message: "Wetin be my right as Nigerian citizen?",
language: "pidgin"
})
});
const pidginData = await pidginResponse.json();
console.log('Chat response (Pidgin):', pidginData);
} catch (error) {
console.error('Test error:', error);
}
}
testChatbot();
})();