2023-06-08 06:58:02 +00:00
|
|
|
// Project : lollms-webui
|
2023-05-02 12:16:10 +00:00
|
|
|
// Author : ParisNeo
|
|
|
|
// Description :
|
|
|
|
// All websocket stuff can be found here.
|
|
|
|
|
|
|
|
|
|
|
|
var globals={
|
|
|
|
is_generating:false,
|
|
|
|
chatWindow:undefined,
|
|
|
|
chatForm:undefined,
|
|
|
|
userInput:undefined,
|
|
|
|
stopGeneration:undefined,
|
|
|
|
sendbtn:undefined,
|
|
|
|
waitAnimation:undefined
|
|
|
|
}
|
|
|
|
|
2023-05-14 19:18:18 +00:00
|
|
|
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port);
|
2023-05-02 12:16:10 +00:00
|
|
|
|
|
|
|
socket.on('connect', function() {
|
|
|
|
});
|
|
|
|
socket.on('disconnect', function() {
|
|
|
|
console.log("Disconnected")
|
|
|
|
});
|
|
|
|
socket.on('infos', function(msg) {
|
2023-05-14 09:10:49 +00:00
|
|
|
console.log(msg)
|
|
|
|
if(msg["status"]=="generation_started"){
|
|
|
|
if(globals.user_msg){
|
|
|
|
globals.user_msg.setSender(msg.user);
|
|
|
|
globals.user_msg.setMessage(msg.message);
|
|
|
|
globals.user_msg.setID(msg.id);
|
|
|
|
}
|
|
|
|
globals.bot_msg.setSender(msg.bot);
|
|
|
|
globals.bot_msg.setID(msg.ai_message_id);
|
|
|
|
globals.bot_msg.messageTextElement.innerHTML = `Generating answer. Please stand by...`;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
globals.sendbtn.style.display="block";
|
|
|
|
globals.waitAnimation.style.display="none";
|
|
|
|
globals.stopGeneration.style.display = "none";
|
|
|
|
globals.is_generating = false
|
|
|
|
alert("It seems that no model has been loaded. Please download and install a model first, then try again.");
|
|
|
|
}
|
2023-05-02 12:16:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('waiter', function(msg) {
|
|
|
|
globals.bot_msg.messageTextElement.innerHTML = `Generating answer. Please stand by...`;
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('message', function(msg) {
|
|
|
|
text = msg.data;
|
|
|
|
// For the other enrtries, these are just the text of the chatbot
|
|
|
|
|
|
|
|
globals.bot_msg.messageTextElement.innerHTML = marked.marked(text);
|
|
|
|
// scroll to bottom of chat window
|
|
|
|
globals.chatWindow.scrollTop = globals.chatWindow.scrollHeight;
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('final',function(msg){
|
|
|
|
text = msg.data;
|
|
|
|
globals.bot_msg.hiddenElement.innerHTML = text
|
|
|
|
globals.bot_msg.messageTextElement.innerHTML = marked.marked(text)
|
|
|
|
globals.sendbtn.style.display="block";
|
|
|
|
globals.waitAnimation.style.display="none";
|
|
|
|
globals.stopGeneration.style.display = "none";
|
|
|
|
globals.is_generating = false
|
|
|
|
});
|
|
|
|
|
|
|
|
globals.socket = socket
|
|
|
|
globals.is_generating = false
|
|
|
|
|
|
|
|
function send_message(service_name, parameters){
|
|
|
|
if(!globals.is_generating){
|
|
|
|
globals.socket.emit(service_name, parameters);
|
|
|
|
globals.is_generating = true
|
|
|
|
}
|
2023-05-13 22:24:26 +00:00
|
|
|
}
|