enhanced ui

This commit is contained in:
Saifeddine ALOUI 2023-08-05 00:28:36 +02:00
parent 2e99b38571
commit c69adacf68
6 changed files with 93 additions and 49 deletions

View File

@ -426,6 +426,7 @@ class LoLLMsAPPI(LollmsApplication):
@socketio.on('load_discussion')
def load_discussion(data):
client_id = request.sid
ASCIIColors.yellow(f"Loading discussion for client {client_id}")
if "id" in data:
discussion_id = data["id"]
self.connections[client_id]["current_discussion"] = Discussion(discussion_id, self.db)
@ -533,7 +534,7 @@ class LoLLMsAPPI(LollmsApplication):
parent_message_id=self.message_id
)
ASCIIColors.green("Starting message generation by"+self.personality.name)
ASCIIColors.green("Starting message generation by "+self.personality.name)
self.connections[client_id]['generation_thread'] = threading.Thread(target=self.start_message_generation, args=(message, message.id, client_id))
self.connections[client_id]['generation_thread'].start()
@ -548,10 +549,14 @@ class LoLLMsAPPI(LollmsApplication):
def generate_msg_from(data):
client_id = request.sid
if self.connections[client_id]["current_discussion"] is None:
self.notify("Please select a discussion", False, client_id)
ASCIIColors.warning("Please select a discussion")
self.notify("Please select a discussion first", False, client_id)
return
id_ = data['id']
message = self.connections[client_id]["current_discussion"].select_message(id_)
if id_==-1:
message = self.connections[client_id]["current_discussion"].current_message
else:
message = self.connections[client_id]["current_discussion"].select_message(id_)
if message is None:
return
self.connections[client_id]['generation_thread'] = threading.Thread(target=self.start_message_generation, args=(message, message.id, client_id))
@ -567,10 +572,14 @@ class LoLLMsAPPI(LollmsApplication):
def handle_connection(data):
client_id = request.sid
if self.connections[client_id]["current_discussion"] is None:
ASCIIColors.yellow("Please select a discussion")
self.notify("Please select a discussion", False, client_id)
return
id_ = data['id']
message = self.connections[client_id]["current_discussion"].select_message(id_)
if id_==-1:
message = self.connections[client_id]["current_discussion"].current_message
else:
message = self.connections[client_id]["current_discussion"].select_message(id_)
self.connections[client_id]['generation_thread'] = threading.Thread(target=self.start_message_generation, args=(message, message.id, client_id, True))
self.connections[client_id]['generation_thread'].start()
@ -1014,7 +1023,7 @@ class LoLLMsAPPI(LollmsApplication):
# First we need to send the new message ID to the client
if is_continue:
self.connections[client_id]["current_discussion"].load_message(message_id)
self.connections[client_id]["generated_text"] = self.connections[client_id]["current_discussion"].current_message.content
self.connections[client_id]["generated_text"] = message.content
else:
self.new_message(client_id, self.personality.name, "✍ please stand by ...")
self.socketio.sleep(0.01)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
web/dist/index.html vendored
View File

@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LoLLMS WebUI - Welcome</title>
<script type="module" crossorigin src="/assets/index-303b1fab.js"></script>
<link rel="stylesheet" href="/assets/index-1c8c1547.css">
<script type="module" crossorigin src="/assets/index-c75baf49.js"></script>
<link rel="stylesheet" href="/assets/index-9c82748a.css">
</head>
<body>
<div id="app"></div>

View File

@ -10,12 +10,6 @@ import io from 'socket.io-client';
const URL = process.env.NODE_ENV === "production" ? undefined : (import.meta.env.VITE_LOLLMS_API);
const socket = new io(URL);
socket.onerror = (error) => {
console.error('WebSocket error:', error);
socket.disconnect()
};
// const app = createApp(/* your root component */);
// app.config.globalProperties.$socket = socket;

View File

@ -855,12 +855,12 @@ export default {
},
socketIOConnected() {
console.log("socketIOConnected")
this.$store.dispatch('setIsConnected',true);
this.$store.state.isConnected=true;
return true
},
socketIODisconnected() {
console.log("socketIOConnected")
this.$store.dispatch('setIsConnected',false);
this.$store.state.isConnected=false;
return true
},
new_message(msgObj) {
@ -908,7 +908,28 @@ export default {
}*/
},
talk(pers){
this.isGenerating = true;
this.setDiscussionLoading(this.currentDiscussion.id, this.isGenerating);
axios.get('/get_generation_status', {}).then((res) => {
if (res) {
//console.log(res.data.status);
if (!res.data.status) {
console.log('Generating message from ',res.data.status);
socket.emit('generate_msg_from', { id: -1 });
// Temp data
let lastmsgid =0
if(this.discussionArr.length>0){
lastmsgid= Number(this.discussionArr[this.discussionArr.length - 1].id) + 1
}
}
else {
console.log("Already generating");
}
}
}).catch((error) => {
console.log("Error: Could not get generation status", error);
});
},
sendMsg(msg) {
@ -1518,6 +1539,7 @@ export default {
},
async created() {
this.$store.state.isConnected=false;
axios.get('/get_lollms_webui_version', {}).then((res) => {
if (res) {
this.version = res.data.version
@ -1528,6 +1550,21 @@ export default {
this.$nextTick(() => {
feather.replace();
});
socket.onclose = (event) => {
console.log('WebSocket connection closed:', event.code, event.reason);
this.socketIODisconnected();
};
socket.onerror = (event) => {
console.log('WebSocket connection error:', event.code, event.reason);
this.socketIODisconnected();
socket.disconnect();
};
socket.on('connected',this.socketIOConnected)
socket.on('disconnected',this.socketIODisconnected)
console.log("Added events")
console.log("Waiting to be ready")
while (this.$store.state.ready === false) {
await new Promise((resolve) => setTimeout(resolve, 100)); // Wait for 100ms
@ -1548,19 +1585,23 @@ export default {
socket.on('update_message', this.streamMessageContent)
socket.on('close_message', this.finalMsgEvent)
console.log("Setting events")
socket.onopen = () => {
console.log('WebSocket connection established.');
this.socketIOConnected();
if (this.currentDiscussion!=null){
this.setPageTitle(item)
localStorage.setItem('selected_discussion', this.currentDiscussion.id)
this.load_discussion(item.id, ()=>{
if (this.discussionArr.length > 1) {
if (this.currentDiscussion.title === '' || this.currentDiscussion.title === null) {
this.changeTitleUsingUserMSG(this.currentDiscussion.id, this.discussionArr[1].content)
}
}
});
}
};
socket.onclose = (event) => {
console.log('WebSocket connection closed:', event.code, event.reason);
this.socketIODisconnected();
};
socket.on('connected',this.socketIOConnected)
socket.on('disconnected',this.socketIODisconnected)
console.log("Added events")
this.isCreated = true
},