diff options
Diffstat (limited to 'continuedev/src')
9 files changed, 28 insertions, 28 deletions
| diff --git a/continuedev/src/continuedev/core/autopilot.py b/continuedev/src/continuedev/core/autopilot.py index d55e521b..b227570e 100644 --- a/continuedev/src/continuedev/core/autopilot.py +++ b/continuedev/src/continuedev/core/autopilot.py @@ -118,7 +118,7 @@ class Autopilot(ContinueBaseModel):                  f"\n{error_string}\n{e}")              observation = InternalErrorObservation( -                error=error_string) +                error=error_string, title=e.title)              step.hide = False          except Exception as e:              # Attach an InternalErrorObservation to the step and unhide it. @@ -128,7 +128,7 @@ class Autopilot(ContinueBaseModel):                  f"Error while running step: \n{error_string}\n{e}")              observation = InternalErrorObservation( -                error=error_string) +                error=error_string, title=e.__repr__())              step.hide = False          self._step_depth -= 1 diff --git a/continuedev/src/continuedev/core/main.py b/continuedev/src/continuedev/core/main.py index 17b30e96..33e25c93 100644 --- a/continuedev/src/continuedev/core/main.py +++ b/continuedev/src/continuedev/core/main.py @@ -181,10 +181,12 @@ class Context:  class ContinueCustomException(Exception): +    title: str      message: str -    def __init__(self, message: str): +    def __init__(self, message: str, title: str = "Error while running step:"):          self.message = message +        self.title = title  HistoryNode.update_forward_refs() diff --git a/continuedev/src/continuedev/core/observation.py b/continuedev/src/continuedev/core/observation.py index b6117236..126cf19e 100644 --- a/continuedev/src/continuedev/core/observation.py +++ b/continuedev/src/continuedev/core/observation.py @@ -36,4 +36,5 @@ class TextObservation(Observation):  class InternalErrorObservation(Observation): +    title: str      error: str diff --git a/continuedev/src/continuedev/core/sdk.py b/continuedev/src/continuedev/core/sdk.py index 690949f1..f4aa2b35 100644 --- a/continuedev/src/continuedev/core/sdk.py +++ b/continuedev/src/continuedev/core/sdk.py @@ -75,9 +75,9 @@ class ContinueSDK(AbstractContinueSDK):      async def wait_for_user_confirmation(self, prompt: str):          return await self.run_step(WaitForUserConfirmationStep(prompt=prompt)) -    async def run(self, commands: Union[List[str], str], cwd: str = None, name: str = None, description: str = None): +    async def run(self, commands: Union[List[str], str], cwd: str = None, name: str = None, description: str = None) -> Coroutine[str, None, None]:          commands = commands if isinstance(commands, List) else [commands] -        return await self.run_step(ShellCommandsStep(cmds=commands, cwd=cwd, description=description, **({'name': name} if name else {}))) +        return (await self.run_step(ShellCommandsStep(cmds=commands, cwd=cwd, description=description, **({'name': name} if name else {})))).text      async def edit_file(self, filename: str, prompt: str, name: str = None, description: str = None):          filepath = await self._ensure_absolute_path(filename) @@ -131,5 +131,5 @@ class ContinueSDK(AbstractContinueSDK):          # self.__autopilot.set_loading_message(message)          raise NotImplementedError() -    def raise_exception(self, message: str): -        raise ContinueCustomException(message) +    def raise_exception(self, message: str, title: str): +        raise ContinueCustomException(message, title) diff --git a/continuedev/src/continuedev/recipes/CreatePipelineRecipe/main.py b/continuedev/src/continuedev/recipes/CreatePipelineRecipe/main.py index 1206db0e..428ac9cc 100644 --- a/continuedev/src/continuedev/recipes/CreatePipelineRecipe/main.py +++ b/continuedev/src/continuedev/recipes/CreatePipelineRecipe/main.py @@ -22,7 +22,7 @@ class CreatePipelineRecipe(Step):                  - Load the data into a local DuckDB instance                  - Write a query to view the data""")) >>              WaitForUserInputStep( -                prompt="What API do you want to load data from?") +                prompt="What API do you want to load data from? (e.g. weatherapi.com, chess.com)")          )          await sdk.run_step(              SetupPipelineStep(api_description=text_observation.text) >> diff --git a/continuedev/src/continuedev/recipes/CreatePipelineRecipe/steps.py b/continuedev/src/continuedev/recipes/CreatePipelineRecipe/steps.py index 3c8277c0..9bee4c95 100644 --- a/continuedev/src/continuedev/recipes/CreatePipelineRecipe/steps.py +++ b/continuedev/src/continuedev/recipes/CreatePipelineRecipe/steps.py @@ -34,8 +34,7 @@ class SetupPipelineStep(Step):              'python3 -m venv env',              'source env/bin/activate',              'pip install dlt', -            f'dlt init {source_name} duckdb', -            'Y', +            f'dlt init {source_name} duckdb\n\rY',              'pip install -r requirements.txt'          ], description=dedent(f"""\              Running the following commands: @@ -43,9 +42,8 @@ class SetupPipelineStep(Step):              - `source env/bin/activate`: Activate the virtual environment              - `pip install dlt`: Install dlt              - `dlt init {source_name} duckdb`: Create a new dlt pipeline called {source_name} that loads data into a local DuckDB instance -            - `pip install -r requirements.txt`: Install the Python dependencies for the pipeline""")) +            - `pip install -r requirements.txt`: Install the Python dependencies for the pipeline"""), name="Setup Python environment") -        await sdk.wait_for_user_confirmation("Wait for the commands to finish running, then press `Continue`")          # editing the resource function to call the requested API          await sdk.ide.highlightCode(RangeInFile(filepath=os.path.join(await sdk.ide.getWorkspaceDirectory(), filename), range=Range.from_shorthand(15, 0, 30, 0)), "#00ff0022") @@ -78,17 +76,12 @@ class ValidatePipelineStep(Step):          #         """)))          # test that the API call works - -        p = subprocess.run( -            ['python3', f'{filename}'], capture_output=True, text=True, cwd=workspace_dir) -        err = p.stderr +        output = await sdk.run(f'python3 {filename}', name="Test the pipeline", description=f"Running python3 {filename} to test loading data from the API")          # If it fails, return the error -        if err is not None and err != "": +        if "Traceback" in output:              sdk.raise_exception( -                f"Error while running pipeline. Fix the resource function in {filename} and rerun this step: \n\n" + err) - -        await sdk.run(f'python3 {filename}', name="Test the pipeline", description=f"Running python3 {filename} to test loading data from the API") +                title="Error while running pipeline.\nFix the resource function in {filename} and rerun this step", description=output)          # remove exit() from the main main function          await sdk.edit_file( diff --git a/continuedev/src/continuedev/server/ide.py b/continuedev/src/continuedev/server/ide.py index 073e1dba..007eb2b4 100644 --- a/continuedev/src/continuedev/server/ide.py +++ b/continuedev/src/continuedev/server/ide.py @@ -76,6 +76,10 @@ class GetUserSecretResponse(BaseModel):      value: str +class RunCommandResponse(BaseModel): +    output: str + +  T = TypeVar("T", bound=BaseModel) @@ -110,7 +114,7 @@ class IdeProtocolServer(AbstractIdeProtocolServer):              fileEdits = list(                  map(lambda d: FileEditWithFullContents.parse_obj(d), data["fileEdits"]))              self.onFileEdits(fileEdits) -        elif message_type in ["highlightedCode", "openFiles", "readFile", "editFile", "workspaceDirectory", "getUserSecret"]: +        elif message_type in ["highlightedCode", "openFiles", "readFile", "editFile", "workspaceDirectory", "getUserSecret", "runCommand"]:              self.sub_queue.post(message_type, data)          else:              raise ValueError("Unknown message type", message_type) @@ -139,10 +143,8 @@ class IdeProtocolServer(AbstractIdeProtocolServer):              "color": color          }) -    async def runCommand(self, command: str): -        await self._send_json("runCommand", { -            "command": command -        }) +    async def runCommand(self, command: str) -> str: +        return (await self._send_and_receive_json({"command": command}, RunCommandResponse, "runCommand")).output      async def showSuggestionsAndWait(self, suggestions: List[FileEdit]) -> bool:          ids = [str(uuid.uuid4()) for _ in suggestions] diff --git a/continuedev/src/continuedev/server/ide_protocol.py b/continuedev/src/continuedev/server/ide_protocol.py index f42de68f..4622d6ff 100644 --- a/continuedev/src/continuedev/server/ide_protocol.py +++ b/continuedev/src/continuedev/server/ide_protocol.py @@ -88,5 +88,5 @@ class AbstractIdeProtocolServer(ABC):          """Highlight code"""      @abstractmethod -    async def runCommand(self, command: str): +    async def runCommand(self, command: str) -> str:          """Run a command""" diff --git a/continuedev/src/continuedev/steps/core/core.py b/continuedev/src/continuedev/steps/core/core.py index 99786b00..c6dc7c04 100644 --- a/continuedev/src/continuedev/steps/core/core.py +++ b/continuedev/src/continuedev/steps/core/core.py @@ -56,7 +56,9 @@ class ShellCommandsStep(Step):          cwd = await sdk.ide.getWorkspaceDirectory() if self.cwd is None else self.cwd          for cmd in self.cmds: -            await sdk.ide.runCommand(cmd) +            output = await sdk.ide.runCommand(cmd) + +        return TextObservation(text=output)          # process = subprocess.Popen(          #     '/bin/bash', stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=cwd) @@ -205,7 +207,7 @@ class WaitForUserInputStep(Step):      async def run(self, sdk: ContinueSDK) -> Coroutine[Observation, None, None]:          self.description = self.prompt          resp = await sdk.wait_for_user_input() -        self._response = resp +        self.description = f"{self.prompt}\n\n`{resp}`"          return TextObservation(text=resp) | 
