diff options
| author | Nate Sesti <sestinj@gmail.com> | 2023-07-30 22:30:00 -0700 |
|---|---|---|
| committer | Nate Sesti <sestinj@gmail.com> | 2023-07-30 22:30:00 -0700 |
| commit | 57a572a420e16b08301f0c6738a1b414c59bce85 (patch) | |
| tree | 2bdbc7831d66aafefe30a9e236ecc150d80024cc /continuedev/src/continuedev/core | |
| parent | 1bc5777ed168e47e2ef2ab1b33eecf6cbd170a61 (diff) | |
| parent | 8bd76be6c0925e0d5e5f6d239e9c6907df3cfd23 (diff) | |
| download | sncontinue-57a572a420e16b08301f0c6738a1b414c59bce85.tar.gz sncontinue-57a572a420e16b08301f0c6738a1b414c59bce85.tar.bz2 sncontinue-57a572a420e16b08301f0c6738a1b414c59bce85.zip | |
Merge remote-tracking branch 'continuedev/main' into llm-object-config-merge-main
Diffstat (limited to 'continuedev/src/continuedev/core')
| -rw-r--r-- | continuedev/src/continuedev/core/autopilot.py | 13 | ||||
| -rw-r--r-- | continuedev/src/continuedev/core/config.py | 39 | ||||
| -rw-r--r-- | continuedev/src/continuedev/core/context.py | 47 | ||||
| -rw-r--r-- | continuedev/src/continuedev/core/sdk.py | 40 |
4 files changed, 57 insertions, 82 deletions
diff --git a/continuedev/src/continuedev/core/autopilot.py b/continuedev/src/continuedev/core/autopilot.py index beb40c75..b4c951b8 100644 --- a/continuedev/src/continuedev/core/autopilot.py +++ b/continuedev/src/continuedev/core/autopilot.py @@ -15,12 +15,13 @@ from ..server.ide_protocol import AbstractIdeProtocolServer 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 ..plugins.steps.core.core import DisplayErrorStep, ReversibleStep, ManualEditStep, UserInputStep 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 +from ..libs.util.logging import logger def get_error_title(e: Exception) -> str: @@ -74,7 +75,7 @@ class Autopilot(ContinueBaseModel): HighlightedCodeContextProvider(ide=ide), FileContextProvider(workspace_dir=ide.workspace_directory) ]) - await autopilot.context_manager.load_index() + await autopilot.context_manager.load_index(ide.workspace_directory) return autopilot @@ -152,7 +153,7 @@ class Autopilot(ContinueBaseModel): await self.update_subscribers() except Exception as e: - print(e) + logger.debug(e) def handle_manual_edits(self, edits: List[FileEditWithFullContents]): for edit in edits: @@ -257,7 +258,7 @@ class Autopilot(ContinueBaseModel): e) # Attach an InternalErrorObservation to the step and unhide it. - print( + logger.error( f"Error while running step: \n{error_string}\n{error_title}") posthog_logger.capture_event('step error', { 'error_message': error_string, 'error_title': error_title, 'step_name': step.name, 'params': step.dict()}) @@ -310,8 +311,8 @@ class Autopilot(ContinueBaseModel): # Update subscribers with new description await self.update_subscribers() - create_async_task(update_description(), - self.continue_sdk.ide.unique_id) + create_async_task(update_description( + ), on_error=lambda e: self.continue_sdk.run_step(DisplayErrorStep(e=e))) return observation diff --git a/continuedev/src/continuedev/core/config.py b/continuedev/src/continuedev/core/config.py index af37264d..4fcab588 100644 --- a/continuedev/src/continuedev/core/config.py +++ b/continuedev/src/continuedev/core/config.py @@ -49,45 +49,6 @@ class ContinueConfig(BaseModel): context_providers: List[ContextProvider] = [] - # Want to force these to be the slash commands for now - @validator('slash_commands', pre=True) - def default_slash_commands_validator(cls, v): - from ..plugins.steps.open_config import OpenConfigStep - from ..plugins.steps.clear_history import ClearHistoryStep - from ..plugins.steps.feedback import FeedbackStep - from ..plugins.steps.comment_code import CommentCodeStep - from ..plugins.steps.main import EditHighlightedCodeStep - - DEFAULT_SLASH_COMMANDS = [ - SlashCommand( - name="edit", - description="Edit code in the current file or the highlighted code", - step=EditHighlightedCodeStep, - ), - SlashCommand( - name="config", - description="Open the config file to create new and edit existing slash commands", - step=OpenConfigStep, - ), - SlashCommand( - name="comment", - description="Write comments for the current file or highlighted code", - step=CommentCodeStep, - ), - SlashCommand( - name="feedback", - description="Send feedback to improve Continue", - step=FeedbackStep, - ), - SlashCommand( - name="clear", - description="Clear step history", - step=ClearHistoryStep, - ) - ] - - return DEFAULT_SLASH_COMMANDS + v - @validator('temperature', pre=True) def temperature_validator(cls, v): return max(0.0, min(1.0, v)) diff --git a/continuedev/src/continuedev/core/context.py b/continuedev/src/continuedev/core/context.py index 8afbd610..e968c35c 100644 --- a/continuedev/src/continuedev/core/context.py +++ b/continuedev/src/continuedev/core/context.py @@ -7,7 +7,7 @@ from pydantic import BaseModel from .main import ChatMessage, ContextItem, ContextItemDescription, ContextItemId from ..server.meilisearch_server import check_meilisearch_running - +from ..libs.util.logging import logger SEARCH_INDEX_NAME = "continue_context_items" @@ -35,7 +35,7 @@ class ContextProvider(BaseModel): return self.selected_items @abstractmethod - async def provide_context_items(self) -> List[ContextItem]: + async def provide_context_items(self, workspace_dir: str) -> List[ContextItem]: """ Provide documents for search index. This is run on startup. @@ -57,16 +57,22 @@ class ContextProvider(BaseModel): Default implementation uses the search index to get the item. """ async with Client('http://localhost:7700') as search_client: - result = await search_client.index( - SEARCH_INDEX_NAME).get_document(id.to_string()) - return ContextItem( - description=ContextItemDescription( - name=result["name"], - description=result["description"], - id=id - ), - content=result["content"] - ) + try: + result = await search_client.index( + SEARCH_INDEX_NAME).get_document(id.to_string()) + return ContextItem( + description=ContextItemDescription( + name=result["name"], + description=result["description"], + id=id + ), + content=result["content"] + ) + except Exception as e: + logger.warning( + f"Error while retrieving document from meilisearch: {e}") + + return None async def delete_context_with_ids(self, ids: List[ContextItemId]): """ @@ -100,8 +106,8 @@ class ContextProvider(BaseModel): if item.description.id.item_id == id.item_id: return - new_item = await self.get_item(id, query) - self.selected_items.append(new_item) + if new_item := await self.get_item(id, query): + self.selected_items.append(new_item) class ContextManager: @@ -146,16 +152,16 @@ class ContextManager: meilisearch_running = False if not meilisearch_running: - print( + logger.warning( "MeiliSearch not running, avoiding any dependent context providers") context_providers = list( filter(lambda cp: cp.title == "code", context_providers)) return cls(context_providers) - async def load_index(self): + async def load_index(self, workspace_dir: str): for _, provider in self.context_providers.items(): - context_items = await provider.provide_context_items() + context_items = await provider.provide_context_items(workspace_dir) documents = [ { "id": item.description.id.to_string(), @@ -166,8 +172,11 @@ class ContextManager: for item in context_items ] if len(documents) > 0: - async with Client('http://localhost:7700') as search_client: - await search_client.index(SEARCH_INDEX_NAME).add_documents(documents) + try: + async with Client('http://localhost:7700') as search_client: + await search_client.index(SEARCH_INDEX_NAME).add_documents(documents) + except Exception as e: + logger.debug(f"Error loading meilisearch index: {e}") async def select_context_item(self, id: str, query: str): """ diff --git a/continuedev/src/continuedev/core/sdk.py b/continuedev/src/continuedev/core/sdk.py index 1dd4b857..be7008c0 100644 --- a/continuedev/src/continuedev/core/sdk.py +++ b/continuedev/src/continuedev/core/sdk.py @@ -1,5 +1,6 @@ from functools import cached_property -from typing import Coroutine, Dict, Union +import traceback +from typing import Coroutine, Dict, Literal, Union import os from ..plugins.steps.core.core import DefaultModelEditCodeStep @@ -16,6 +17,7 @@ from ..plugins.steps.core.core import * from ..libs.util.telemetry import posthog_logger from ..libs.util.paths import getConfigFilePath from .models import Models +from ..libs.util.logging import logger class Autopilot: @@ -43,11 +45,15 @@ class ContinueSDK(AbstractContinueSDK): config = sdk._load_config_dot_py() sdk.config = config except Exception as e: - print(e) - sdk.config = ContinueConfig() + logger.error(f"Failed to load config.py: {e}") + + sdk.config = ContinueConfig( + ) if sdk._last_valid_config is None else sdk._last_valid_config + + formatted_err = '\n'.join(traceback.format_exception(e)) msg_step = MessageStep( - name="Invalid Continue Config File", message=e.__repr__()) - msg_step.description = e.__repr__() + name="Invalid Continue Config File", message=formatted_err) + msg_step.description = f"Falling back to default config settings.\n```\n{formatted_err}\n```" sdk.history.add_node(HistoryNode( step=msg_step, observation=None, @@ -57,6 +63,11 @@ class ContinueSDK(AbstractContinueSDK): sdk.models = sdk.config.models await sdk.models.start(sdk) + + # When the config is loaded, setup posthog logger + posthog_logger.setup( + sdk.ide.unique_id, sdk.config.allow_anonymous_telemetry) + return sdk @property @@ -154,21 +165,14 @@ class ContinueSDK(AbstractContinueSDK): def _load_config_dot_py(self) -> ContinueConfig: # Use importlib to load the config file config.py at the given path path = getConfigFilePath() - try: - import importlib.util - spec = importlib.util.spec_from_file_location("config", path) - 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) + import importlib.util + spec = importlib.util.spec_from_file_location("config", path) + config = importlib.util.module_from_spec(spec) + spec.loader.exec_module(config) + self._last_valid_config = config.config - return config.config - except Exception as e: - print("Error loading config.py: ", e) - return ContinueConfig() if self._last_valid_config is None else self._last_valid_config + return config.config def get_code_context(self, only_editing: bool = False) -> List[RangeInFileWithContents]: highlighted_ranges = self.__autopilot.context_manager.context_providers[ |
