From 6c08e6d5befb0729b5020e93a60fbbe381347b7d Mon Sep 17 00:00:00 2001
From: Ty Dunn <ty@tydunn.com>
Date: Wed, 21 Jun 2023 15:25:49 -0700
Subject: initial ideas

---
 extension/react-app/src/hooks/useContinueGUIProtocol.ts | 4 ++++
 1 file changed, 4 insertions(+)

(limited to 'extension/react-app/src/hooks/useContinueGUIProtocol.ts')

diff --git a/extension/react-app/src/hooks/useContinueGUIProtocol.ts b/extension/react-app/src/hooks/useContinueGUIProtocol.ts
index 59397742..4eb68046 100644
--- a/extension/react-app/src/hooks/useContinueGUIProtocol.ts
+++ b/extension/react-app/src/hooks/useContinueGUIProtocol.ts
@@ -55,6 +55,10 @@ class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol {
     });
   }
 
+  changeDefaultModel() {
+    this.messenger.send("change_default_model", {});
+  }
+
   sendClear() {
     this.messenger.send("clear_history", {});
   }
-- 
cgit v1.2.3-70-g09d2


From a1f9bfd25c2df807ccc49be67b0bc0e57321c272 Mon Sep 17 00:00:00 2001
From: Ty Dunn <ty@tydunn.com>
Date: Wed, 21 Jun 2023 15:28:37 -0700
Subject: Revert "initial ideas"

This reverts commit 6c08e6d5befb0729b5020e93a60fbbe381347b7d.
---
 continuedev/src/continuedev/core/autopilot.py           | 4 ----
 continuedev/src/continuedev/server/gui.py               | 3 ---
 continuedev/src/continuedev/server/gui_protocol.py      | 4 ----
 extension/react-app/src/hooks/useContinueGUIProtocol.ts | 4 ----
 extension/react-app/src/tabs/gui.tsx                    | 4 ++--
 5 files changed, 2 insertions(+), 17 deletions(-)

(limited to 'extension/react-app/src/hooks/useContinueGUIProtocol.ts')

diff --git a/continuedev/src/continuedev/core/autopilot.py b/continuedev/src/continuedev/core/autopilot.py
index 2ed77e4d..a6e688ae 100644
--- a/continuedev/src/continuedev/core/autopilot.py
+++ b/continuedev/src/continuedev/core/autopilot.py
@@ -45,10 +45,6 @@ class Autopilot(ContinueBaseModel):
     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):
-        # TODO: Implement this
-        temp = self.continue_sdk.config.slash_commands
-
     async def clear_history(self):
         self.history = History.from_empty()
         self._main_user_input_queue = []
diff --git a/continuedev/src/continuedev/server/gui.py b/continuedev/src/continuedev/server/gui.py
index 53a5f16b..cf046734 100644
--- a/continuedev/src/continuedev/server/gui.py
+++ b/continuedev/src/continuedev/server/gui.py
@@ -116,9 +116,6 @@ 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 66839d9b..d9506c6f 100644
--- a/continuedev/src/continuedev/server/gui_protocol.py
+++ b/continuedev/src/continuedev/server/gui_protocol.py
@@ -35,10 +35,6 @@ class AbstractGUIProtocolServer(ABC):
     def on_retry_at_index(self, index: int):
         """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"""
diff --git a/extension/react-app/src/hooks/useContinueGUIProtocol.ts b/extension/react-app/src/hooks/useContinueGUIProtocol.ts
index 4eb68046..59397742 100644
--- a/extension/react-app/src/hooks/useContinueGUIProtocol.ts
+++ b/extension/react-app/src/hooks/useContinueGUIProtocol.ts
@@ -55,10 +55,6 @@ class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol {
     });
   }
 
-  changeDefaultModel() {
-    this.messenger.send("change_default_model", {});
-  }
-
   sendClear() {
     this.messenger.send("clear_history", {});
   }
