This commit is contained in:
Saifeddine ALOUI 2023-12-06 01:28:13 +01:00
parent 328b9f6d2e
commit 7a9ccac548
10 changed files with 178 additions and 84 deletions

View File

@ -1480,11 +1480,17 @@ class LoLLMsAPI(LollmsApplication):
def notify(self, content, status=True, duration=4, client_id=None): def notify(self, content, status=True, duration=4, client_id=None, notification_type=0):
"""
notification type is:
0 : suddle
1 : Critical (shows a message box )
"""
self.socketio.emit('notification', { self.socketio.emit('notification', {
'content': content,# self.connections[client_id]["generated_text"], 'content': content,# self.connections[client_id]["generated_text"],
'status': status, 'status': status,
"duration": duration "duration": duration,
'notification_type':notification_type
}, room=client_id }, room=client_id
) )

121
app.py
View File

@ -269,6 +269,7 @@ try:
self.add_endpoint("/install_model_from_path", "install_model_from_path", self.install_model_from_path, methods=["GET"]) self.add_endpoint("/install_model_from_path", "install_model_from_path", self.install_model_from_path, methods=["GET"])
self.add_endpoint("/install_binding", "install_binding", self.install_binding, methods=["POST"])
self.add_endpoint("/unInstall_binding", "unInstall_binding", self.unInstall_binding, methods=["POST"]) self.add_endpoint("/unInstall_binding", "unInstall_binding", self.unInstall_binding, methods=["POST"])
self.add_endpoint("/reinstall_binding", "reinstall_binding", self.reinstall_binding, methods=["POST"]) self.add_endpoint("/reinstall_binding", "reinstall_binding", self.reinstall_binding, methods=["POST"])
self.add_endpoint("/reinstall_personality", "reinstall_personality", self.reinstall_personality, methods=["POST"]) self.add_endpoint("/reinstall_personality", "reinstall_personality", self.reinstall_personality, methods=["POST"])
@ -917,6 +918,32 @@ try:
elif setting_name== "override_personality_model_parameters": elif setting_name== "override_personality_model_parameters":
self.config["override_personality_model_parameters"]=bool(data['setting_value']) self.config["override_personality_model_parameters"]=bool(data['setting_value'])
elif setting_name== "binding_name":
if self.config['binding_name']!= data['setting_value']:
print(f"New binding selected : {data['setting_value']}")
self.config["binding_name"]=data['setting_value']
try:
if self.binding:
self.binding.destroy_model()
self.binding = None
self.model = None
for per in self.mounted_personalities:
per.model = None
gc.collect()
self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths, InstallOption.INSTALL_IF_NECESSARY, self.notify)
self.model = None
self.config.save_config()
ASCIIColors.green("Binding loaded successfully")
except Exception as ex:
ASCIIColors.error(f"Couldn't build binding: [{ex}]")
trace_exception(ex)
return jsonify({"status":False, 'error':str(ex)})
else:
if self.config["debug"]:
print(f"Configuration {data['setting_name']} set to {data['setting_value']}")
return jsonify({'setting_name': data['setting_name'], "status":True})
elif setting_name == "model_name": elif setting_name == "model_name":
ASCIIColors.yellow(f"Changing model to: {data['setting_value']}") ASCIIColors.yellow(f"Changing model to: {data['setting_value']}")
self.config["model_name"]=data['setting_value'] self.config["model_name"]=data['setting_value']
@ -933,30 +960,6 @@ try:
except Exception as ex: except Exception as ex:
self.notify("It looks like you we couldn't load the model.\nThis can hapen when you don't have enough VRAM. Please restart the program.",False,30) self.notify("It looks like you we couldn't load the model.\nThis can hapen when you don't have enough VRAM. Please restart the program.",False,30)
elif setting_name== "binding_name":
if self.config['binding_name']!= data['setting_value']:
print(f"New binding selected : {data['setting_value']}")
self.config["binding_name"]=data['setting_value']
try:
if self.binding:
self.binding.destroy_model()
self.binding = None
self.model = None
for per in self.mounted_personalities:
per.model = None
gc.collect()
self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths, self.notify)
self.model = None
self.config.save_config()
ASCIIColors.green("Model loaded successfully")
except Exception as ex:
ASCIIColors.error(f"Couldn't build binding: [{ex}]")
trace_exception(ex)
return jsonify({"status":False, 'error':str(ex)})
else:
if self.config["debug"]:
print(f"Configuration {data['setting_name']} set to {data['setting_value']}")
return jsonify({'setting_name': data['setting_name'], "status":True})
else: else:
if data['setting_name'] in self.config.config.keys(): if data['setting_name'] in self.config.config.keys():
@ -1264,10 +1267,10 @@ try:
save_db=True save_db=True
) )
ASCIIColors.yellow("1- Exporting discussions") ASCIIColors.yellow("1- Exporting discussions")
self.notify("Exporting discussions",True, None) self.notify("Exporting discussions")
discussions = self.db.export_all_as_markdown_list_for_vectorization() discussions = self.db.export_all_as_markdown_list_for_vectorization()
ASCIIColors.yellow("2- Adding discussions to vectorizer") ASCIIColors.yellow("2- Adding discussions to vectorizer")
self.notify("Adding discussions to vectorizer",True, None) self.notify("Adding discussions to vectorizer")
index = 0 index = 0
nb_discussions = len(discussions) nb_discussions = len(discussions)
@ -1557,6 +1560,35 @@ try:
else: else:
return jsonify({}) return jsonify({})
def install_binding(self):
try:
data = request.get_json()
# Further processing of the data
except Exception as e:
print(f"Error occurred while parsing JSON: {e}")
return jsonify({"status":False, 'error':str(e)})
ASCIIColors.info(f"- Reinstalling binding {data['name']}...")
try:
ASCIIColors.info("Unmounting binding and model")
ASCIIColors.info("Reinstalling binding")
old_bn = self.config.binding_name
self.config.binding_name = data['name']
self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths, InstallOption.FORCE_INSTALL, self.notify)
ASCIIColors.success("Binding reinstalled successfully")
self.notify("Please reboot the application so that the binding installation can be taken into consideration",True, 30, notification_type=1)
del self.binding
self.binding = None
self.config.binding_name = old_bn
if old_bn is not None:
self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths, self.notify)
self.model = self.binding.build_model()
for per in self.mounted_personalities:
per.model = self.model
return jsonify({"status": True})
except Exception as ex:
ASCIIColors.error(f"Couldn't build binding: [{ex}]")
trace_exception(ex)
return jsonify({"status":False, 'error':str(ex)})
def reinstall_binding(self): def reinstall_binding(self):
try: try:
@ -1568,8 +1600,7 @@ try:
ASCIIColors.info(f"- Reinstalling binding {data['name']}...") ASCIIColors.info(f"- Reinstalling binding {data['name']}...")
try: try:
ASCIIColors.info("Unmounting binding and model") ASCIIColors.info("Unmounting binding and model")
GG = AdvancedGarbageCollector() del self.binding
GG.safeHardCollect("binding", self)
self.binding = None self.binding = None
gc.collect() gc.collect()
ASCIIColors.info("Reinstalling binding") ASCIIColors.info("Reinstalling binding")
@ -1577,7 +1608,7 @@ try:
self.config.binding_name = data['name'] self.config.binding_name = data['name']
self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths, InstallOption.FORCE_INSTALL, self.notify) self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths, InstallOption.FORCE_INSTALL, self.notify)
ASCIIColors.success("Binding reinstalled successfully") ASCIIColors.success("Binding reinstalled successfully")
self.notify("<b>Please reboot the application so that the binding installation</b>",True, 30) self.notify("Please reboot the application so that the binding installation can be taken into consideration",True, 30, 1)
self.config.binding_name = old_bn self.config.binding_name = old_bn
self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths, self.notify) self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths, self.notify)
self.model = self.binding.build_model() self.model = self.binding.build_model()
@ -1596,26 +1627,28 @@ try:
except Exception as e: except Exception as e:
print(f"Error occurred while parsing JSON: {e}") print(f"Error occurred while parsing JSON: {e}")
return jsonify({"status":False, 'error':str(e)}) return jsonify({"status":False, 'error':str(e)})
ASCIIColors.info(f"- UnInstalling binding {data['name']}...") ASCIIColors.info(f"- Reinstalling binding {data['name']}...")
try: try:
ASCIIColors.info("Unmounting binding and model") ASCIIColors.info("Unmounting binding and model")
self.binding = None if self.binding is not None:
self.model = None del self.binding
for per in self.mounted_personalities: self.binding = None
per.model = None gc.collect()
gc.collect() ASCIIColors.info("Uninstalling binding")
ASCIIColors.info("UnInstalling binding") old_bn = self.config.binding_name
self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths, InstallOption.FORCE_INSTALL, self.notify) self.config.binding_name = data['name']
self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths, InstallOption.NEVER_INSTALL, self.notify)
self.binding.uninstall() self.binding.uninstall()
ASCIIColors.success("Binding UnInstalled successfully") ASCIIColors.green("Uninstalled successful")
self.config.binding_name= None if old_bn!=self.config.binding_name:
if self.config.auto_save: self.config.binding_name = old_bn
ASCIIColors.info("Saving configuration") self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths, self.notify)
self.config.save_config() self.model = self.binding.build_model()
ASCIIColors.info("Please select a binding") for per in self.mounted_personalities:
per.model = self.model
return jsonify({"status": True}) return jsonify({"status": True})
except Exception as ex: except Exception as ex:
ASCIIColors.error(f"Couldn't uninstall binding: [{ex}]") ASCIIColors.error(f"Couldn't build binding: [{ex}]")
trace_exception(ex) trace_exception(ex)
return jsonify({"status":False, 'error':str(ex)}) return jsonify({"status":False, 'error':str(ex)})

