From e97e6ca3a89f3fa47940424c7104572bce84358c Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Sun, 28 May 2023 08:47:57 +0200 Subject: [PATCH] Added get available space --- .gitignore | 5 ++++- api/langchain.py | 1 + app.py | 13 +++++++++++++ docs/dev/server_endpoints.md | 15 +++++++++++++++ requirements.txt | 2 ++ shared/.keep | 0 6 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 api/langchain.py create mode 100644 shared/.keep diff --git a/.gitignore b/.gitignore index aa3551e6..330eb981 100644 --- a/.gitignore +++ b/.gitignore @@ -177,4 +177,7 @@ outputs # ignore installation files .installed -test.http \ No newline at end of file +test.http + +shared/* +!shared/.keep \ No newline at end of file diff --git a/api/langchain.py b/api/langchain.py new file mode 100644 index 00000000..28be258f --- /dev/null +++ b/api/langchain.py @@ -0,0 +1 @@ +# TODO : implement \ No newline at end of file diff --git a/app.py b/app.py index e69aa2b4..bda6e536 100644 --- a/app.py +++ b/app.py @@ -44,6 +44,8 @@ from gevent.pywsgi import WSGIServer import requests from concurrent.futures import ThreadPoolExecutor, as_completed import logging +import psutil + log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) @@ -82,6 +84,11 @@ class Gpt4AllWebUI(GPT4AllAPI): # ========================================================================================= + self.add_endpoint( + "/get_available_space", "get_available_space", self.get_available_space, methods=["GET"] + ) + + self.add_endpoint( "/list_bindings", "list_bindings", self.list_bindings, methods=["GET"] ) @@ -461,6 +468,12 @@ class Gpt4AllWebUI(GPT4AllAPI): print("Set config results:") print(result) return jsonify(result) + + def get_available_space(self): + current_drive = Path.cwd().anchor + disk_usage = psutil.disk_usage(current_drive) + available_space = disk_usage.free + return jsonify({"available_space":available_space}) def list_bindings(self): bindings_dir = Path('./bindings') # replace with the actual path to the models folder diff --git a/docs/dev/server_endpoints.md b/docs/dev/server_endpoints.md index 8246938f..22e2454f 100644 --- a/docs/dev/server_endpoints.md +++ b/docs/dev/server_endpoints.md @@ -240,6 +240,21 @@ This Flask server provides various endpoints to manage and interact with the cha - "/help": GET request endpoint to display the help page. - "/get_all_personalities": GET request endpoint to get all personalities array - "/get_personality": GET request endpoint to get speciffic data based on request +- "/get_available_space": GET request endpoint to retrieve the available space in the current folder's drive. + Method: GET + Description: Retrieves the available space in bytes for the current folder's drive. + Response: + Content-Type: application/json + Body: JSON object with a single entry 'available_space' containing the available space in bytes. + Example Response: + json + Copy code + { + "available_space": 1234567890 + } + Example Usage: + Request: GET /disk_space + Response: 200 OK ## TODO Endpoints: diff --git a/requirements.txt b/requirements.txt index 72f433a8..2e132e08 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ tqdm +psutil flask flask_socketio pytest @@ -7,3 +8,4 @@ markdown gevent gevent-websocket pyaipersonality>=0.0.14 +langchain \ No newline at end of file diff --git a/shared/.keep b/shared/.keep new file mode 100644 index 00000000..e69de29b