2023-04-13 10:31:48 +00:00
|
|
|
function update_main(){
|
2023-04-27 23:39:57 +00:00
|
|
|
globals.chatWindow = document.getElementById('chat-window');
|
|
|
|
globals.chatForm = document.getElementById('chat-form');
|
|
|
|
globals.userInput = document.getElementById('user-input');
|
|
|
|
globals.stopGeneration = document.getElementById("stop-generation")
|
|
|
|
globals.sendbtn = document.querySelector("#submit-input")
|
|
|
|
globals.waitAnimation = document.querySelector("#wait-animation")
|
|
|
|
|
|
|
|
globals.stopGeneration.addEventListener('click', (event) =>{
|
2023-04-22 17:14:25 +00:00
|
|
|
event.preventDefault();
|
|
|
|
console.log("Stop clicked");
|
2023-04-23 22:19:15 +00:00
|
|
|
fetch('/stop_gen')
|
2023-04-22 17:14:25 +00:00
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => {
|
|
|
|
console.log(data);
|
2023-05-02 12:16:10 +00:00
|
|
|
globals.is_generating = true
|
2023-04-22 17:14:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
})
|
2023-04-13 20:44:26 +00:00
|
|
|
|
2023-04-24 19:24:18 +00:00
|
|
|
|
|
|
|
function submit_form(){
|
|
|
|
console.log("Submitting")
|
2023-04-13 10:31:48 +00:00
|
|
|
|
2023-04-24 19:24:18 +00:00
|
|
|
// get user input and clear input field
|
2023-04-27 23:39:57 +00:00
|
|
|
message = globals.userInput.value;
|
|
|
|
globals.userInput.value = '';
|
|
|
|
globals.sendbtn.style.display="none";
|
|
|
|
globals.waitAnimation.style.display="block";
|
|
|
|
globals.stopGeneration.style.display = "block";
|
2023-04-24 19:24:18 +00:00
|
|
|
console.log("Sending message to bot")
|
2023-04-16 11:32:14 +00:00
|
|
|
|
2023-04-27 23:39:57 +00:00
|
|
|
globals.user_msg = addMessage('',message, 0, 0, can_edit=true);
|
|
|
|
globals.bot_msg = addMessage('', '', 0, 0, can_edit=true);
|
2023-04-24 21:11:32 +00:00
|
|
|
// scroll to bottom of chat window
|
2023-04-27 23:39:57 +00:00
|
|
|
globals.chatWindow.scrollTop = globals.chatWindow.scrollHeight;
|
2023-04-17 21:15:17 +00:00
|
|
|
|
2023-04-27 23:39:57 +00:00
|
|
|
send_message('generate_msg',{prompt: message})
|
2023-04-24 19:24:18 +00:00
|
|
|
|
2023-04-17 10:54:48 +00:00
|
|
|
|
2023-04-27 14:44:22 +00:00
|
|
|
//socket.emit('stream-text', {text: text});
|
2023-04-24 19:24:18 +00:00
|
|
|
}
|
2023-04-27 23:39:57 +00:00
|
|
|
globals.chatForm.addEventListener('submit', event => {
|
2023-04-24 19:24:18 +00:00
|
|
|
event.preventDefault();
|
|
|
|
submit_form();
|
2023-04-13 20:44:26 +00:00
|
|
|
});
|
2023-04-27 23:39:57 +00:00
|
|
|
globals.userInput.addEventListener("keyup", function(event) {
|
2023-04-24 19:24:18 +00:00
|
|
|
// Check if Enter key was pressed while holding Shift
|
|
|
|
// Also check if Shift + Ctrl keys were pressed while typing
|
|
|
|
// These combinations override the submit action
|
|
|
|
const shiftPressed = event.shiftKey;
|
|
|
|
const ctrlPressed = event.ctrlKey && !event.metaKey;
|
|
|
|
|
|
|
|
if ((!shiftPressed) && event.key === "Enter") {
|
|
|
|
submit_form();
|
|
|
|
}
|
|
|
|
});
|
2023-04-13 20:44:26 +00:00
|
|
|
}
|