This commit is contained in:
Saifeddine ALOUI 2023-07-15 23:06:28 +02:00
parent 7cb99bb8e6
commit 831b3ea6fb
8 changed files with 108 additions and 107 deletions

View File

@ -444,13 +444,14 @@ class LoLLMsAPPI(LollmsApplication):
@socketio.on('generate_msg_from')
def handle_connection(data):
client_id = request.sid
message_id = int(data['id'])
id_ = data['id']
message_id = int(id_)
if message_id==-1:
message_id = self.message_id
self.message_id = message_id
message = ""
else:
message = data["prompt"]
self.current_user_message_id = message_id
self.current_user_message_id = message_id
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()
@ -550,6 +551,9 @@ class LoLLMsAPPI(LollmsApplication):
@property
def message_id(self):
return self._message_id
@message_id.setter
def message_id(self, id):
self._message_id=id
@property
def current_user_message_id(self):
@ -639,34 +643,34 @@ class LoLLMsAPPI(LollmsApplication):
def prepare_query(self, message_id=-1, is_continue=False):
messages = self.current_discussion.get_messages()
self.full_message_list = []
for message in messages:
if message["id"]< message_id or message_id==-1:
for i, message in enumerate(messages):
if message["id"]< message_id or (message_id==-1 and i<len(messages)-1):
if message["type"]<=MSG_TYPE.MSG_TYPE_FULL_INVISIBLE_TO_USER.value and message["type"]!=MSG_TYPE.MSG_TYPE_FULL_INVISIBLE_TO_AI.value:
if message["sender"]==self.personality.name:
self.full_message_list.append(self.personality.ai_message_prefix+message["content"])
else:
self.full_message_list.append(self.personality.user_message_prefix + message["content"])
self.full_message_list.append("\n!@>"+message["sender"]+": "+message["content"].strip())
else:
break
link_text = self.personality.link_text
if not is_continue:
self.full_message_list.append(self.personality.user_message_prefix+message["content"]+self.personality.link_text+self.personality.ai_message_prefix)
self.full_message_list.append("\n!@>"+message["sender"]+": "+message["content"].strip()+self.personality.link_text+self.personality.ai_message_prefix)
else:
self.full_message_list.append(self.personality.ai_message_prefix+message["content"])
self.full_message_list.append("\n!@>"+message["sender"]+": "+message["content"].strip())
messages = link_text.join(self.full_message_list)
t = self.model.tokenize(messages)
composed_messages = link_text.join(self.full_message_list)
t = self.model.tokenize(composed_messages)
n_t = len(t)
max_prompt_stx_size = 3*int(self.config.ctx_size/4)
if self.n_cond_tk+n_t>max_prompt_stx_size:
nb_tk = max_prompt_stx_size-self.n_cond_tk
messages = self.model.detokenize(t[-nb_tk:])
composed_messages = self.model.detokenize(t[-nb_tk:])
ASCIIColors.warning(f"Cropping discussion to fit context [using {nb_tk} tokens/{self.config.ctx_size}]")
discussion_messages = self.personality.personality_conditioning+ messages
discussion_messages = self.personality.personality_conditioning+ composed_messages
tokens = self.model.tokenize(discussion_messages)
if self.config["debug"]:
ASCIIColors.yellow(discussion_messages)
return discussion_messages, message["content"], tokens
def get_discussion_to(self, message_id=-1):

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-60b5747e.js"></script>
<link rel="stylesheet" href="/assets/index-192e1418.css">
<script type="module" crossorigin src="/assets/index-d843c7fd.js"></script>
<link rel="stylesheet" href="/assets/index-7d5b903d.css">
</head>
<body>
<div id="app"></div>

View File

