This commit is contained in:
ParisNeo
2023-05-06 21:03:57 +02:00
parent 366cc0d56d
commit 2a78438a41
4 changed files with 119 additions and 5 deletions

36
app.py
View File

@ -270,11 +270,43 @@ class Gpt4AllWebUI(GPT4AllAPI):
self.config["language"]=data['setting_value']
elif setting_name== "personality_language":
self.config["personality_language"]=data['setting_value']
back_language = self.config["personality_language"]
if self.config["personality_language"]!=data['setting_value']:
self.config["personality_language"]=data['setting_value']
cats = self.list_personalities_categories()
if len(cats)>0:
back_category = self.config["personality_category"]
self.config["personality_category"]=cats[0]
pers = json.loads(self.list_personalities().data.decode("utf8"))
if len(pers)>0:
self.config["personality"]=pers[0]
personality_fn = f"personalities/{self.config['personality_language']}/{self.config['personality_category']}/{self.config['personality']}"
self.personality.load_personality(personality_fn)
else:
self.config["personality_language"]=back_language
self.config["personality_category"]=back_category
return jsonify({'setting_name': data['setting_name'], "status":False})
else:
self.config["personality_language"]=back_language
return jsonify({'setting_name': data['setting_name'], "status":False})
elif setting_name== "personality_category":
self.config["personality_category"]=data['setting_value']
back_category = self.config["personality_category"]
if self.config["personality_category"]!=data['setting_value']:
self.config["personality_category"]=data['setting_value']
pers = json.loads(self.list_personalities().data.decode("utf8"))
if len(pers)>0:
self.config["personality"]=pers[0]
personality_fn = f"personalities/{self.config['personality_language']}/{self.config['personality_category']}/{self.config['personality']}"
self.personality.load_personality(personality_fn)
else:
self.config["personality_category"]=back_category
return jsonify({'setting_name': data['setting_name'], "status":False})
elif setting_name== "personality":
self.config["personality"]=data['setting_value']
personality_fn = f"personalities/{self.config['personality_language']}/{self.config['personality_category']}/{self.config['personality']}"
self.personality.load_personality(personality_fn)
elif setting_name== "override_personality_model_parameters":
self.config["override_personality_model_parameters"]=bool(data['setting_value'])

View File

@ -1,6 +1,6 @@
<template>
<div v-if="show" class="fixed top-0 left-0 right-0 bottom-0 flex items-center justify-center bg-black bg-opacity-50">
<div class="bg-white p-8 rounded-lg shadow-lg">
<div class="bg-bg-light dark:bg-bg-dark p-8 rounded-lg shadow-lg">
<h3 class="text-lg font-medium">{{ message }}</h3>
<div class="mt-4 flex justify-end">
<button @click="hide" class="bg-secondary text-white px-4 py-2 rounded-lg shadow-lg hover:bg-secondary-dark">

View File

@ -0,0 +1,44 @@
<template>
<div v-if="show" class="fixed top-0 left-0 right-0 bottom-0 flex items-center justify-center bg-black bg-opacity-50">
<div class="bg-bg-light dark:bg-bg-dark p-8 rounded-lg shadow-lg">
<h3 class="text-lg font-medium">{{ message }}</h3>
<div class="mt-4 flex justify-end">
<button @click="hide(false)" class="bg-secondary text-white px-4 py-2 rounded-lg shadow-lg hover:bg-secondary-dark">
No
</button>
<button @click="hide(true)" class="bg-secondary text-white px-4 py-2 rounded-lg shadow-lg hover:bg-secondary-dark ml-4">
Yes
</button>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
show: false,
message: "",
resolve: null,
};
},
methods: {
hide(response) {
this.show = false;
if (this.resolve) {
this.resolve(response);
this.resolve = null;
}
},
askQuestion(message) {
return new Promise((resolve) => {
this.message = message;
this.show = true;
this.resolve = resolve;
});
},
},
};
</script>

View File

@ -10,7 +10,7 @@
</button>
</div>
<div class="overflow-y-scroll flex-col no-scrollbar shadow-lg bg-bg-light-tone dark:bg-bg-dark-tone ">
<button title="Reset configuration" class="text-2xl hover:text-secondary duration-75 active:scale-90 mr-2" @click="save_configuration()">
<button title="Reset configuration" class="text-2xl hover:text-secondary duration-75 active:scale-90 mr-2" @click="reset_configuration()">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
</svg>
@ -234,14 +234,21 @@
</div>
</div>
</div>
<YesNoDialog ref="yesNoDialog" />
<MessageBox ref="messageBox" />
</template>
<script>
import axios from "axios";
import MessageBox from "@/components/MessageBox.vue";
import YesNoDialog from "@/components/YesNoDialog.vue";
export default {
components: {
MessageBox,
},
setup() {
@ -267,6 +274,10 @@ export default {
}
}, methods: {
// messagebox ok stuff
onMessageBoxOk() {
console.log("OK button clicked");
},
// Refresh stuff
refresh(){
this.api_get_req("list_backends").then(response=>{this.backendsArr = response})
@ -306,9 +317,36 @@ export default {
})
.catch(error=>{
console.log(error)
this.$refs.messageBox.showMessage("Couldn't save settings!")
return {'status':false}
});
},
reset_configuration(){
this.$refs.yesNoDialog.askQuestion("Are you sure?<br>This will delete all your configurations and get back to default configuration.").then(response=>{
if (response) {
// User clicked Yes
axios.post('/reset_settings', {})
.then((res) => {
if (res) {
if(res.status)
this.$refs.messageBox.showMessage("Settings have been reset correctly")
else
this.$refs.messageBox.showMessage("Couldn't reset settings!")
return res.data;
}
})
.catch(error=>{
console.log(error)
this.$refs.messageBox.showMessage("Couldn't reset settings!")
return {'status':false}
});
// Perform delete operation
} else {
// User clicked No
// Do nothing
}
});
},
update_backend(value){
res = update_setting('backend', value)