-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
59 lines (49 loc) · 1.63 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>Test Bot Responses</title>
<style>
input[type="text"] {
width: 50%;
resize: none;
}
</style>
<script src="assistant.js" defer></script>
</head>
<body>
<h1>Test Bot Responses</h1>
<p>Enter your message below to test the bot responses.</p>
<p>This is just for demonstration purposes of the assistantjs. Visit <a href="https://github.com/sandunwira/assistantjs" target="_blank">GitHub</a> for more information.</p>
<form id="chatForm">
<label for="chatMessage">Message:</label><br>
<input type="text" id="chatMessage" name="message"><br><br>
<input type="submit" value="Submit">
</form>
<p id="botResponse"></p>
<script>
document.addEventListener('DOMContentLoaded', async function () {
const chatForm = document.getElementById('chatForm');
const chatMessage = document.getElementById('chatMessage');
const botResponse = document.getElementById('botResponse');
try {
const assistant = new Assistant();
await assistant.initialize();
chatForm.addEventListener('submit', async function (event) {
event.preventDefault();
const userMessage = chatMessage.value.trim();
try {
const response = await assistant.processQuery(userMessage);
botResponse.innerHTML = response;
} catch (error) {
console.error('Error processing query:', error);
botResponse.innerHTML = 'Sorry, an error occurred while processing your request.';
}
});
} catch (error) {
console.error('Failed to initialize assistant:', error);
botResponse.innerHTML = 'Sorry, the assistant failed to initialize properly.';
}
});
</script>
</body>
</html>