From 86c329982c630fe9bf5acd4e544a5a9ab5258936 Mon Sep 17 00:00:00 2001 From: jeffser Date: Mon, 8 Jul 2024 16:48:14 -0600 Subject: [PATCH] Removed legacy chat updater (pre 0.9.4) --- src/meson.build | 1 - src/update_history.py | 39 --------------------------------------- src/window.py | 4 +--- 3 files changed, 1 insertion(+), 43 deletions(-) delete mode 100644 src/update_history.py diff --git a/src/meson.build b/src/meson.build index 75adf37..28fe075 100644 --- a/src/meson.build +++ b/src/meson.build @@ -42,7 +42,6 @@ alpaca_sources = [ 'connection_handler.py', 'dialogs.py', 'local_instance.py', - 'update_history.py', 'available_models.json', 'available_models_descriptions.py' ] diff --git a/src/update_history.py b/src/update_history.py deleted file mode 100644 index ae21c4d..0000000 --- a/src/update_history.py +++ /dev/null @@ -1,39 +0,0 @@ -# update_history.py -# This script updates the old chats.json file to the structure needed for the new version -import os, json, base64 -from PIL import Image -import io - - -def update(self): - old_data = None - new_data = {"chats": {}} - with open(os.path.join(self.config_dir, "chats.json"), 'r') as f: - old_data = json.load(f)["chats"] - for chat_name, content in old_data.items(): - directory = os.path.join(self.data_dir, "chats", chat_name) - if not os.path.exists(directory): os.makedirs(directory) - new_messages = {} - for message in content['messages']: - if message: - message_id = self.generate_uuid() - if 'images' in message: - if not os.path.exists(os.path.join(directory, message_id)): os.makedirs(os.path.join(directory, message_id)) - new_images = [] - for image in message['images']: - file_name = f"{self.generate_uuid()}.png" - decoded = base64.b64decode(image) - buffer = io.BytesIO(decoded) - im = Image.open(buffer) - im.save(os.path.join(directory, message_id, file_name)) - new_images.append(file_name) - message['images'] = new_images - new_messages[message_id] = message - new_data['chats'][chat_name] = {} - new_data['chats'][chat_name]['messages'] = new_messages - - with open(os.path.join(self.data_dir, "chats", "chats.json"), "w+") as f: - json.dump(new_data, f, indent=6) - - os.remove(os.path.join(self.config_dir, "chats.json")) - diff --git a/src/window.py b/src/window.py index eb66dce..2d3131d 100644 --- a/src/window.py +++ b/src/window.py @@ -27,7 +27,7 @@ from io import BytesIO from PIL import Image from pypdf import PdfReader from datetime import datetime -from . import dialogs, local_instance, connection_handler, update_history, available_models_descriptions +from . import dialogs, local_instance, connection_handler, available_models_descriptions @Gtk.Template(resource_path='/com/jeffser/Alpaca/window.ui') class AlpacaWindow(Adw.ApplicationWindow): @@ -1468,8 +1468,6 @@ Generate a title following these rules: self.available_models = json.load(f) if not os.path.exists(os.path.join(self.data_dir, "chats")): os.makedirs(os.path.join(self.data_dir, "chats")) - if os.path.exists(os.path.join(self.config_dir, "chats.json")) and not os.path.exists(os.path.join(self.data_dir, "chats", "chats.json")): - update_history.update(self) self.set_help_overlay(self.shortcut_window) self.get_application().set_accels_for_action("win.show-help-overlay", ['slash']) self.get_application().create_action('new_chat', lambda *_: self.new_chat(), ['n'])