Removed legacy chat updater (pre 0.9.4)
This commit is contained in:
parent
32d16a1e61
commit
86c329982c
@ -42,7 +42,6 @@ alpaca_sources = [
|
|||||||
'connection_handler.py',
|
'connection_handler.py',
|
||||||
'dialogs.py',
|
'dialogs.py',
|
||||||
'local_instance.py',
|
'local_instance.py',
|
||||||
'update_history.py',
|
|
||||||
'available_models.json',
|
'available_models.json',
|
||||||
'available_models_descriptions.py'
|
'available_models_descriptions.py'
|
||||||
]
|
]
|
||||||
|
@ -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"))
|
|
||||||
|
|
@ -27,7 +27,7 @@ from io import BytesIO
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
from pypdf import PdfReader
|
from pypdf import PdfReader
|
||||||
from datetime import datetime
|
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')
|
@Gtk.Template(resource_path='/com/jeffser/Alpaca/window.ui')
|
||||||
class AlpacaWindow(Adw.ApplicationWindow):
|
class AlpacaWindow(Adw.ApplicationWindow):
|
||||||
@ -1468,8 +1468,6 @@ Generate a title following these rules:
|
|||||||
self.available_models = json.load(f)
|
self.available_models = json.load(f)
|
||||||
if not os.path.exists(os.path.join(self.data_dir, "chats")):
|
if not os.path.exists(os.path.join(self.data_dir, "chats")):
|
||||||
os.makedirs(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.set_help_overlay(self.shortcut_window)
|
||||||
self.get_application().set_accels_for_action("win.show-help-overlay", ['<primary>slash'])
|
self.get_application().set_accels_for_action("win.show-help-overlay", ['<primary>slash'])
|
||||||
self.get_application().create_action('new_chat', lambda *_: self.new_chat(), ['<primary>n'])
|
self.get_application().create_action('new_chat', lambda *_: self.new_chat(), ['<primary>n'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user