@ -1 +1 @@
Subproject commit 8388d197d2b72a42f270761fd4ba9fd7b757e321 Subproject commit dfb5470d8d63927de91d0589229712290e13a6e4

@ -1 +1 @@
Subproject commit 425f7614df835e6bb9d01e8be1ea45593beb9b3a Subproject commit 65236d13731c2d890073979dfae0d934dfa5e7d5

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"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LoLLMS WebUI - Welcome</title> <title>LoLLMS WebUI - Welcome</title>
<script type="module" crossorigin src="/assets/index-db4abb7a.js"></script> <script type="module" crossorigin src="/assets/index-86f0c808.js"></script>
<link rel="stylesheet" href="/assets/index-ad7cb3e8.css"> <link rel="stylesheet" href="/assets/index-cb75143a.css">
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

View File

@ -373,10 +373,10 @@ export default {
data() { data() {
return { return {
host:"", host:"",
progress_visibility_val : true,
progress_value : 0,
// To be synced with the backend database types // To be synced with the backend database types
msgTypes: { msgTypes: {
progress_visibility_val : true,
progress_value : 0,
// Messaging // Messaging
MSG_TYPE_CHUNK : 0, // A chunk of a message (used for classical chat) MSG_TYPE_CHUNK : 0, // A chunk of a message (used for classical chat)
MSG_TYPE_FULL : 1, // A full message (for some personality the answer is sent in bulk) MSG_TYPE_FULL : 1, // A full message (for some personality the answer is sent in bulk)
@ -1197,8 +1197,13 @@ export default {
nextTick(() => { nextTick(() => {
const msgList = document.getElementById('messages-list') const msgList = document.getElementById('messages-list')
this.scrollBottom(msgList) this.scrollBottom(msgList)
}) })
this.$refs.toast.showToast(notif.content, notif.duration, notif.status) if(notif.notification_type==0){
this.$refs.toast.showToast(notif.content, notif.duration, notif.status)
}
else if(notif.notification_type==1){
this.$refs.messageBox.showMessage(notif.content)
}
this.chime.play() this.chime.play()
}, },
streamMessageContent(msgObj) { streamMessageContent(msgObj) {

View File

@ -1757,7 +1757,7 @@ import YesNoDialog from "@/components/YesNoDialog.vue";
import Toast from '../components/Toast.vue' import Toast from '../components/Toast.vue'
import ModelEntry from '@/components/ModelEntry.vue'; import ModelEntry from '@/components/ModelEntry.vue';
import PersonalityViewer from '@/components/PersonalityViewer.vue'; import PersonalityViewer from '@/components/PersonalityViewer.vue';
import PersonalityEntry from "../components/PersonalityEntry.vue"; import PersonalityEntry from "@/components/PersonalityEntry.vue";
import BindingEntry from "../components/BindingEntry.vue"; import BindingEntry from "../components/BindingEntry.vue";
import socket from '@/services/websocket.js' import socket from '@/services/websocket.js'
import defaultModelImgPlaceholder from "../assets/default_model.png" import defaultModelImgPlaceholder from "../assets/default_model.png"
@ -1884,10 +1884,23 @@ export default {
async created() { async created() {
socket.on('loading_text',this.on_loading_text); socket.on('loading_text',this.on_loading_text);
this.updateHasUpdates(); this.updateHasUpdates();
socket.on('notification', this.notify)
//await socket.on('install_progress', this.progressListener); //await socket.on('install_progress', this.progressListener);
//refreshHardwareUsage() //refreshHardwareUsage()
}, },
methods: { methods: {
notify(notif){
nextTick(() => {
const msgList = document.getElementById('messages-list')
this.scrollBottom(msgList)
})
if(notif.notification_type==0){
this.$refs.toast.showToast(notif.content, notif.duration, notif.status)
}
else if(notif.notification_type==1){
this.$refs.messageBox.showMessage(notif.content)
}
},
load_more_models(){ load_more_models(){
if(this.models_zoo_initialLoadCount+10<this.models_zoo.length){ if(this.models_zoo_initialLoadCount+10<this.models_zoo.length){
this.models_zoo_initialLoadCount+=10 this.models_zoo_initialLoadCount+=10
@ -2623,30 +2636,63 @@ export default {
// return // return
// } // }
this.isLoading = true
if (binding_object.disclaimer){ if (binding_object.disclaimer){
this.$refs.yesNoDialog.askQuestion(binding_object.disclaimer, 'Proceed', 'Cancel') this.$refs.yesNoDialog.askQuestion(binding_object.disclaimer, 'Proceed', 'Cancel')
if (res) { }
this.update_binding(binding_object.binding.folder) axios.post('/install_binding', { name: binding_object.binding.folder }).then((res) => {
}
if (res) {
this.isLoading = false
console.log('install_binding', res)
if (res.data.status) {
this.$refs.toast.showToast("Installed binding successfully!", 4, true)
this.update_binding(binding_object.binding.folder);
} else {
this.$refs.toast.showToast("Could not reinstall binding", 4, false)
}
this.isLoading = false
return res.data;
} }
else{ this.isLoading = false
this.update_binding(binding_object.binding.folder) })
} // eslint-disable-next-line no-unused-vars
//console.log('lol',binding_object)
.catch(error => {
this.isLoading = false
this.$refs.toast.showToast("Could not reinstall binding\n" + error.message, 4, false)
return { 'status': false }
}); //console.log('lol',binding_object)
}
else{
this.update_binding(binding_object.binding.folder);
} }
}, },
onUnInstallBinding(binding_object){ onUnInstallBinding(binding_object){
this.isLoading = true this.isLoading = true
axios.post('/unInstall_binding', { name: binding_object.binding.folder }).then((res) => { axios.post('/unInstall_binding', { name: binding_object.binding.folder }).then((res) => {
if (res) { if (res) {
this.isLoading = false this.isLoading = false
console.log('unInstall_binding', res) console.log('unInstall_binding', res)
if (res.data.status) { if (res.data.status) {
this.$refs.toast.showToast("Reinstalled binding successfully!", 4, true) const index = this.bindingsZoo.findIndex(item => item.folder == binding_object.binding.folder)
const item = this.bindingsZoo[index]
if (item) {
item.installed = true
}
else{
item.installed = false
}
this.settingsChanged = true
this.binding_changed = true;
this.$refs.toast.showToast("Binding uninstalled successfully!", 4, true)
} else { } else {
this.$refs.toast.showToast("Could not reinstall binding", 4, false) this.$refs.toast.showToast("Could not uninstall binding", 4, false)
} }
return res.data; return res.data;
} }
@ -2658,7 +2704,7 @@ export default {
.catch(error => { .catch(error => {
this.isLoading = false this.isLoading = false
this.$refs.toast.showToast("Could not reinstall binding\n" + error.message, 4, false) this.$refs.toast.showToast("Could not uninstall binding\n" + error.message, 4, false)
return { 'status': false } return { 'status': false }
}); });
}, },
@ -2890,7 +2936,7 @@ export default {
this.isLoading = false this.isLoading = false
console.log('update_setting', res) console.log('update_setting', res)
if(res['status']){ if(res['status']){
this.$refs.toast.showToast("Setting updated successfully.\nDon't forget to save to keep the setting permanently.", 4, true) this.$refs.toast.showToast("Setting updated successfully.\n", 4, true)
} }
else{ else{
this.$refs.toast.showToast("Setting update failed.\nPlease view the console for more details.", 4, false) this.$refs.toast.showToast("Setting update failed.\nPlease view the console for more details.", 4, false)
@ -3033,6 +3079,9 @@ export default {
if (item) { if (item) {
item.installed = true item.installed = true
} }
else{
item.installed = false
}
this.settingsChanged = true this.settingsChanged = true
this.isLoading = false this.isLoading = false

@ -1 +1 @@
Subproject commit 8978a42f56eba0e3df8edf429ae5d30a400363fd Subproject commit 3a251d29f9939f4693a4282f7e97d98fa740ebee