@ -227,30 +227,18 @@ export default {
feather.replace()
console.log('ppa', pers)
if (pers) {
if (pers.selected) {
this.$refs.toast.showToast("Personality already selected", 4, true)
return
}
if (pers.isMounted) {
const res = await this.select_personality(pers)
if (res) {
if (res.status) {
await this.constructor()
this.$refs.toast.showToast("Selected personality:\n" + pers.name, 4, true)
this.onTalk(pers)
}
}
} else {
this.onPersonalityMounted(pers)
}
this.onTalk(pers)
}
},
@ -266,8 +254,6 @@ export default {
}
if (pers.isMounted) {
const res = await this.select_personality(pers)

View File

@ -60,12 +60,7 @@ export default {
computed:{
...mapState(['isConnected']),
// Add a watcher to log the changes
isConnectedWatcher: {
handler(newValue) {
console.log('isConnected:', newValue);
},
immediate: true,
}
},
data() {
return {

View File

@ -23,14 +23,6 @@ socket.onerror = (error) => {
socket.disconnect()
};
socket.on("connect", () => {
console.log('WebSocket connected (websocket)');
});
socket.on("disconnect", () => {
console.log('WebSocket disonnected (websocket)');
});
// const app = createApp(/* your root component */);
// app.config.globalProperties.$socket = socket;

View File

@ -51,12 +51,10 @@
<i data-feather="database"></i>
</button>
<input type="file" ref="fileDialog" style="display: none" @change="importDiscussions" />
<div @click="toggleDropdown" class="text-2xl hover:text-secondary duration-75">
<i data-feather="import"></i>
</div>
<div @click="toggleDropdown" class="text-2xl hover:text-secondary duration-75">
<i data-feather="log-in"></i>
</div>
<button class="text-2xl hover:text-secondary duration-75 active:scale-90 rotate-90"
title="Import discussions" type="button" @click.stop="$refs.fileDialog.click()">
<i data-feather="log-in"></i>
</button>
<div v-if="isOpen" class="dropdown">
<button @click="importDiscussions">LOLLMS</button>
@ -359,14 +357,10 @@ export default {
fileList: [],
isDragOverDiscussion: false,
isDragOverChat: false,
panelCollapsed: false // left panel collapse
panelCollapsed: false, // left panel collapse
isOpen: false
}
},
data() {
return {
isOpen: false
}
},
methods: {
showToastMessage(text){
console.log("sending",text)
@ -412,6 +406,7 @@ export default {
async load_discussion(id) {
try {
if (id) {
console.log("Loading discussion", id)
this.loading = true
this.discussionArr=[]
this.setDiscussionLoading(id, this.loading)
@ -607,10 +602,9 @@ export default {
},
async selectDiscussion(item) {
if (item) {
console.log("this.currentDiscussion",this.currentDiscussion)
// When discussion is selected it loads the discussion array
if (this.currentDiscussion.id != item.id) {
if (this.currentDiscussion===undefined) {
this.currentDiscussion = item
this.setPageTitle(item)
@ -624,7 +618,27 @@ export default {
this.changeTitleUsingUserMSG(this.currentDiscussion.id, this.discussionArr[1].content)
}
}
}
else{
if (this.currentDiscussion.id != item.id) {
this.currentDiscussion = item
this.setPageTitle(item)
localStorage.setItem('selected_discussion', this.currentDiscussion.id)
await 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)
}
}
}
}
nextTick(() => {
@ -814,6 +828,7 @@ export default {
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
@ -941,7 +956,9 @@ export default {
},
loadLastUsedDiscussion() {
// Checks local storage for last selected discussion
console.log("Loading last discussion")
const id = localStorage.getItem('selected_discussion')
console.log("Last discussion id: ",id)
if (id) {
const index = this.list.findIndex((x) => x.id == id)
const discussionItem = this.list[index]
@ -1026,6 +1043,7 @@ export default {
this.isSelectAll = !this.isSelectAll
},
createDiscussionList(disList) {
console.log("Creating discussions list", disList)
// This creates a discussion list for UI with additional properties
if (disList) {
const newDisList = disList.map((item) => {
@ -1042,9 +1060,10 @@ export default {
}).sort(function (a, b) {
return b.id - a.id
})
this.list = newDisList
this.tempList = newDisList
console.log("List created")
}
},
setDiscussionLoading(id, loading) {
@ -1411,16 +1430,22 @@ export default {
},
async created() {
this.$nextTick(() => {
feather.replace();
});
console.log("Waiting to be ready")
while (this.$store.state.ready === false) {
await new Promise((resolve) => setTimeout(resolve, 100)); // Wait for 100ms
}
// Constructor
console.log("Setting title")
this.setPageTitle()
console.log("listing discussions")
await this.list_discussions()
console.log("loading last discussion")
this.loadLastUsedDiscussion()
this.isCreated = true
console.log("Discussions view is ready")
nextTick(() => {
feather.replace()
})
// socket responses
socket.on('infos', this.createBotMsg)
@ -1429,18 +1454,16 @@ export default {
socket.on('connected',this.socketIOConnected)
socket.on('disconnected',this.socketIODisconnected)
console.log("Added events")
this.isCreated = true
},
mounted() {
//console.log('chatbox mnt',this.$refs)
this.$nextTick(() => {
feather.replace();
});
},
async activated() {
//console.log('settings changed', this.$store.state.mountedPersonalities)
// This lifecycle hook runs every time you switch from other page back to this page (vue-router)
// To fix scrolling back to last message, this hook is needed.
// If anyone knows hor to fix scroll issue when changing pages, please do fix it :D
console.log("Websocket connected (activated)", this.socketConnected)
//console.log('settings changed acc', this.$store.state.settingsChanged)
// await this.getPersonalityAvatars()
await this.getPersonalityAvatars()
@ -1498,18 +1521,19 @@ export default {
},
computed: {
isReady(){
return this.$store.state.ready
console.log("verify ready", this.isCreated)
return this.isCreated
},
showPanel() {
return this.$store.state.ready && !this.panelCollapsed;
},
socketConnected() {
console.log(" --- > Websocket connected")
this.$store.state.isConnected=true;// ('setConnectionStatus', true);
this.$store.commit('setIsConnected', true);
return true
},
socketDisconnected() {
this.$store.state.isConnected=false;// .$store.commit('setConnectionStatus', false);
this.$store.commit('setIsConnected', false);
console.log(" --- > Websocket disconnected")
return true
},