From 42da16a0ca844d0da85ff1a4e66d035532af759f Mon Sep 17 00:00:00 2001 From: saloui Date: Tue, 2 May 2023 14:16:10 +0200 Subject: [PATCH] pyllamacpp version 2.1.1 --- .gitignore | 5 ++ app.py | 1 + .../english/general/gpt4all/config.yaml | 6 +- pyGpt4All/api.py | 1 + static/js/chat.js | 4 +- static/js/main.js | 71 +------------------ static/js/websocket.js | 66 +++++++++++++++++ templates/index.html | 1 + 8 files changed, 79 insertions(+), 76 deletions(-) create mode 100644 static/js/websocket.js diff --git a/.gitignore b/.gitignore index a729f041..b1245204 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,8 @@ databases/* # extensions extensions/ !extensions/.keep + +# backends +backends/ +!backends/llama_cpp +!backends/__init__.py \ No newline at end of file diff --git a/app.py b/app.py index c301d2a5..c700385f 100644 --- a/app.py +++ b/app.py @@ -337,6 +337,7 @@ class Gpt4AllWebUI(GPT4AllAPI): print() print("## Done ##") print() + self.cancel_gen = False return "" diff --git a/personalities/english/general/gpt4all/config.yaml b/personalities/english/general/gpt4all/config.yaml index 84692e5d..32d0cde9 100644 --- a/personalities/english/general/gpt4all/config.yaml +++ b/personalities/english/general/gpt4all/config.yaml @@ -30,19 +30,19 @@ personality_description: | # The conditionning instructions sent to eh model at the start of the discussion personality_conditioning: | - ##Instructions:GPT4All is a smart and helpful Assistant built by Nomic-AI. It can discuss with humans and assist them. + ##Instructions:\nGPT4All is a smart and helpful Assistant built by Nomic-AI. It can discuss with humans and assist them. #Welcome message to be sent to the user when a new discussion is started welcome_message: "Welcome! I am GPT4All A free and open assistant. What can I do for you today?" # This prefix is added at the beginning of any message input by the user -user_message_prefix: "##Human:" +user_message_prefix: "##Human:\n" # A text to put between user and chatbot messages link_text: "\n" # This prefix is added at the beginning of any message output by the ai -ai_message_prefix: "##Assistant:" +ai_message_prefix: "##Assistant:\n" # Here is the list of extensions this personality requires dependencies: [] diff --git a/pyGpt4All/api.py b/pyGpt4All/api.py index ed717fd1..31e151e1 100644 --- a/pyGpt4All/api.py +++ b/pyGpt4All/api.py @@ -181,6 +181,7 @@ class GPT4AllAPI(): self.socketio.emit('message', {'data': self.bot_says}); if self.cancel_gen: print("Generation canceled") + self.cancel_gen = False return False else: return True diff --git a/static/js/chat.js b/static/js/chat.js index 45c9da62..40f48ffa 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -90,9 +90,7 @@ function addMessage(sender, message, id, rank = 0, can_edit = false) { globals.user_msg = undefined // scroll to bottom of chat window chatWindow.scrollTop = chatWindow.scrollHeight; - send_message('generate_msg_from',{prompt: message, id: messageElement.id}) - entry_counter = 0; - + send_message('generate_msg_from',{prompt: message, id: messageElement.id}) }); diff --git a/static/js/main.js b/static/js/main.js index 2aa975e8..cf909744 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1,71 +1,3 @@ -var globals={ - is_generating:false, - chatWindow:undefined, - chatForm:undefined, - userInput:undefined, - stopGeneration:undefined, - sendbtn:undefined, - waitAnimation:undefined -} - -function send_message(service_name, parameters){ - var socket = io.connect('http://' + document.domain + ':' + location.port); - globals.socket = socket - globals.is_generating = false - socket.on('connect', function() { - entry_counter = 0; - if(globals.is_generating){ - globals.socket.disconnect() - } - else{ - globals.socket.emit(service_name, parameters); - globals.is_generating = true - } - - }); - socket.on('disconnect', function() { - console.log("disconnected") - entry_counter = 0; - console.log("Disconnected") - globals.sendbtn.style.display="block"; - globals.waitAnimation.style.display="none"; - globals.stopGeneration.style.display = "none"; - }); - - - socket.on('infos', function(msg) { - if(globals.user_msg){ - globals.user_msg.setSender(msg.user); - globals.user_msg.setMessage(msg.message); - globals.user_msg.setID(msg.id); - } - globals.bot_msg.setSender(msg.bot); - globals.bot_msg.setID(msg.response_id); - globals.bot_msg.messageTextElement.innerHTML = `Generating answer. Please stand by...`; - }); - - socket.on('waiter', function(msg) { - globals.bot_msg.messageTextElement.innerHTML = `Generating answer. Please stand by...`; - }); - - socket.on('message', function(msg) { - text = msg.data; - // For the other enrtries, these are just the text of the chatbot - - globals.bot_msg.messageTextElement.innerHTML = marked.marked(text); - // scroll to bottom of chat window - globals.chatWindow.scrollTop = globals.chatWindow.scrollHeight; - }); - - socket.on('final',function(msg){ - text = msg.data; - globals.bot_msg.hiddenElement.innerHTML = text - globals.bot_msg.messageTextElement.innerHTML = marked.marked(text) - socket.disconnect() - - }); -} - function update_main(){ globals.chatWindow = document.getElementById('chat-window'); globals.chatForm = document.getElementById('chat-form'); @@ -81,7 +13,7 @@ function update_main(){ .then(response => response.json()) .then(data => { console.log(data); - socket.disconnect() + globals.is_generating = true }); }) @@ -103,7 +35,6 @@ function update_main(){ // scroll to bottom of chat window globals.chatWindow.scrollTop = globals.chatWindow.scrollHeight; - entry_counter = 0; send_message('generate_msg',{prompt: message}) diff --git a/static/js/websocket.js b/static/js/websocket.js new file mode 100644 index 00000000..1e3b40d3 --- /dev/null +++ b/static/js/websocket.js @@ -0,0 +1,66 @@ +// Project : GPT4ALL-ui +// Author : ParisNeo +// Description : +// All websocket stuff can be found here. + + +var globals={ + is_generating:false, + chatWindow:undefined, + chatForm:undefined, + userInput:undefined, + stopGeneration:undefined, + sendbtn:undefined, + waitAnimation:undefined +} + +var socket = io.connect('http://' + document.domain + ':' + location.port); + +socket.on('connect', function() { +}); +socket.on('disconnect', function() { +console.log("Disconnected") +}); +socket.on('infos', function(msg) { +if(globals.user_msg){ + globals.user_msg.setSender(msg.user); + globals.user_msg.setMessage(msg.message); + globals.user_msg.setID(msg.id); +} +globals.bot_msg.setSender(msg.bot); +globals.bot_msg.setID(msg.response_id); +globals.bot_msg.messageTextElement.innerHTML = `Generating answer. Please stand by...`; +}); + +socket.on('waiter', function(msg) { +globals.bot_msg.messageTextElement.innerHTML = `Generating answer. Please stand by...`; +}); + +socket.on('message', function(msg) { + text = msg.data; + // For the other enrtries, these are just the text of the chatbot + + globals.bot_msg.messageTextElement.innerHTML = marked.marked(text); + // scroll to bottom of chat window + globals.chatWindow.scrollTop = globals.chatWindow.scrollHeight; +}); + +socket.on('final',function(msg){ +text = msg.data; +globals.bot_msg.hiddenElement.innerHTML = text +globals.bot_msg.messageTextElement.innerHTML = marked.marked(text) +globals.sendbtn.style.display="block"; +globals.waitAnimation.style.display="none"; +globals.stopGeneration.style.display = "none"; +globals.is_generating = false +}); + +globals.socket = socket +globals.is_generating = false + +function send_message(service_name, parameters){ + if(!globals.is_generating){ + globals.socket.emit(service_name, parameters); + globals.is_generating = true + } +} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 0c444b02..504f98b1 100644 --- a/templates/index.html +++ b/templates/index.html @@ -56,6 +56,7 @@ +