Upgraded code

This commit is contained in:
Saifeddine ALOUI 2023-04-13 21:40:46 +02:00
parent 96bae50151
commit 7e5cbfdc15
6 changed files with 103 additions and 17 deletions

37
app.py
View File

@ -136,8 +136,6 @@ class Gpt4AllWebUI:
def prepare_a_new_chatbot(self):
# Create chatbot
self.chatbot_bindings = self.create_chatbot()
# Chatbot conditionning
self.condition_chatbot(self.personality["personality_conditionning"])
def create_chatbot(self):
@ -148,18 +146,26 @@ class Gpt4AllWebUI:
)
def condition_chatbot(self, conditionning_message):
self.full_message += conditionning_message
if self.current_discussion is None:
self.current_discussion = self.db.load_last_discussion()
message_id = self.current_discussion.add_message(
"conditionner", conditionning_message, DiscussionsDB.MSG_TYPE_CONDITIONNING,0,self.current_message_id
"conditionner",
conditionning_message,
DiscussionsDB.MSG_TYPE_CONDITIONNING,
0,
self.current_message_id
)
self.current_message_id = message_id
if self.personality["welcome_message"]!="":
message_id = self.current_discussion.add_message(
"gpt4all", self.personality["welcome_message"], DiscussionsDB.MSG_TYPE_CONDITIONNING,0,self.current_message_id
self.personality["name"], self.personality["welcome_message"],
DiscussionsDB.MSG_TYPE_NORMAL,
0,
self.current_message_id
)
self.current_message_id = message_id
return message_id
def prepare_query(self):
@ -243,7 +249,7 @@ class Gpt4AllWebUI:
print(f"Received message : {message}")
# First we need to send the new message ID to the client
response_id = self.current_discussion.add_message(
"GPT4All", ""
self.personality["name"], ""
) # first the content is empty, but we'll fill it at the end
yield (
json.dumps(
@ -261,7 +267,7 @@ class Gpt4AllWebUI:
self.full_message_list.append(self.current_message)
if len(self.full_message_list) > self.config["nb_messages_to_remember"]:
self.prompt_message = [self.personality["personality_conditionning"]]+ '\n'.join(self.full_message_list[-self.config["nb_messages_to_remember"]:])
self.prompt_message = self.personality["personality_conditionning"]+ '\n'.join(self.full_message_list[-self.config["nb_messages_to_remember"]:])
else:
self.prompt_message = self.full_message
self.prepare_query()
@ -333,20 +339,23 @@ class Gpt4AllWebUI:
data = request.get_json()
if "id" in data:
discussion_id = data["id"]
self.current_discussion = Discussion(discussion_id, self.db)
else:
if self.current_discussion is not None:
discussion_id = self.current_discussion.discussion_id
self.current_discussion = Discussion(discussion_id, self.db)
else:
discussion_id = self.db.create_discussion()
self.current_discussion = Discussion(discussion_id, self.db)
self.current_discussion = self.db.create_discussion()
messages = self.current_discussion.get_messages()
self.full_message = ""
self.full_message_list = []
for message in messages:
self.full_message += message['sender'] + ": " + message['content'] + "\n"
self.full_message_list.append(message['sender'] + ": " + message['content'])
self.current_message_id=message['id']
if message['sender']!="conditionner":
self.full_message += message['sender'] + ": " + message['content'] + "\n"
self.full_message_list.append(message['sender'] + ": " + message['content'])
self.current_message_id=message['id']
app.config['executor'].submit(self.restore_discussion, self.full_message)
return jsonify(messages)
@ -391,6 +400,10 @@ class Gpt4AllWebUI:
self.full_message =""
# Chatbot conditionning
self.condition_chatbot(self.personality["personality_conditionning"])
# Return a success response
return json.dumps({"id": self.current_discussion.discussion_id, "time": timestamp, "welcome_message":self.personality["welcome_message"]})

3
db.py
View File

@ -256,7 +256,8 @@ class Discussion:
rows = self.discussions_db.select(
f"SELECT * FROM message WHERE discussion_id={self.discussion_id}"
)
return [{"id": row[0], "sender": row[1], "content": row[2], "type": row[3], "rank": row[4]} for row in rows]
return [{"id": row[0], "sender": row[1], "content": row[2], "type": row[3], "rank": row[4], "parent": row[5]} for row in rows]
def update_message(self, message_id, new_content):
"""Updates the content of a message

View File

@ -1,27 +1,41 @@
# GPT4All Chatbot conditionning file
# Author : @ParisNeo
# Version : 1.0
# Description :
# An NLP needs conditionning to instruct it to be whatever we want it to be.
# This file is used by the GPT4All web ui to condition the personality of the model you are
# talking to.
# Name of the personality
name: gpt4all
# Language (see the list of supported languages here : https://github.com/ParisNeo/GPT4All_Personalities/blob/main/README.md)
language: "en_XX"
# Category
category: "General"
# Personality description:
personality_description: |
This personality is a helpful and Kind AI ready to help you solve your problems
# The conditionning instructions sent to eh model at the start of the discussion
personality_conditionning: |
Instruction: Act as gpt4all. A kind and helpful AI bot built to help users solve problems.
#Welcome message to be sent to the user when a new discussion is started
welcome_message: "Welcome! I am GPT4All A free and open discussion AI. What can I do for you today?"
# This prefix is added at the beginning of any message input by the user
message_prefix: "\nuser:"
# This suffix is added at the end of any message input by the user
message_suffix: "\ngpt4all:"
# Here is the list of extensions this personality requires
dependencies: []
# Some personalities need a disclaimer to warn the user of potential harm that can be caused by the AI
# for example, for medical assistants, it is important to tell the user to be careful and not use medication
# without advise from a real docor.
disclaimer: ""
disclaimer: ""

View File

@ -1,9 +1,13 @@
function load_discussion(discussion=0){
if(discussion)
{
console.log(discussion.id)
body = { id: discussion.id }
else
}
else{
body = { }
}
// send query with discussion id to reveal discussion messages
fetch('/load_discussion', {
method: 'POST',
@ -21,7 +25,9 @@ function load_discussion(discussion=0){
var container = document.getElementById('chat-window');
container.innerHTML = '';
messages.forEach(message => {
console.log(`Adding message ${message.type}`)
if(message.type==0){
console.log("Showing message")
addMessage(message.sender, message.content, message.id, message.rank, true);
}
});
@ -152,8 +158,8 @@ function populate_discussions_list()
discussionButton.classList.add('bg-green-500', 'hover:bg-green-700', 'text-white', 'font-bold', 'py-2', 'px-4', 'rounded', 'ml-2', 'w-full');
discussionButton.textContent = discussion.title;
discussionButton.addEventListener('click', () => {
load_discussion(discussion);
console.log(`Showing messages for discussion ${discussion.id}`);
load_discussion(discussion);
});

View File

@ -56,8 +56,9 @@ function update_main(){
{
// We parse it and
infos = JSON.parse(text)
console.log(infos)
addMessage('User', infos.message, infos.id, 0, can_edit=true);
elements = addMessage('GPT4ALL', '', infos.response_id, 0, can_edit=true);
elements = addMessage(infos.sender, '', infos.response_id, 0, can_edit=true);
messageTextElement=elements['messageTextElement'];
hiddenElement=elements['hiddenElement'];
entry_counter ++;

51
update.bat Normal file
View File

@ -0,0 +1,51 @@
echo off
echo HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHH .HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHH. ,HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHH.## HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHHHH#.HHHHH/*,*,*,*,*,*,*,*,***,*,**#HHHHHHHHHHHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHHHHHH.*,,***,***,***,***,***,***,*******HHHHHHHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHHHH*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*,,,,,HHHHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHH.,,,***,***,***,***,***,***,***,***,***,***/HHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHH*,,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*HHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHH#,***,***,***,***,***,***,***,***,***,***,***,**HHHHHHHHHHHHHHHHH
echo HHHHHHHHHH..HHH,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*#HHHHHHHHHHHHHHHH
echo HHHHHHH,,,**,/H*,***,***,***,,,*,***,***,***,**,,,**,***,***,***H,,*,***HHHHHHHH
echo HHHHHH.*,,,*,,,,,*,*,*,***#HHHHH.,,*,*,*,*,**/HHHHH.,*,*,*,*,*,*,*,*****HHHHHHHH
echo HHHHHH.*,***,*,*,***,***,.HHHHHHH/**,***,****HHHHHHH.***,***,***,*******HHHHHHHH
echo HHHHHH.,,,,,,,,,,,,,,,,,,,.HHHHH.,,,,,,,,,,,,.HHHHHH,,,,,,,,,,,,,,,,,***HHHHHHHH
echo HHHHHH.,,,,,,/H,,,**,***,***,,,*,***,***,***,**,,,,*,***,***,***H***,***HHHHHHHH
echo HHHHHHH.,,,,*.H,,,,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,***H*,,,,/HHHHHHHHH
echo HHHHHHHHHHHHHHH*,***,***,**,,***,***,***,***,***,***,***,***,**.HHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHH,,,,,,,,*,,#H#,,,,,*,,,*,,,,,,,,*#H*,,,,,,,,,**HHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHH,,*,***,***,**/.HHHHHHHHHHHHH#*,,,*,***,***,*HHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHHH,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*HHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHHH**,***,***,***,***,***,***,***,***,***,***,*.HHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHHH*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*HHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHHH**,***,***,*******/..HHHHHHHHH.#/*,*,,,***,***HHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHH*,*,*,******#HHHHHHHHHHHHHHHHHHHHHHHHHHHH./**,,,.HHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHH.,,*,***.HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH.*#HHHHHHHHHHHH
echo HHHHHHHHHHHHHHH/,,,*.HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHH,,#HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHH.HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
echo HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
REM Activate the virtual environment
call env\Scripts\activate.bat
REM Pull latest version of the code
git pull
REM Download latest personalities
if not exist tmp\personalities git clone https://github.com/ParisNeo/GPT4All_Personalities.git tmp\personalities
copy tmp\personalities\* personalities
echo Cleaning tmp folder
rd /s /q "./tmp"
pause