-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.html
More file actions
172 lines (147 loc) · 4.26 KB
/
Copy pathindex.html
File metadata and controls
172 lines (147 loc) · 4.26 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Chat Assistant</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
}
body {
display: flex;
flex-direction: column;
}
#chat-container {
display: flex;
flex-direction: column;
height: 100vh;
width: 70%;
max-width: 1000px;
margin: 0 auto;
padding: 1rem 0;
}
#chat-box {
flex: 1;
overflow-y: auto;
padding: 1rem;
border: 1px solid #ddd;
border-radius: 0.5rem;
margin-bottom: 1rem;
}
.field {
margin: 0;
}
.message {
background-color: transparent;
margin-bottom: 1rem;
}
.message.user {
display: flex;
justify-content: flex-end;
}
.message.assistant {
display: flex;
justify-content: flex-start;
}
.message.user .bubble {
background-color: #3273dc;
color: white;
padding: 1em 1.25em;
border-radius: 1em;
max-width: 70%;
line-height: 1.4;
}
.message.assistant .bubble {
background-color: #f0f0f0;
padding: 1em 1.25em;
border-radius: 1em;
max-width: 70%;
line-height: 1.6;
}
.message.assistant .bubble p {
margin-bottom: 0.75em;
}
.message.assistant .bubble ul,
.message.assistant .bubble ol {
padding-left: 1.25em;
margin-left: 0;
}
.message.assistant .bubble li {
margin-bottom: 0.5em;
}
.message.assistant .bubble pre {
background-color: #f6f6f6;
padding: 1em;
border-radius: 0.5em;
overflow-x: auto;
margin: 1em 0;
}
</style>
</head>
<body>
<div id="chat-container">
<h1 class="title">Helidon Assistant</h1>
<div id="chat-box"></div>
<div class="field has-addons" id="input-container">
<div class="control is-expanded">
<input id="user-input" class="input" type="text" placeholder="Type your message..." />
</div>
<div class="control">
<button id="send-button" class="button is-primary">Send</button>
</div>
</div>
</div>
<script>
const chatBox = document.getElementById('chat-box');
const userInput = document.getElementById('user-input');
const sendButton = document.getElementById('send-button');
let summary = "";
function appendMessage(text, sender) {
const div = document.createElement('div');
div.className = `message ${sender}`;
const bubble = document.createElement('div');
bubble.className = 'bubble';
if (sender === 'assistant') {
bubble.innerHTML = marked.parse(text);
} else {
bubble.textContent = text;
}
div.appendChild(bubble);
chatBox.appendChild(div);
chatBox.scrollTop = chatBox.scrollHeight;
}
async function sendMessage() {
const text = userInput.value.trim();
if (!text) return;
appendMessage(text, 'user');
userInput.value = '';
try {
const response = await fetch('/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ message: text, summary: summary })
});
const data = await response.json();
summary = data.summary;
appendMessage(data.message || '_[No response]_ 🤖', 'assistant');
// appendMessage("Summary: " + summary);
} catch (err) {
appendMessage('_[Error contacting assistant]_ ❌', 'assistant');
}
}
sendButton.addEventListener('click', sendMessage);
userInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
sendMessage();
}
});
</script>
</body>
</html>