From 96bae501510b58b4c1ef9776bda12039654ab80d Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Thu, 13 Apr 2023 19:02:20 +0200 Subject: [PATCH] bugfix: the wait animation is back --- .gitignore | 10 ++++++-- app.py | 13 +++++++--- db.py | 1 + personalities/gpt4all_chatbot.yaml | 7 ++++-- static/css/chat.css | 38 ++++++++++++++++++++++++++++++ static/js/discussions.js | 5 ++-- 6 files changed, 65 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 0509a19a..eab2bd27 100644 --- a/.gitignore +++ b/.gitignore @@ -142,5 +142,11 @@ models/ # Temporary files tmp/ -# -llama.cpp +# configurations other than the default one +configs/* +!configs/default.yaml + +# personalities other than the default one +personalities/* +!personalities/gpt4all_chatbot.yaml + diff --git a/app.py b/app.py index f04b86e6..bd6f7267 100644 --- a/app.py +++ b/app.py @@ -40,6 +40,7 @@ class Gpt4AllWebUI: self.config = config self.personality = personality self.current_discussion = None + self.current_message_id = 0 self.app = _app self.db_path = config["db_path"] self.db = DiscussionsDB(self.db_path) @@ -152,8 +153,13 @@ class Gpt4AllWebUI: self.current_discussion = self.db.load_last_discussion() message_id = self.current_discussion.add_message( - "conditionner", conditionning_message, DiscussionsDB.MSG_TYPE_CONDITIONNING,0 + "conditionner", conditionning_message, DiscussionsDB.MSG_TYPE_CONDITIONNING,0,self.current_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 + ) + return message_id def prepare_query(self): @@ -255,7 +261,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.config["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() @@ -340,6 +346,7 @@ class Gpt4AllWebUI: 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'] app.config['executor'].submit(self.restore_discussion, self.full_message) return jsonify(messages) @@ -385,7 +392,7 @@ class Gpt4AllWebUI: self.full_message ="" # Return a success response - return json.dumps({"id": self.current_discussion.discussion_id, "time": timestamp}) + return json.dumps({"id": self.current_discussion.discussion_id, "time": timestamp, "welcome_message":self.personality["welcome_message"]}) def update_model_params(self): data = request.get_json() diff --git a/db.py b/db.py index 1d6ad32f..0ebd3d14 100644 --- a/db.py +++ b/db.py @@ -155,6 +155,7 @@ class DiscussionsDB: last_discussion_id = self.create_discussion() else: last_discussion_id=last_discussion_id[0] + self.current_message_id = self.select("SELECT id FROM message WHERE discussion_id=? ORDER BY id DESC LIMIT 1", (last_discussion_id,), fetch_all=False) return Discussion(last_discussion_id, self) def create_discussion(self, title="untitled"): diff --git a/personalities/gpt4all_chatbot.yaml b/personalities/gpt4all_chatbot.yaml index 96780480..1ab6a52c 100644 --- a/personalities/gpt4all_chatbot.yaml +++ b/personalities/gpt4all_chatbot.yaml @@ -4,14 +4,17 @@ # 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. - +# 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. - gpt4all:Welcome! I'm here to assist you with anything you need. What can I do for you today? +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 diff --git a/static/css/chat.css b/static/css/chat.css index 72fc3630..79c14ea9 100644 --- a/static/css/chat.css +++ b/static/css/chat.css @@ -1,3 +1,41 @@ +/* Wait animation */ +.lds-facebook { + display: inline-block; + position: relative; + width: 40px; + height: 40px; +} +.lds-facebook div { + display: inline-block; + position: absolute; + left: 8px; + width: 8px; + background: #fff; + animation: lds-facebook 1.2s cubic-bezier(0, 0.5, 0.5, 1) infinite; +} +.lds-facebook div:nth-child(1) { + left: 4px; + animation-delay: -0.24s; +} +.lds-facebook div:nth-child(2) { + left: 16px; + animation-delay: -0.12s; +} +.lds-facebook div:nth-child(3) { + left: 28px; + animation-delay: 0; +} +@keyframes lds-facebook { + 0% { + top: 8px; + height: 34px; + } + 50%, 100% { + top: 12px; + height: 18px; + } +} + :root { --color-primary-light: #ffffff; --color-secondary-light: #f2f2f2; diff --git a/static/js/discussions.js b/static/js/discussions.js index 72715b21..de5a4541 100644 --- a/static/js/discussions.js +++ b/static/js/discussions.js @@ -215,11 +215,12 @@ newDiscussionBtn.addEventListener('click', () => { fetch(`/new_discussion?title=${discussionName}`) .then(response => response.json()) .then(data => { - console.log(`New chat ${data}`) + console.log(`New chat ${data.welcome_message}`) // Select the new discussion //selectDiscussion(discussionId); chatWindow.innerHTML="" - addMessage("GPT4ALL", welcome_message,0); + addMessage("GPT4ALL", data.welcome_message,0); + populate_discussions_list() sendbtn.style.display="block"; waitAnimation.style.display="none";