Skip to content

Commit

Permalink
Moving to webSocket format for text streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
saloui authored and ParisNeo committed Apr 27, 2023
1 parent a886789 commit 2ae9f97
Show file tree
Hide file tree
Showing 5 changed files with 6,067 additions and 5 deletions.
20 changes: 17 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,26 @@
stream_with_context,
send_from_directory
)
from flask_socketio import SocketIO
from pathlib import Path
import gc
app = Flask("GPT4All-WebUI", static_url_path="/static", static_folder="static")
socketio = SocketIO(app)

import time
from pyGpt4All.config import load_config, save_config
from pyGpt4All.api import GPT4AllAPI
import shutil
import markdown


class Gpt4AllWebUI(GPT4AllAPI):
def __init__(self, _app, config:dict, personality:dict, config_file_path) -> None:
def __init__(self, _app, _socketio, config:dict, personality:dict, config_file_path) -> None:
super().__init__(config, personality, config_file_path)

self.app = _app
self.cancel_gen = False
self.socketio = _socketio


self.add_endpoint(
Expand Down Expand Up @@ -291,6 +297,15 @@ def parse_to_prompt_stream(self, message, message_id):
yield "FINAL:"+bot_says
self.cancel_gen = False
return bot_says


# Socket IO stuff
@socketio.on('connected')
def handle_connection(self, data):
self.socketio.emit('message', {'data': 'WebSocket connected!'})

for i in range(10):
socketio.emit('message', {'data': 'Message ' + str(i)})

def generate(self):

Expand Down Expand Up @@ -591,8 +606,7 @@ def extensions(self):

# executor = ThreadPoolExecutor(max_workers=1)
# app.config['executor'] = executor

bot = Gpt4AllWebUI(app, config, personality, config_file_path)
bot = Gpt4AllWebUI(app, socketio, config, personality, config_file_path)

if config["debug"]:
app.run(debug=True, host=config["host"], port=config["port"])
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
flask
flask_socketio
nomic
pytest
pyyaml
Expand Down
3 changes: 2 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
flask
flask_socketio
nomic
pytest
pyyaml
markdown
pyllamacpp==1.0.6
pyllamacpp==1.0.7
gpt4all-j
transformers
Loading

0 comments on commit 2ae9f97

Please sign in to comment.