2023-06-14 15:23:13 +00:00
|
|
|
import { createApp, ref } from 'vue'
|
2023-06-13 15:09:25 +00:00
|
|
|
import { createStore } from 'vuex'
|
2023-07-09 17:32:25 +00:00
|
|
|
import axios from "axios";
|
2023-05-02 20:53:27 +00:00
|
|
|
import App from './App.vue'
|
|
|
|
import router from './router'
|
|
|
|
|
|
|
|
import './assets/tailwind.css'
|
|
|
|
|
|
|
|
const app = createApp(App)
|
2023-07-09 17:32:25 +00:00
|
|
|
console.log("Loaded main.js")
|
2023-05-02 20:53:27 +00:00
|
|
|
|
2023-06-13 15:09:25 +00:00
|
|
|
// Create a new store instance.
|
2023-07-06 17:19:48 +00:00
|
|
|
export const store = createStore({
|
2023-06-13 15:09:25 +00:00
|
|
|
state () {
|
|
|
|
return {
|
2023-06-17 10:53:40 +00:00
|
|
|
// count: 0,
|
2023-07-10 20:01:20 +00:00
|
|
|
ready:false,
|
2023-09-02 18:37:06 +00:00
|
|
|
version : "unknown",
|
|
|
|
refreshingModelsList:false,
|
2023-07-06 11:47:23 +00:00
|
|
|
settingsChanged:false,
|
|
|
|
isConnected: false, // Add the isConnected property
|
2023-07-09 17:32:25 +00:00
|
|
|
config:null,
|
|
|
|
mountedPers:null,
|
2023-07-10 22:45:47 +00:00
|
|
|
mountedPersArr:null,
|
2023-07-10 20:01:20 +00:00
|
|
|
bindingsArr:null,
|
|
|
|
modelsArr:null,
|
|
|
|
models_zoo:null,
|
2023-07-09 17:32:25 +00:00
|
|
|
personalities:null,
|
2023-07-10 20:01:20 +00:00
|
|
|
diskUsage:null,
|
|
|
|
ramUsage:null,
|
|
|
|
vramUsage:null,
|
2023-07-20 09:44:33 +00:00
|
|
|
extensionsZoo:null,
|
2023-06-13 15:09:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mutations: {
|
2023-07-10 20:01:20 +00:00
|
|
|
setIsConnected(state, isConnected) {
|
|
|
|
state.isConnected = isConnected;
|
|
|
|
},
|
2023-07-09 17:32:25 +00:00
|
|
|
setConfig(state, config) {
|
|
|
|
state.config = config;
|
|
|
|
},
|
|
|
|
setPersonalities(state, personalities) {
|
|
|
|
state.personalities = personalities;
|
|
|
|
},
|
|
|
|
setMountedPers(state, mountedPers) {
|
|
|
|
state.mountedPers = mountedPers;
|
|
|
|
},
|
2023-07-10 22:45:47 +00:00
|
|
|
setMountedPersArr(state, mountedPersArr) {
|
|
|
|
state.mountedPersArr = mountedPersArr;
|
|
|
|
},
|
2023-07-10 20:01:20 +00:00
|
|
|
setBindingsArr(state, bindingsArr) {
|
|
|
|
state.bindingsArr = bindingsArr;
|
|
|
|
},
|
|
|
|
setModelsArr(state, modelsArr) {
|
|
|
|
state.modelsArr = modelsArr;
|
|
|
|
},
|
|
|
|
setDiskUsage(state, diskUsage) {
|
|
|
|
state.diskUsage = diskUsage;
|
|
|
|
},
|
|
|
|
setRamUsage(state, ramUsage) {
|
|
|
|
state.ramUsage = ramUsage;
|
|
|
|
},
|
|
|
|
setVramUsage(state, vramUsage) {
|
|
|
|
state.vramUsage = vramUsage;
|
|
|
|
},
|
|
|
|
|
2023-07-20 09:44:33 +00:00
|
|
|
setExtensionsZoo(state, extensionsZoo) {
|
|
|
|
state.extensionsZoo = extensionsZoo;
|
|
|
|
},
|
2023-07-10 20:01:20 +00:00
|
|
|
setModelsZoo(state, modelsZoo) {
|
|
|
|
state.models_zoo = modelsZoo;
|
|
|
|
},
|
2023-06-17 10:53:40 +00:00
|
|
|
// increment (state) {
|
|
|
|
// state.count++
|
2023-07-06 17:19:48 +00:00
|
|
|
// }
|
2023-07-09 17:32:25 +00:00
|
|
|
},
|
|
|
|
getters: {
|
2023-07-10 20:01:20 +00:00
|
|
|
getIsConnected(state) {
|
|
|
|
return state.isConnected
|
|
|
|
},
|
2023-07-09 17:32:25 +00:00
|
|
|
getConfig(state) {
|
|
|
|
return state.config
|
|
|
|
},
|
2023-07-10 20:01:20 +00:00
|
|
|
getPersonalities(state) {
|
|
|
|
return state.personalities;
|
2023-07-09 17:32:25 +00:00
|
|
|
},
|
2023-07-10 22:45:47 +00:00
|
|
|
getMountedPersArr(state) {
|
|
|
|
return state.mountedPersArr;
|
|
|
|
},
|
2023-07-09 17:32:25 +00:00
|
|
|
getMountedPers(state) {
|
|
|
|
return state.mountedPers;
|
2023-07-10 20:01:20 +00:00
|
|
|
},
|
|
|
|
getbindingsArr(state) {
|
|
|
|
return state.bindingsArr;
|
|
|
|
},
|
|
|
|
getModelsArr(state) {
|
|
|
|
return state.modelsArr;
|
|
|
|
},
|
|
|
|
getDiskUsage(state) {
|
|
|
|
return state.diskUsage;
|
|
|
|
},
|
|
|
|
getRamUsage(state) {
|
|
|
|
return state.ramUsage;
|
|
|
|
},
|
|
|
|
getVramUsage(state) {
|
|
|
|
return state.vramUsage;
|
|
|
|
},
|
|
|
|
getModelsZoo(state) {
|
|
|
|
return state.models_zoo;
|
|
|
|
},
|
2023-07-20 09:44:33 +00:00
|
|
|
getExtensionsZoo(state) {
|
|
|
|
return state.extensionsZoo;
|
|
|
|
},
|
2023-07-09 17:32:25 +00:00
|
|
|
},
|
|
|
|
actions: {
|
2023-09-02 18:37:06 +00:00
|
|
|
async getVersion(){
|
|
|
|
let res = await axios.get('/get_lollms_webui_version', {});
|
|
|
|
if (res) {
|
|
|
|
this.state.version = res.data.version
|
|
|
|
}
|
|
|
|
},
|
2023-07-09 17:32:25 +00:00
|
|
|
async refreshConfig({ commit }) {
|
|
|
|
console.log("Fetching configuration");
|
|
|
|
try {
|
2023-07-10 22:45:47 +00:00
|
|
|
const configFile = await api_get_req('get_config')
|
|
|
|
let personality_path_infos = configFile.personalities[configFile.active_personality_id].split("/")
|
|
|
|
//let personality_path_infos = await this.api_get_req("get_current_personality_path_infos")
|
2023-08-17 23:29:53 +00:00
|
|
|
configFile.personality_category = personality_path_infos[0]
|
|
|
|
configFile.personality_folder = personality_path_infos[1]
|
2023-08-25 19:47:28 +00:00
|
|
|
console.log("Recovered config")
|
|
|
|
console.log(configFile)
|
2023-07-09 17:32:25 +00:00
|
|
|
commit('setConfig', configFile);
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error.message, 'refreshConfig');
|
|
|
|
// Handle error
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async refreshPersonalitiesArr({ commit }) {
|
|
|
|
let personalities = []
|
2023-08-17 23:29:53 +00:00
|
|
|
const catdictionary = await api_get_req("get_all_personalities")
|
|
|
|
const catkeys = Object.keys(catdictionary); // returns categories
|
2023-08-25 19:47:28 +00:00
|
|
|
console.log("Personalities recovered:"+this.state.config.personalities)
|
2023-07-09 17:32:25 +00:00
|
|
|
|
2023-08-17 23:29:53 +00:00
|
|
|
for (let j = 0; j < catkeys.length; j++) {
|
|
|
|
const catkey = catkeys[j];
|
|
|
|
const personalitiesArray = catdictionary[catkey];
|
|
|
|
const modPersArr = personalitiesArray.map((item) => {
|
|
|
|
const isMounted = this.state.config.personalities.includes(catkey + '/' + item.folder)
|
|
|
|
// if (isMounted) {
|
|
|
|
// console.log(item)
|
|
|
|
// }
|
|
|
|
let newItem = {}
|
|
|
|
newItem = item
|
|
|
|
newItem.category = catkey // add new props to items
|
|
|
|
newItem.full_path = catkey + '/' + item.folder // add new props to items
|
|
|
|
newItem.isMounted = isMounted // add new props to items
|
|
|
|
return newItem
|
|
|
|
})
|
2023-07-09 17:32:25 +00:00
|
|
|
|
|
|
|
|
2023-08-17 23:29:53 +00:00
|
|
|
if (personalities.length == 0) {
|
|
|
|
personalities = modPersArr
|
|
|
|
} else {
|
|
|
|
personalities = personalities.concat(modPersArr)
|
2023-07-09 17:32:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
personalities.sort((a, b) => a.name.localeCompare(b.name))
|
2023-07-15 21:06:27 +00:00
|
|
|
|
2023-07-10 20:01:20 +00:00
|
|
|
commit('setPersonalities', personalities);
|
2023-07-09 17:32:25 +00:00
|
|
|
|
2023-07-10 20:01:20 +00:00
|
|
|
console.log("Done loading personalities")
|
2023-07-09 17:32:25 +00:00
|
|
|
},
|
|
|
|
refreshMountedPersonalities({ commit }) {
|
|
|
|
let mountedPersArr = []
|
|
|
|
// console.log('perrs listo',this.state.personalities)
|
|
|
|
for (let i = 0; i < this.state.config.personalities.length; i++) {
|
|
|
|
const full_path_item = this.state.config.personalities[i]
|
|
|
|
const index = this.state.personalities.findIndex(item => item.full_path == full_path_item)
|
|
|
|
|
|
|
|
const pers = this.state.personalities[index]
|
|
|
|
if (pers) {
|
|
|
|
mountedPersArr.push(pers)
|
|
|
|
}
|
|
|
|
else {
|
2023-08-25 19:47:28 +00:00
|
|
|
mountedPersArr.push(this.state.personalities[this.state.personalities.findIndex(item => item.full_path == "generic/lollms")])
|
2023-07-09 17:32:25 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-21 21:59:24 +00:00
|
|
|
console.log("Personalities list",this.state.personalities)
|
2023-07-10 22:45:47 +00:00
|
|
|
commit('setMountedPersArr', mountedPersArr);
|
2023-07-21 21:59:24 +00:00
|
|
|
|
|
|
|
console.log("active_personality_id",this.state.config.active_personality_id)
|
|
|
|
console.log("selected pers",this.state.config.personalities[this.state.config.active_personality_id])
|
2023-07-09 17:32:25 +00:00
|
|
|
this.state.mountedPers = this.state.personalities[this.state.personalities.findIndex(item => item.full_path == this.state.config.personalities[this.state.config.active_personality_id])]
|
2023-07-21 21:59:24 +00:00
|
|
|
console.log("selected pers",this.state.mountedPers)
|
|
|
|
|
2023-07-09 17:32:25 +00:00
|
|
|
},
|
2023-07-10 20:01:20 +00:00
|
|
|
async refreshBindings({ commit }) {
|
|
|
|
let bindingsArr = await api_get_req("list_bindings")
|
|
|
|
commit('setBindingsArr',bindingsArr)
|
|
|
|
},
|
|
|
|
async refreshModels({ commit }) {
|
|
|
|
let modelsArr = await api_get_req("list_models")
|
|
|
|
commit('setModelsArr',modelsArr)
|
|
|
|
},
|
2023-07-20 09:44:33 +00:00
|
|
|
async refreshExtensionsZoo({ commit }) {
|
|
|
|
let extensionsZoo = await api_get_req("list_extensions")
|
|
|
|
commit('setExtensionsZoo',extensionsZoo)
|
|
|
|
},
|
2023-07-10 20:01:20 +00:00
|
|
|
|
|
|
|
async refreshDiskUsage({ commit }) {
|
|
|
|
this.state.diskUsage = await api_get_req("disk_usage")
|
|
|
|
},
|
|
|
|
async refreshRamUsage({ commit }) {
|
|
|
|
this.state.ramUsage = await api_get_req("ram_usage")
|
|
|
|
},
|
|
|
|
async refreshVramUsage({ commit }) {
|
|
|
|
console.log("getting gpu data")
|
|
|
|
const resp = await api_get_req("vram_usage")
|
|
|
|
// {
|
|
|
|
// "gpu_0_total_vram": 11811160064,
|
|
|
|
// "gpu_0_used_vram": 3177185280,
|
|
|
|
// "nb_gpus": 1
|
|
|
|
// }
|
|
|
|
|
|
|
|
const gpuArr = []
|
|
|
|
|
|
|
|
if (resp.nb_gpus > 0) {
|
|
|
|
// Get keys
|
|
|
|
const keys = Object.keys(resp)
|
|
|
|
// for each gpu
|
|
|
|
for (let i = 0; i < resp.nb_gpus; i++) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const total_vram = resp[`gpu_${i}_total_vram`];
|
|
|
|
const used_vram = resp[`gpu_${i}_used_vram`];
|
|
|
|
const model = resp[`gpu_${i}_model`];
|
|
|
|
const percentage = (used_vram / total_vram) * 100
|
|
|
|
const available_space = total_vram - used_vram
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpuArr.push({
|
|
|
|
total_vram: total_vram,
|
|
|
|
used_vram: used_vram,
|
|
|
|
gpu_index: i,
|
|
|
|
gpu_model: model,
|
|
|
|
percentage: percentage.toFixed(2),
|
|
|
|
available_space: available_space
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
const result = {
|
|
|
|
|
|
|
|
"nb_gpus": resp.nb_gpus,
|
|
|
|
"gpus": gpuArr
|
|
|
|
}
|
|
|
|
console.log('gpu usage: ',result)
|
|
|
|
this.state.vramUsage = result
|
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
const result = {
|
|
|
|
"nb_gpus": 0,
|
|
|
|
"gpus": []
|
|
|
|
}
|
|
|
|
console.log('gpu usage: ',result)
|
|
|
|
this.state.vramUsage = result
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
async refreshModelsZoo({ commit }) {
|
|
|
|
console.log("Refreshing models zoo")
|
2023-09-02 18:37:06 +00:00
|
|
|
this.state.refreshingModelsList=true;
|
2023-07-10 20:01:20 +00:00
|
|
|
axios.get('/get_available_models')
|
|
|
|
.then(response => {
|
2023-07-10 22:45:47 +00:00
|
|
|
console.log("found models")
|
2023-07-10 20:01:20 +00:00
|
|
|
let models_zoo = response.data
|
|
|
|
models_zoo.sort((a, b) => a.title.localeCompare(b.title))
|
|
|
|
|
|
|
|
// Returns array of model filenames which are = to title of models zoo entry
|
|
|
|
for (let i = 0; i < this.state.modelsArr.length; i++) {
|
|
|
|
const customModel = this.state.modelsArr[i]
|
|
|
|
const index = models_zoo.findIndex(x => x.title == customModel)
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
let newModelEntry = {}
|
|
|
|
newModelEntry.title = customModel
|
|
|
|
newModelEntry.path = customModel
|
|
|
|
newModelEntry.icon = ""
|
|
|
|
newModelEntry.isCustomModel = true
|
|
|
|
newModelEntry.isInstalled = true
|
|
|
|
models_zoo.push(newModelEntry)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
models_zoo.sort((a, b) => {
|
|
|
|
if (a.isInstalled && !b.isInstalled) {
|
|
|
|
return -1; // a is installed, b is not installed, so a comes first
|
|
|
|
} else if (!a.isInstalled && b.isInstalled) {
|
|
|
|
return 1; // b is installed, a is not installed, so b comes first
|
|
|
|
} else {
|
|
|
|
return 0; // both models are either installed or not installed, maintain their original order
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
models_zoo.forEach(model => {
|
|
|
|
if (model.title == this.state.config["model_name"]) {
|
|
|
|
model.selected = true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
model.selected = false;
|
|
|
|
}
|
|
|
|
});
|
2023-07-10 22:45:47 +00:00
|
|
|
commit('setModelsZoo', models_zoo)
|
2023-07-10 20:01:20 +00:00
|
|
|
console.log("Models zoo loaded successfully")
|
2023-09-02 18:37:06 +00:00
|
|
|
this.state.refreshingModelsList=false;
|
2023-07-10 20:01:20 +00:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error.message, 'fetchModels');
|
2023-09-02 18:37:06 +00:00
|
|
|
this.state.refreshingModelsList=false;
|
2023-07-10 20:01:20 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchCustomModels({ commit }) {
|
|
|
|
axios.get('/list_models')
|
|
|
|
.then(response => {
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error.message, 'fetchCustomModels');
|
|
|
|
});
|
|
|
|
},
|
2023-07-09 17:32:25 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
async function api_get_req(endpoint) {
|
|
|
|
try {
|
|
|
|
const res = await axios.get('/' + endpoint);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
return res.data;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error.message, 'api_get_req');
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let actionsExecuted = false;
|
|
|
|
|
|
|
|
app.mixin({
|
2023-07-10 20:01:20 +00:00
|
|
|
created() {
|
2023-07-09 17:32:25 +00:00
|
|
|
if (!actionsExecuted) {
|
|
|
|
actionsExecuted = true;
|
2023-07-10 20:01:20 +00:00
|
|
|
console.log("Calling")
|
2023-09-02 18:37:06 +00:00
|
|
|
this.$store.dispatch('refreshConfig').then(async () => {
|
|
|
|
console.log("recovered config");
|
|
|
|
await this.$store.dispatch('getVersion');
|
|
|
|
console.log("recovered version");
|
|
|
|
await this.$store.dispatch('refreshPersonalitiesArr')
|
|
|
|
|
2023-07-09 17:32:25 +00:00
|
|
|
this.$store.dispatch('refreshMountedPersonalities');
|
2023-07-10 20:01:20 +00:00
|
|
|
this.$store.dispatch('refreshBindings');
|
|
|
|
this.$store.dispatch('refreshModels');
|
|
|
|
|
|
|
|
this.$store.dispatch('refreshDiskUsage');
|
|
|
|
this.$store.dispatch('refreshRamUsage');
|
|
|
|
this.$store.dispatch('refreshVramUsage');
|
|
|
|
this.$store.dispatch('refreshModelsZoo');
|
2023-07-20 09:44:33 +00:00
|
|
|
this.$store.dispatch('refreshExtensionsZoo');
|
|
|
|
|
2023-07-10 20:01:20 +00:00
|
|
|
|
|
|
|
this.$store.state.ready = true
|
|
|
|
console.log("done loading data")
|
2023-07-09 17:32:25 +00:00
|
|
|
});
|
2023-06-13 15:09:25 +00:00
|
|
|
}
|
2023-07-10 20:01:20 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
beforeMount() {
|
2023-07-09 17:32:25 +00:00
|
|
|
}
|
|
|
|
})
|
2023-05-02 20:53:27 +00:00
|
|
|
app.use(router)
|
2023-06-13 15:09:25 +00:00
|
|
|
app.use(store)
|
2023-07-10 20:01:20 +00:00
|
|
|
app.mount('#app')
|
2023-05-02 20:53:27 +00:00
|
|
|
|