From 6dfd473c446849556a8021a53acbb105f51e0457 Mon Sep 17 00:00:00 2001 From: saloui Date: Fri, 9 Jun 2023 16:49:13 +0200 Subject: [PATCH 1/2] Tested personalities mounting --- app.py | 31 ++++++++++++++----- .../list_mounted_personalities.http | 5 +++ tests/end_point_tests/mount_personality.http | 8 +++++ .../end_point_tests/unmount_personality.http | 8 +++++ {test => tests/unitary_tests}/test_app.py | 0 5 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 tests/end_point_tests/list_mounted_personalities.http create mode 100644 tests/end_point_tests/mount_personality.http create mode 100644 tests/end_point_tests/unmount_personality.http rename {test => tests/unitary_tests}/test_app.py (100%) diff --git a/app.py b/app.py index f8fe4d52..67f31fa3 100644 --- a/app.py +++ b/app.py @@ -89,6 +89,8 @@ class LoLLMsWebUI(LoLLMsAPPI): self.add_endpoint("/add_reference_to_local_model", "add_reference_to_local_model", self.add_reference_to_local_model, methods=["POST"]) self.add_endpoint("/send_file", "send_file", self.send_file, methods=["POST"]) + + self.add_endpoint("/list_mounted_personalities", "list_mounted_personalities", self.list_mounted_personalities, methods=["POST"]) self.add_endpoint("/mount_personality", "mount_personality", self.mount_personality, methods=["POST"]) self.add_endpoint("/unmount_personality", "unmount_personality", self.unmount_personality, methods=["POST"]) self.add_endpoint("/select_personality", "select_personality", self.select_personality, methods=["POST"]) @@ -674,6 +676,13 @@ class LoLLMsWebUI(LoLLMsAPPI): else: return jsonify({"status": True}) + def list_mounted_personalities(self): + print("- Listing mounted personalities") + return jsonify({"status": True, + "personalities":self.config["personalities"], + "active_personality_id":self.config["active_personality_id"] + }) + def mount_personality(self): print("- Mounting personality") @@ -705,10 +714,15 @@ class LoLLMsWebUI(LoLLMsAPPI): def unmount_personality(self): print("- Unmounting personality") - data = request.get_json() - language = data['language'] - category = data['category'] - name = data['name'] + try: + data = request.get_json() + # Further processing of the data + except Exception as e: + print(f"Error occurred while parsing JSON: {e}") + return + language = data['language'] + category = data['category'] + name = data['name'] try: index = self.config["personalities"].index(f"{language}/{category}/{name}") self.config["personalities"].remove(f"{language}/{category}/{name}") @@ -717,10 +731,11 @@ class LoLLMsWebUI(LoLLMsAPPI): self.personalities = self.process.rebuild_personalities() self.personality = self.personalities[self.config["active_personality_id"]] self.apply_settings() - return jsonify({"status": True, - "personalities":self.config["personalities"], - "active_personality_id":self.config["active_personality_id"] - }) + return jsonify({ + "status": True, + "personalities":self.config["personalities"], + "active_personality_id":self.config["active_personality_id"] + }) except: return jsonify({"status": False, "error":"Couldn't unmount personality"}) diff --git a/tests/end_point_tests/list_mounted_personalities.http b/tests/end_point_tests/list_mounted_personalities.http new file mode 100644 index 00000000..01cf461e --- /dev/null +++ b/tests/end_point_tests/list_mounted_personalities.http @@ -0,0 +1,5 @@ +POST http://localhost:9600/list_mounted_personalities +Content-Type: application/json + +{ +} \ No newline at end of file diff --git a/tests/end_point_tests/mount_personality.http b/tests/end_point_tests/mount_personality.http new file mode 100644 index 00000000..91a77197 --- /dev/null +++ b/tests/end_point_tests/mount_personality.http @@ -0,0 +1,8 @@ +POST http://localhost:9600/mount_personality +Content-Type: application/json + +{ + "language": "english", + "category": "generic", + "name": "gpt4all" +} \ No newline at end of file diff --git a/tests/end_point_tests/unmount_personality.http b/tests/end_point_tests/unmount_personality.http new file mode 100644 index 00000000..ca9c03aa --- /dev/null +++ b/tests/end_point_tests/unmount_personality.http @@ -0,0 +1,8 @@ +POST http://localhost:9600/unmount_personality +Content-Type: application/json + +{ + "language": "english", + "category": "generic", + "name": "lollms" +} diff --git a/test/test_app.py b/tests/unitary_tests/test_app.py similarity index 100% rename from test/test_app.py rename to tests/unitary_tests/test_app.py From ca66875180190db280c40e5cdbcea100a0ad9c73 Mon Sep 17 00:00:00 2001 From: saloui Date: Fri, 9 Jun 2023 16:51:27 +0200 Subject: [PATCH 2/2] upgraded unmount personalities --- app.py | 8 ++++++-- tests/end_point_tests/unmount_personality.http | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 67f31fa3..a053aab9 100644 --- a/app.py +++ b/app.py @@ -728,8 +728,12 @@ class LoLLMsWebUI(LoLLMsAPPI): self.config["personalities"].remove(f"{language}/{category}/{name}") if self.config["active_personality_id"]>=index: self.config["active_personality_id"]=0 - self.personalities = self.process.rebuild_personalities() - self.personality = self.personalities[self.config["active_personality_id"]] + if len(self.config["personalities"])>0: + self.personalities = self.process.rebuild_personalities() + self.personality = self.personalities[self.config["active_personality_id"]] + else: + self.personalities = [] + self.personality = None self.apply_settings() return jsonify({ "status": True, diff --git a/tests/end_point_tests/unmount_personality.http b/tests/end_point_tests/unmount_personality.http index ca9c03aa..a69e8eb2 100644 --- a/tests/end_point_tests/unmount_personality.http +++ b/tests/end_point_tests/unmount_personality.http @@ -4,5 +4,5 @@ Content-Type: application/json { "language": "english", "category": "generic", - "name": "lollms" + "name": "gpt4all" }