diff --git a/extension/react-app/src/tabs/gui.tsx b/extension/react-app/src/tabs/gui.tsx
index 15260e0c..f0e3ffd4 100644
--- a/extension/react-app/src/tabs/gui.tsx
+++ b/extension/react-app/src/tabs/gui.tsx
@@ -470,7 +470,7 @@ function GUI(props: GUIProps) {
             Contribute Data
           </span>
         </div>
-        { <HeaderButtonWithText
+        {/* <HeaderButtonWithText
           onClick={() => {
             setUsingFastModel((prev) => !prev);
           }}
@@ -481,7 +481,7 @@ function GUI(props: GUIProps) {
           >
             {usingFastModel ? "⚡" : "🧠"}
           </div>
-        </HeaderButtonWithText>}
+        </HeaderButtonWithText> */}
         <HeaderButtonWithText
           onClick={() => {
             client?.sendClear();
-- 
cgit v1.2.3-70-g09d2


From 559a5301c382934f48c81f476909931a0a0e9b44 Mon Sep 17 00:00:00 2001
From: Ty Dunn <ty@tydunn.com>
Date: Wed, 21 Jun 2023 15:36:12 -0700
Subject: initial ideas

---
 continuedev/src/continuedev/core/autopilot.py           | 4 ++++
 continuedev/src/continuedev/server/gui.py               | 3 +++
 continuedev/src/continuedev/server/gui_protocol.py      | 4 ++++
 extension/react-app/src/hooks/useContinueGUIProtocol.ts | 4 ++++
 extension/react-app/src/tabs/gui.tsx                    | 4 ++--
 5 files changed, 17 insertions(+), 2 deletions(-)

(limited to 'extension/react-app/src/hooks/useContinueGUIProtocol.ts')

diff --git a/continuedev/src/continuedev/core/autopilot.py b/continuedev/src/continuedev/core/autopilot.py
index a6e688ae..2ed77e4d 100644
--- a/continuedev/src/continuedev/core/autopilot.py
+++ b/continuedev/src/continuedev/core/autopilot.py
@@ -45,6 +45,10 @@ class Autopilot(ContinueBaseModel):
     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):
+        # TODO: Implement this
+        temp = self.continue_sdk.config.slash_commands
+
     async def clear_history(self):
         self.history = History.from_empty()
         self._main_user_input_queue = []
diff --git a/continuedev/src/continuedev/server/gui.py b/continuedev/src/continuedev/server/gui.py
index cf046734..53a5f16b 100644
--- a/continuedev/src/continuedev/server/gui.py
+++ b/continuedev/src/continuedev/server/gui.py
@@ -116,6 +116,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
@@ -35,6 +35,10 @@ class AbstractGUIProtocolServer(ABC):
     def on_retry_at_index(self, index: int):
         """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"""
diff --git a/extension/react-app/src/hooks/useContinueGUIProtocol.ts b/extension/react-app/src/hooks/useContinueGUIProtocol.ts
index 59397742..4eb68046 100644
--- a/extension/react-app/src/hooks/useContinueGUIProtocol.ts
+++ b/extension/react-app/src/hooks/useContinueGUIProtocol.ts
@@ -55,6 +55,10 @@ class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol {
     });
   }
 
+  changeDefaultModel() {
+    this.messenger.send("change_default_model", {});
+  }
+
   sendClear() {
     this.messenger.send("clear_history", {});
   }
diff --git a/extension/react-app/src/tabs/gui.tsx b/extension/react-app/src/tabs/gui.tsx
index f0e3ffd4..cbc0e8af 100644
--- a/extension/react-app/src/tabs/gui.tsx
+++ b/extension/react-app/src/tabs/gui.tsx
@@ -470,7 +470,7 @@ function GUI(props: GUIProps) {
             Contribute Data
           </span>
         </div>
-        {/* <HeaderButtonWithText
+        <HeaderButtonWithText
           onClick={() => {
             setUsingFastModel((prev) => !prev);
           }}
@@ -481,7 +481,7 @@ function GUI(props: GUIProps) {
           >
             {usingFastModel ? "⚡" : "🧠"}
           </div>
-        </HeaderButtonWithText> */}
+        </HeaderButtonWithText>
         <HeaderButtonWithText
           onClick={() => {
             client?.sendClear();
-- 
cgit v1.2.3-70-g09d2


From 589fd45fb13c17a1bd13d758806946b55d157a22 Mon Sep 17 00:00:00 2001
From: Nate Sesti <sestinj@gmail.com>
Date: Thu, 22 Jun 2023 13:56:48 -0700
Subject: update global config with default model toggle

---
 continuedev/src/continuedev/core/autopilot.py      |  4 +-
 continuedev/src/continuedev/core/config.py         | 64 ++++++++++++----------
 continuedev/src/continuedev/core/sdk.py            | 18 +++---
 continuedev/src/continuedev/server/gui.py          |  6 +-
 .../src/hooks/ContinueGUIClientProtocol.ts         |  2 +-
 .../react-app/src/hooks/useContinueGUIProtocol.ts  |  4 +-
 extension/react-app/src/tabs/gui.tsx               | 10 ++--
 7 files changed, 57 insertions(+), 51 deletions(-)

(limited to 'extension/react-app/src/hooks/useContinueGUIProtocol.ts')

diff --git a/continuedev/src/continuedev/core/autopilot.py b/continuedev/src/continuedev/core/autopilot.py
index ab7f4747..f14a4127 100644
--- a/continuedev/src/continuedev/core/autopilot.py
+++ b/continuedev/src/continuedev/core/autopilot.py
@@ -45,8 +45,8 @@ class Autopilot(ContinueBaseModel):
     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 change_default_model(self, model: str):
+        self.continue_sdk.update_default_model(model)
 
     async def clear_history(self):
         self.history = History.from_empty()
diff --git a/continuedev/src/continuedev/core/config.py b/continuedev/src/continuedev/core/config.py
index 21d21879..01316f1b 100644
--- a/continuedev/src/continuedev/core/config.py
+++ b/continuedev/src/continuedev/core/config.py
@@ -87,37 +87,45 @@ def load_config(config_file: str) -> ContinueConfig:
         raise ValueError(f'Unknown config file extension: {ext}')
     return ContinueConfig(**config_dict)
 
-def update_config(config_file: str):
+
+def load_global_config() -> ContinueConfig:
     """
-    Update the config file with the current ContinueConfig object.
+    Load the global config file and return a 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':
+    global_dir = os.path.expanduser('~/.continue')
+    if not os.path.exists(global_dir):
+        os.mkdir(global_dir)
 
-        with open(config_file, 'w') as f:
-            config_dict = yaml.safe_load(f)
+    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)
 
-            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)
+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)
 
-        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
+    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/sdk.py b/continuedev/src/continuedev/core/sdk.py
index 5652ec39..192552e7 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, update_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
@@ -76,7 +76,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
@@ -168,16 +168,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):
-        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 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 9b36c704..cc6235e9 100644
--- a/continuedev/src/continuedev/server/gui.py
+++ b/continuedev/src/continuedev/server/gui.py
@@ -78,7 +78,7 @@ class GUIProtocolServer(AbstractGUIProtocolServer):
             elif message_type == "retry_at_index":
                 self.on_retry_at_index(data["index"])
             elif message_type == "change_default_model":
-                self.on_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":
@@ -118,8 +118,8 @@ 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_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/extension/react-app/src/hooks/ContinueGUIClientProtocol.ts b/extension/react-app/src/hooks/ContinueGUIClientProtocol.ts
index 6d9d1fdd..3d8e0a38 100644
--- a/extension/react-app/src/hooks/ContinueGUIClientProtocol.ts
+++ b/extension/react-app/src/hooks/ContinueGUIClientProtocol.ts
@@ -13,7 +13,7 @@ abstract class AbstractContinueGUIClientProtocol {
     callback: (commands: { name: string; description: string }[]) => void
   ): void;
 
-  abstract changeDefaultModel(): void;
+  abstract changeDefaultModel(model: string): void;
 
   abstract sendClear(): void;
 
diff --git a/extension/react-app/src/hooks/useContinueGUIProtocol.ts b/extension/react-app/src/hooks/useContinueGUIProtocol.ts
index 4eb68046..f43a66ff 100644
--- a/extension/react-app/src/hooks/useContinueGUIProtocol.ts
+++ b/extension/react-app/src/hooks/useContinueGUIProtocol.ts
@@ -55,8 +55,8 @@ class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol {
     });
   }
 
-  changeDefaultModel() {
-    this.messenger.send("change_default_model", {});
+  changeDefaultModel(model: string) {
+    this.messenger.send("change_default_model", { model });
   }
 
   sendClear() {
diff --git a/extension/react-app/src/tabs/gui.tsx b/extension/react-app/src/tabs/gui.tsx
index 16c950ef..f47371ee 100644
--- a/extension/react-app/src/tabs/gui.tsx
+++ b/extension/react-app/src/tabs/gui.tsx
@@ -427,9 +427,9 @@ function GUI(props: GUIProps) {
         }}
         hidden={!showDataSharingInfo}
       >
-        By turning on this switch, you signal that you would 
-        contribute this software development data to a publicly 
-        accessible, open-source dataset in the future.
+        By turning on this switch, you signal that you would contribute this
+        software development data to a publicly accessible, open-source dataset
+        in the future.
         <br />
         <br />
         <b>
@@ -473,8 +473,10 @@ function GUI(props: GUIProps) {
         </div>
         <HeaderButtonWithText
           onClick={() => {
+            client?.changeDefaultModel(
+              usingFastModel ? "gpt-4" : "gpt-3.5-turbo"
+            );
             setUsingFastModel((prev) => !prev);
-            client?.changeDefaultModel();
           }}
           text={usingFastModel ? "gpt-3.5-turbo" : "gpt-4"}
         >
-- 
cgit v1.2.3-70-g09d2