From 10dea92101e684c357411eec086f79665f824d70 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Mon, 10 Apr 2023 20:58:53 +0200 Subject: [PATCH] Bugfix for first time db --- db.py | 6 +++++- static/js/chat.js | 6 +++--- templates/chat.html | 28 ++++++++++++++-------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/db.py b/db.py index 44d359e2..a36304e6 100644 --- a/db.py +++ b/db.py @@ -127,7 +127,11 @@ class DiscussionsDB: conn.commit() def load_last_discussion(self): - last_discussion_id = self.select("SELECT id FROM discussions ORDER BY id DESC LIMIT 1", fetch_all=False)[0] + last_discussion_id = self.select("SELECT id FROM discussions ORDER BY id DESC LIMIT 1", fetch_all=False) + if last_discussion_id is None: + last_discussion_id = self.create_discussion() + else: + last_discussion_id=last_discussion_id[0] return Discussion(last_discussion_id, self) def create_discussion(self, title="untitled"): diff --git a/static/js/chat.js b/static/js/chat.js index eb863347..f7ec28e5 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -55,8 +55,8 @@ chatForm.addEventListener('submit', event => { { // We parse it and infos = JSON.parse(text) - addMessage('User', infos.message, infos.id, can_edit=true); - elements = addMessage('GPT4ALL', '', infos.response_id, can_edit=true); + addMessage('User', infos.message, infos.id, 0, can_edit=true); + elements = addMessage('GPT4ALL', '', infos.response_id, 0, can_edit=true); messageTextElement=elements['messageTextElement']; hiddenElement=elements['hiddenElement']; entry_counter ++; @@ -264,7 +264,7 @@ Examples: Welcome! I'm here to assist you with anything you need. What can I do for you today? `; -addMessage("GPT4ALL",welcome_message,0); +addMessage("GPT4ALL",welcome_message,0,0,false); // Code for collapsable text const collapsibles = document.querySelectorAll('.collapsible'); diff --git a/templates/chat.html b/templates/chat.html index e817b583..cbf5c15a 100644 --- a/templates/chat.html +++ b/templates/chat.html @@ -21,10 +21,9 @@ -
-
-
-
+
+
+
-
-
+
+
+
+
+ + + +
-
+
-
+
@@ -94,11 +99,6 @@
- - - - -