diff --git a/Pieces.sublime-settings b/Pieces.sublime-settings index 84123cd..ea19279 100644 --- a/Pieces.sublime-settings +++ b/Pieces.sublime-settings @@ -1,5 +1,5 @@ { - // "host": "http:localhost/1000" + "host": "", "model":"GPT-3.5-turbo Chat Model" // "GPT-4o Chat Model", // "GPT-4 Chat Model", diff --git a/main.py b/main.py index 6956ea5..6e42879 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,6 @@ from .settings import PiecesSettings import sublime -import asyncio # load the commands from .assets import * @@ -13,9 +12,9 @@ from .misc import * from .base_websocket import BaseWebsocket -PiecesSettings.host_init() # Intilize the hosts url -def startup(): + +def startup(settings_model): pieces_version = open_pieces_os() @@ -24,15 +23,11 @@ def startup(): else: if version_check(): PiecesSettings.is_loaded = True - PiecesSettings.models_init() # initilize the models PiecesSettings.get_application() print_version_details(pieces_version, __version__) - - settings = sublime.load_settings('Pieces.sublime-settings') - - settings.add_on_change("PIECES_SETTINGS",PiecesSettings.on_settings_change) - + + PiecesSettings.models_init(settings_model) # Intilize the models # WEBSOCKETS: @@ -45,7 +40,15 @@ def startup(): def plugin_loaded(): - sublime.set_timeout_async(startup,0) + global settings # Set it to global to use + + settings = sublime.load_settings('Pieces.sublime-settings') + host = settings.get("host") + model = settings.get('model') + settings.add_on_change("PIECES_SETTINGS",PiecesSettings.on_settings_change) + PiecesSettings.host_init(host) # Intilize the hosts url + + sublime.set_timeout_async(lambda : startup(model) ,0) def plugin_unloaded(): diff --git a/misc/reload_command.py b/misc/reload_command.py index f793921..b5e63f7 100644 --- a/misc/reload_command.py +++ b/misc/reload_command.py @@ -13,8 +13,7 @@ def run(self): def reload_async(): if PiecesSettings.get_health(): try: - PiecesSettings.models_init() - PiecesSettings.host_init() + PiecesSettings.on_settings_change(all = True) BaseWebsocket.reconnect_all() PiecesSettings.is_loaded = True sublime.status_message(f"Reloading [completed]") diff --git a/settings.py b/settings.py index d415f67..d2f7873 100644 --- a/settings.py +++ b/settings.py @@ -15,8 +15,7 @@ class PiecesSettings: api_client = None _is_loaded = False # is the plugin loaded - # Load the settings from 'pieces.sublime-settings' file using Sublime Text API - settings = sublime.load_settings('Pieces.sublime-settings') + @property @@ -49,18 +48,15 @@ def get_health(cls): @classmethod - def host_init(cls): + def host_init(cls,host): """ Initialize the host URL for the API connection. This method sets the host URL based on the configuration settings. If the host URL is not provided in the settings, it defaults to a specific URL based on the platform. It then creates the WebSocket base URL and defines the WebSocket URLs for different API endpoints. """ - cls.host = cls.settings.get('host') - if not isinstance(cls.host,str): - return sublime.error_message("Invalid host") - - if not cls.host: + cls.host = host + if not host: if 'linux' == sublime.platform(): cls.host = "http://127.0.0.1:5323" else: @@ -80,7 +76,7 @@ def host_init(cls): @classmethod - def models_init(cls): + def models_init(cls,model): """ Initialize the model ID for the class using the specified settings. @@ -89,7 +85,7 @@ def models_init(cls): """ models = cls.get_models_ids() - cls.model_name = cls.settings.get("model") + cls.model_name = model cls.model_id = models.get(str(cls.model_name)) if not cls.model_id: @@ -97,11 +93,19 @@ def models_init(cls): @classmethod - def on_settings_change(cls): - if cls.host != cls.settings.get('host'): - cls.host_init() - if cls.model_name != cls.settings.get("model"): - cls.models_init() + def on_settings_change(cls,all = False): + """ + all parameter means to update everything not the changes + """ + settings = sublime.load_settings("Pieces.sublime-settings") # Reload the settings + host = settings.get('host') + model = settings.get("model") + if cls.host != host or all: + cls.host_init(host = host) + cls.models_init(model = model) + + if cls.model_name != model or all: + cls.models_init(model = model)