diff options
| author | Nate Sesti <sestinj@gmail.com> | 2023-07-24 19:19:33 -0700 |
|---|---|---|
| committer | Nate Sesti <sestinj@gmail.com> | 2023-07-24 19:19:33 -0700 |
| commit | 000e9c0735c50bd6cb63866441d7f73083665902 (patch) | |
| tree | e721ae8223e4683f12522861d82036ead1f7993d /continuedev/src/continuedev/core | |
| parent | 0672fa836c9e2b242fbc530ebdb645192c4b0590 (diff) | |
| download | sncontinue-000e9c0735c50bd6cb63866441d7f73083665902.tar.gz sncontinue-000e9c0735c50bd6cb63866441d7f73083665902.tar.bz2 sncontinue-000e9c0735c50bd6cb63866441d7f73083665902.zip | |
telemetry refactoring and switch config.json->py
Diffstat (limited to 'continuedev/src/continuedev/core')
| -rw-r--r-- | continuedev/src/continuedev/core/autopilot.py | 14 | ||||
| -rw-r--r-- | continuedev/src/continuedev/core/config.py | 71 | ||||
| -rw-r--r-- | continuedev/src/continuedev/core/policy.py | 1 | ||||
| -rw-r--r-- | continuedev/src/continuedev/core/sdk.py | 15 |
4 files changed, 12 insertions, 89 deletions
diff --git a/continuedev/src/continuedev/core/autopilot.py b/continuedev/src/continuedev/core/autopilot.py index 2ce7c1f9..0e355d78 100644 --- a/continuedev/src/continuedev/core/autopilot.py +++ b/continuedev/src/continuedev/core/autopilot.py @@ -2,7 +2,6 @@ from functools import cached_property import traceback import time from typing import Any, Callable, Coroutine, Dict, List, Union -import os from aiohttp import ClientPayloadError from pydantic import root_validator @@ -17,11 +16,11 @@ from ..libs.util.queue import AsyncSubscriptionQueue from ..models.main import ContinueBaseModel from .main import Context, ContinueCustomException, Policy, History, FullState, Step, HistoryNode from ..plugins.steps.core.core import ReversibleStep, ManualEditStep, UserInputStep -from ..libs.util.telemetry import capture_event from .sdk import ContinueSDK from ..libs.util.traceback_parsers import get_python_traceback, get_javascript_traceback from openai import error as openai_errors from ..libs.util.create_async_task import create_async_task +from ..libs.util.telemetry import posthog_logger def get_error_title(e: Exception) -> str: @@ -111,9 +110,6 @@ class Autopilot(ContinueBaseModel): "name": x.name, "description": x.description}, self.continue_sdk.config.slash_commands)) or [] return custom_commands + slash_commands - async def change_default_model(self, model: str): - self.continue_sdk.update_default_model(model) - async def clear_history(self): # Reset history self.history = History.from_empty() @@ -222,8 +218,8 @@ class Autopilot(ContinueBaseModel): # last_depth = self.history.timeline[i].depth # i -= 1 - capture_event(self.continue_sdk.ide.unique_id, 'step run', { - 'step_name': step.name, 'params': step.dict()}) + posthog_logger.capture_event( + 'step run', {'step_name': step.name, 'params': step.dict()}) if not is_future_step: # Check manual edits buffer, clear out if needed by creating a ManualEditStep @@ -264,8 +260,8 @@ class Autopilot(ContinueBaseModel): # Attach an InternalErrorObservation to the step and unhide it. print( f"Error while running step: \n{error_string}\n{error_title}") - capture_event(self.continue_sdk.ide.unique_id, 'step error', { - 'error_message': error_string, 'error_title': error_title, 'step_name': step.name, 'params': step.dict()}) + posthog_logger.capture_event('step error', { + 'error_message': error_string, 'error_title': error_title, 'step_name': step.name, 'params': step.dict()}) observation = InternalErrorObservation( error=error_string, title=error_title) diff --git a/continuedev/src/continuedev/core/config.py b/continuedev/src/continuedev/core/config.py index 565c617d..cb9c8977 100644 --- a/continuedev/src/continuedev/core/config.py +++ b/continuedev/src/continuedev/core/config.py @@ -95,74 +95,3 @@ class ContinueConfig(BaseModel): @validator('temperature', pre=True) def temperature_validator(cls, v): return max(0.0, min(1.0, v)) - - -def load_config(config_file: str) -> ContinueConfig: - """ - Load the config file and return a ContinueConfig object. - """ - if not os.path.exists(config_file): - return ContinueConfig() - - _, ext = os.path.splitext(config_file) - if ext == '.yaml': - with open(config_file, 'r') as f: - try: - config_dict = yaml.safe_load(f) - except: - return ContinueConfig() - elif ext == '.json': - with open(config_file, 'r') as f: - try: - config_dict = json.load(f) - except: - return 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') - if not os.path.exists(config_path): - with open(config_path, 'w') as f: - json.dump(ContinueConfig().dict(), f, indent=4) - 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, indent=4) - else: - config_path = os.path.join(global_dir, 'config.json') - with open(config_path, 'w') as f: - json.dump(config.dict(exclude_unset=False), f, indent=4) diff --git a/continuedev/src/continuedev/core/policy.py b/continuedev/src/continuedev/core/policy.py index 1c87cfeb..d90177b5 100644 --- a/continuedev/src/continuedev/core/policy.py +++ b/continuedev/src/continuedev/core/policy.py @@ -56,7 +56,6 @@ class DefaultPolicy(Policy): - Use `cmd+m` (Mac) / `ctrl+m` (Windows) to open Continue - Use `/help` to ask questions about how to use Continue""")) >> WelcomeStep() >> - # SetupContinueWorkspaceStep() >> # CreateCodebaseIndexChroma() >> StepsOnStartupStep()) diff --git a/continuedev/src/continuedev/core/sdk.py b/continuedev/src/continuedev/core/sdk.py index f925f20f..6668c8c3 100644 --- a/continuedev/src/continuedev/core/sdk.py +++ b/continuedev/src/continuedev/core/sdk.py @@ -1,13 +1,11 @@ -import asyncio from functools import cached_property from typing import Coroutine, Dict, Union import os from ..plugins.steps.core.core import DefaultModelEditCodeStep from ..models.main import Range -from .context import ContextItem from .abstract_sdk import AbstractContinueSDK -from .config import ContinueConfig, load_config, load_global_config, update_global_config +from .config import ContinueConfig from ..models.filesystem_edit import FileEdit, FileSystemEdit, AddFile, DeleteFile, AddDirectory, DeleteDirectory from ..models.filesystem import RangeInFile from ..libs.llm.hf_inference_api import HuggingFaceInferenceAPI @@ -19,6 +17,7 @@ from ..server.ide_protocol import AbstractIdeProtocolServer from .main import Context, ContinueCustomException, History, HistoryNode, Step, ChatMessage from ..plugins.steps.core.core import * from ..libs.llm.proxy_server import ProxyServer +from ..libs.util.telemetry import posthog_logger class Autopilot: @@ -266,6 +265,11 @@ class ContinueSDK(AbstractContinueSDK): config = importlib.util.module_from_spec(spec) spec.loader.exec_module(config) self._last_valid_config = config.config + + # When the config is loaded, setup posthog logger + posthog_logger.setup( + self.ide.unique_id, config.config.allow_anonymous_telemetry or True) + return config.config except Exception as e: print("Error loading config.py: ", e) @@ -276,11 +280,6 @@ class ContinueSDK(AbstractContinueSDK): ) if only_editing else self.__autopilot._highlighted_ranges return [c.range for c in context] - 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) raise NotImplementedError() |
