diff options
author | Ty Dunn <ty@tydunn.com> | 2023-06-22 13:04:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-22 13:04:46 -0700 |
commit | e203dd81262d231aed2b73f269c7863dde010d3c (patch) | |
tree | bd777a30350df8abef38018951091a24e8588b7c /continuedev/src | |
parent | 4c7702f10e2be7e6687d975604c9ac84ad98f15f (diff) | |
parent | 71f8e361117ea5b4d88cc5c94e2e54a8ac5f2bf8 (diff) | |
download | sncontinue-e203dd81262d231aed2b73f269c7863dde010d3c.tar.gz sncontinue-e203dd81262d231aed2b73f269c7863dde010d3c.tar.bz2 sncontinue-e203dd81262d231aed2b73f269c7863dde010d3c.zip |
Merge pull request #141 from continuedev/model-button
adding button to toggle between 3.5 and 4
Diffstat (limited to 'continuedev/src')
-rw-r--r-- | continuedev/src/continuedev/core/autopilot.py | 5 | ||||
-rw-r--r-- | continuedev/src/continuedev/core/config.py | 35 | ||||
-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, 59 insertions, 2 deletions
diff --git a/continuedev/src/continuedev/core/autopilot.py b/continuedev/src/continuedev/core/autopilot.py index a6e688ae..ab7f4747 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): + self.continue_sdk.update_default_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..21d21879 100644 --- a/continuedev/src/continuedev/core/config.py +++ b/continuedev/src/continuedev/core/config.py @@ -86,3 +86,38 @@ def load_config(config_file: str) -> ContinueConfig: else: raise ValueError(f'Unknown config file extension: {ext}') return ContinueConfig(**config_dict) + +def update_config(config_file: str): + """ + Update the config file with the current ContinueConfig object. + """ + if not os.path.exists(config_file): + with open(config_file, 'w') as f: + config_dict = { "default_model": "gpt-3.5-turbo" } + json.dump(config_dict, f, indent=4) + + _, ext = os.path.splitext(config_file) + if ext == '.yaml': + + with open(config_file, 'w') as f: + config_dict = yaml.safe_load(f) + + if config_dict["default_model"] == "gpt-4": + config_dict["default_model"] = "gpt-3.5-turbo" + else: + config_dict["default_model"] = "gpt-4" + + with open(config_file, 'w') as f: + json.dump(config_dict, f, indent=4) + + elif ext == '.json': + with open(config_file, 'r') as f: + config_dict = json.load(f) + + if config_dict["default_model"] == "gpt-4": + config_dict["default_model"] = "gpt-3.5-turbo" + else: + config_dict["default_model"] = "gpt-4" + + with open(config_file, 'w') as f: + json.dump(config_dict, f, indent=4)
\ No newline at end of file diff --git a/continuedev/src/continuedev/core/main.py b/continuedev/src/continuedev/core/main.py index efb91488..d6412ece 100644 --- a/continuedev/src/continuedev/core/main.py +++ b/continuedev/src/continuedev/core/main.py @@ -114,6 +114,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 d6acc404..5652ec39 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, update_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 @@ -170,6 +170,15 @@ class ContinueSDK(AbstractContinueSDK): else: return ContinueConfig() + def update_default_model(self): + dir = self.ide.workspace_directory + yaml_path = os.path.join(dir, '.continue', 'config.yaml') + json_path = os.path.join(dir, '.continue', 'config.json') + if os.path.exists(yaml_path): + update_config(yaml_path) + else: + update_config(json_path) + def set_loading_message(self, message: str): # self.__autopilot.set_loading_message(message) raise NotImplementedError() diff --git a/continuedev/src/continuedev/server/gui.py b/continuedev/src/continuedev/server/gui.py index cf046734..9b36c704 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() 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): + asyncio.create_task(self.session.autopilot.change_default_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""" |