From 35e08e5f9bb1542052d40af38eb8097a61dc7c29 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 14 Nov 2023 23:57:31 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20docs=20page=20for=20migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docs/config-file-migration.md | 25 +++++++++ .../libs/constants/default_config.py | 55 +++++++++++++++++++ .../continuedev/plugins/steps/open_config.py | 2 +- .../continuedev/plugins/steps/setup_model.py | 19 ++----- server/continuedev/server/window_manager.py | 8 ++- 5 files changed, 94 insertions(+), 15 deletions(-) create mode 100644 docs/docs/config-file-migration.md diff --git a/docs/docs/config-file-migration.md b/docs/docs/config-file-migration.md new file mode 100644 index 000000000..4dacd1ac8 --- /dev/null +++ b/docs/docs/config-file-migration.md @@ -0,0 +1,25 @@ +# Continue Configuration File Formats + +On November 15, 2023, we migrated to using JSON as the primary config file format. If you previously used Continue, we will have attempted to automatically translate your existing config.py into a config.json file. If this fails, we will fallback to a default config.json. + +The JSON format provides stronger guiderails, making it easier to write a valid config, while still allowing Intellisense in VS Code. + +If you need any help migrating, please reach out to us on Discord. + +## Configuration as Code + +For configuration that requires code, we now provide a simpler interface that works alongside config.json. In the same folder, `~/.continue`, create a file named `config.py` (the same name as before) and add a function called `modify_config`. This function should take a `ContinueConfig` object as its only argument, and return a `ContinueConfig` object. This allows you to modify the initial configuration object defined in your `config.json`. Here's an example that cuts the temperature in half: + +```python +from continuedev.core.config import ContinueConfig + +def modify_config(config: ContinueConfig) -> ContinueConfig: + config.completion_options.temperature /= 2 + return config +``` + +To summarize, these are the steps taken to load your configuration: + +1. Load `~/.continue/config.json` +2. Convert this into a `ContinueConfig` object +3. If `~/.continue/config.py` exists and has defined `modify_config` correctly, call `modify_config` with the `ContinueConfig` object to generate the final configuration diff --git a/server/continuedev/libs/constants/default_config.py b/server/continuedev/libs/constants/default_config.py index 1890b448d..f0036232f 100644 --- a/server/continuedev/libs/constants/default_config.py +++ b/server/continuedev/libs/constants/default_config.py @@ -13,3 +13,58 @@ def modify_config(config: ContinueConfig) -> ContinueConfig: return config """ + +default_config_json = """\ +{ + "models": [ + { + "title": "GPT-4", + "provider": "openai-free-trial", + "model": "gpt-4" + }, + { + "title": "GPT-3.5-Turbo", + "provider": "openai-free-trial", + "model": "gpt-3.5-turbo" + } + ], + "model_roles": { + "default": "GPT-4", + "summarize": "GPT-3.5-Turbo" + }, + "slash_commands": [ + { + "name": "edit", + "description": "Edit highlighted code", + "step": "EditHighlightedCodeStep" + }, + { + "name": "config", + "description": "Customize Continue", + "step": "OpenConfigStep" + }, + { + "name": "comment", + "description": "Write comments for the highlighted code", + "step": "CommentCodeStep" + }, + { + "name": "share", + "description": "Download and share this session", + "step": "ShareSessionStep" + }, + { + "name": "cmd", + "description": "Generate a shell command", + "step": "GenerateShellCommandStep" + } + ], + "custom_commands": [ + { + "name": "test", + "prompt": "Write a comprehensive set of unit tests for the selected code. It should setup, run tests that check for correctness including important edge cases, and teardown. Ensure that the tests are complete and sophisticated. Give the tests just as chat output, don't edit any file.", + "description": "Write unit tests for highlighted code" + } + ] +} +""" diff --git a/server/continuedev/plugins/steps/open_config.py b/server/continuedev/plugins/steps/open_config.py index a79db5425..1ea7e1963 100644 --- a/server/continuedev/plugins/steps/open_config.py +++ b/server/continuedev/plugins/steps/open_config.py @@ -15,4 +15,4 @@ class OpenConfigStep(Step): ) async def run(self, sdk: ContinueSDK): - await sdk.ide.setFileOpen(getConfigFilePath()) + await sdk.ide.setFileOpen(getConfigFilePath(json=True)) diff --git a/server/continuedev/plugins/steps/setup_model.py b/server/continuedev/plugins/steps/setup_model.py index dcf6bacc7..ec021b6d0 100644 --- a/server/continuedev/plugins/steps/setup_model.py +++ b/server/continuedev/plugins/steps/setup_model.py @@ -1,4 +1,4 @@ -from ...core.main import Step +from ...core.main import SetStep, Step from ...core.sdk import ContinueSDK from ...libs.util.paths import getConfigFilePath from ...models.filesystem import RangeInFile @@ -24,16 +24,9 @@ class SetupModelStep(Step): hide: bool = True async def run(self, sdk: ContinueSDK): - await sdk.ide.setFileOpen(getConfigFilePath()) - self.description = MODEL_CLASS_TO_MESSAGE.get( - self.model_class, "Please finish setting up this model in `config.py`" - ) - - config_contents = await sdk.ide.readFile(getConfigFilePath()) - start = config_contents.find("default=") + len("default=") - end = config_contents.find("saved=") - 1 - range = Range.from_indices(config_contents, start, end) - range.end.line -= 1 - await sdk.ide.highlightCode( - RangeInFile(filepath=getConfigFilePath(), range=range) + await sdk.ide.setFileOpen(getConfigFilePath(json=True)) + yield SetStep( + description=MODEL_CLASS_TO_MESSAGE.get( + self.model_class, "Please finish setting up this model in `config.py`" + ) ) diff --git a/server/continuedev/server/window_manager.py b/server/continuedev/server/window_manager.py index 54106e4a5..5c36684e6 100644 --- a/server/continuedev/server/window_manager.py +++ b/server/continuedev/server/window_manager.py @@ -1,3 +1,4 @@ +import os import traceback from typing import Dict, Optional @@ -5,6 +6,7 @@ from ..core.autopilot import Autopilot from ..core.config import ContinueConfig from ..core.context import ContextManager from ..core.main import SessionState +from ..libs.constants.default_config import default_config_json from ..libs.index.build_index import build_index from ..libs.util.create_async_task import create_async_task from ..libs.util.devdata import dev_data_logger @@ -74,7 +76,11 @@ class Window: async def display_config_error(self): if self._error_loading_config is not None: - await self.ide.setFileOpen(getConfigFilePath()) + if not os.path.exists(getConfigFilePath(json=True)): + with open(getConfigFilePath(json=True), "w") as f: + f.write(default_config_json) + + await self.ide.setFileOpen(getConfigFilePath(json=True)) await self.ide.showMessage( f"""We found an error while loading your config.py. For now, Continue is falling back to the default configuration. If you need help solving this error, please reach out to us on Discord by clicking the question mark button in the bottom right.\n\n{self._error_loading_config}""" )