diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-06-25 12:24:45 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-06-25 12:24:45 -0700 |
commit | 54048d3e7bda9c39cc08888b37e0c7dc0716a713 (patch) | |
tree | 3ff7254f755e4b3b28a523d652b78dd1f61f868d /continuedev/src | |
parent | 82ead52472d4e2a2e291aa5f17ea8522fc11f236 (diff) | |
parent | ad462728afc4e6a9e1402aff295010ced9cf2f7a (diff) | |
download | sncontinue-54048d3e7bda9c39cc08888b37e0c7dc0716a713.tar.gz sncontinue-54048d3e7bda9c39cc08888b37e0c7dc0716a713.tar.bz2 sncontinue-54048d3e7bda9c39cc08888b37e0c7dc0716a713.zip |
Merge branch 'main' into function-calling
Diffstat (limited to 'continuedev/src')
-rw-r--r-- | continuedev/src/continuedev/core/autopilot.py | 5 | ||||
-rw-r--r-- | continuedev/src/continuedev/core/config.py | 43 | ||||
-rw-r--r-- | continuedev/src/continuedev/core/main.py | 1 | ||||
-rw-r--r-- | continuedev/src/continuedev/core/sdk.py | 11 | ||||
-rw-r--r-- | continuedev/src/continuedev/server/gui.py | 5 | ||||
-rw-r--r-- | continuedev/src/continuedev/server/gui_protocol.py | 4 |
6 files changed, 65 insertions, 4 deletions
diff --git a/continuedev/src/continuedev/core/autopilot.py b/continuedev/src/continuedev/core/autopilot.py index a6e688ae..f14a4127 100644 --- a/continuedev/src/continuedev/core/autopilot.py +++ b/continuedev/src/continuedev/core/autopilot.py @@ -40,11 +40,14 @@ class Autopilot(ContinueBaseModel): keep_untouched = (cached_property,) def get_full_state(self) -> FullState: - return FullState(history=self.history, active=self._active, user_input_queue=self._main_user_input_queue) + return FullState(history=self.history, active=self._active, user_input_queue=self._main_user_input_queue, default_model=self.continue_sdk.config.default_model) async def get_available_slash_commands(self) -> List[Dict]: return list(map(lambda x: {"name": x.name, "description": x.description}, self.continue_sdk.config.slash_commands)) or [] + async def change_default_model(self, model: str): + self.continue_sdk.update_default_model(model) + async def clear_history(self): self.history = History.from_empty() self._main_user_input_queue = [] diff --git a/continuedev/src/continuedev/core/config.py b/continuedev/src/continuedev/core/config.py index 652320fb..01316f1b 100644 --- a/continuedev/src/continuedev/core/config.py +++ b/continuedev/src/continuedev/core/config.py @@ -86,3 +86,46 @@ def load_config(config_file: str) -> ContinueConfig: else: raise ValueError(f'Unknown config file extension: {ext}') return ContinueConfig(**config_dict) + + +def load_global_config() -> ContinueConfig: + """ + Load the global config file and return a ContinueConfig object. + """ + global_dir = os.path.expanduser('~/.continue') + if not os.path.exists(global_dir): + os.mkdir(global_dir) + + yaml_path = os.path.join(global_dir, 'config.yaml') + if os.path.exists(yaml_path): + with open(config_path, 'r') as f: + try: + config_dict = yaml.safe_load(f) + except: + return ContinueConfig() + else: + config_path = os.path.join(global_dir, 'config.json') + with open(config_path, 'r') as f: + try: + config_dict = json.load(f) + except: + return ContinueConfig() + return ContinueConfig(**config_dict) + + +def update_global_config(config: ContinueConfig): + """ + Update the config file with the given ContinueConfig object. + """ + global_dir = os.path.expanduser('~/.continue') + if not os.path.exists(global_dir): + os.mkdir(global_dir) + + yaml_path = os.path.join(global_dir, 'config.yaml') + if os.path.exists(yaml_path): + with open(config_path, 'w') as f: + yaml.dump(config.dict(), f) + else: + config_path = os.path.join(global_dir, 'config.json') + with open(config_path, 'w') as f: + json.dump(config.dict(), f) diff --git a/continuedev/src/continuedev/core/main.py b/continuedev/src/continuedev/core/main.py index 0dd5bb64..b9ae9eba 100644 --- a/continuedev/src/continuedev/core/main.py +++ b/continuedev/src/continuedev/core/main.py @@ -200,6 +200,7 @@ class FullState(ContinueBaseModel): history: History active: bool user_input_queue: List[str] + default_model: str class ContinueSDK: diff --git a/continuedev/src/continuedev/core/sdk.py b/continuedev/src/continuedev/core/sdk.py index be3bc9d4..62361250 100644 --- a/continuedev/src/continuedev/core/sdk.py +++ b/continuedev/src/continuedev/core/sdk.py @@ -6,7 +6,7 @@ import os from ..steps.core.core import DefaultModelEditCodeStep from ..models.main import Range from .abstract_sdk import AbstractContinueSDK -from .config import ContinueConfig, load_config +from .config import ContinueConfig, load_config, load_global_config, update_global_config from ..models.filesystem_edit import FileEdit, FileSystemEdit, AddFile, DeleteFile, AddDirectory, DeleteDirectory from ..models.filesystem import RangeInFile from ..libs.llm.hf_inference_api import HuggingFaceInferenceAPI @@ -71,7 +71,7 @@ class Models: else: raise Exception(f"Unknown model {model_name}") - @cached_property + @property def default(self): default_model = self.sdk.config.default_model return self.__model_from_name(default_model) if default_model is not None else self.gpt35 @@ -163,7 +163,12 @@ class ContinueSDK(AbstractContinueSDK): elif os.path.exists(json_path): return load_config(json_path) else: - return ContinueConfig() + return load_global_config() + + def update_default_model(self, model: str): + config = self.config + config.default_model = model + update_global_config(config) def set_loading_message(self, message: str): # self.__autopilot.set_loading_message(message) diff --git a/continuedev/src/continuedev/server/gui.py b/continuedev/src/continuedev/server/gui.py index cf046734..cc6235e9 100644 --- a/continuedev/src/continuedev/server/gui.py +++ b/continuedev/src/continuedev/server/gui.py @@ -77,6 +77,8 @@ class GUIProtocolServer(AbstractGUIProtocolServer): self.on_reverse_to_index(data["index"]) elif message_type == "retry_at_index": self.on_retry_at_index(data["index"]) + elif message_type == "change_default_model": + self.on_change_default_model(data["model"]) elif message_type == "clear_history": self.on_clear_history() elif message_type == "delete_at_index": @@ -116,6 +118,9 @@ class GUIProtocolServer(AbstractGUIProtocolServer): asyncio.create_task( self.session.autopilot.retry_at_index(index)) + def on_change_default_model(self, model: str): + asyncio.create_task(self.session.autopilot.change_default_model(model)) + def on_clear_history(self): asyncio.create_task(self.session.autopilot.clear_history()) diff --git a/continuedev/src/continuedev/server/gui_protocol.py b/continuedev/src/continuedev/server/gui_protocol.py index d9506c6f..66839d9b 100644 --- a/continuedev/src/continuedev/server/gui_protocol.py +++ b/continuedev/src/continuedev/server/gui_protocol.py @@ -36,6 +36,10 @@ class AbstractGUIProtocolServer(ABC): """Called when the user requests a retry at a previous index""" @abstractmethod + def on_change_default_model(self): + """Called when the user requests to change the default model""" + + @abstractmethod def on_clear_history(self): """Called when the user requests to clear the history""" |