-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (28 loc) · 1.02 KB
/
Copy pathscript.js
File metadata and controls
32 lines (28 loc) · 1.02 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
$(document).ready(function () {
$('#send').click(function () {
const message = $('#message').val();
const model = $('#model').val();
if (!message.trim()) return;
$('#chat-box').append(`<div class="bubble user"><b>user:</b><br>${message}</div>`);
$('#message').val('');
$.ajax({
url: 'chat.php',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({ message, model }),
success: function (data) {
$('#chat-box').append(`<div class="bubble assistant"><b>assistant:</b><br>${data.assistant.replace(/\n/g, '<br>')}</div>`);
$('#chat-box').scrollTop($('#chat-box')[0].scrollHeight);
},
error: function () {
alert("Something went wrong!");
}
});
});
$('#message').keypress(function (e) {
if (e.which === 13 && !e.shiftKey) {
e.preventDefault();
$('#send').click();
}
});
});