fixed final (query) step in CreatePipelineRecipe

This commit is contained in:
Nate Sesti 2023-06-09 12:10:45 -04:00
parent c6f70eac0d
commit d7fad7f55a
5 changed files with 40 additions and 13 deletions

View file

@ -22,11 +22,6 @@ class Autopilot:
pass
class ContinueSDKSteps:
def __init__(self, sdk: "ContinueSDK"):
self.sdk = sdk
class Models:
def __init__(self, sdk: "ContinueSDK"):
self.sdk = sdk
@ -51,7 +46,6 @@ class Models:
class ContinueSDK(AbstractContinueSDK):
"""The SDK provided as parameters to a step"""
ide: AbstractIdeProtocolServer
steps: ContinueSDKSteps
models: Models
context: Context
__autopilot: Autopilot
@ -59,7 +53,6 @@ class ContinueSDK(AbstractContinueSDK):
def __init__(self, autopilot: Autopilot):
self.ide = autopilot.ide
self.__autopilot = autopilot
self.steps = ContinueSDKSteps(self)
self.models = Models(self)
self.context = autopilot.context

View file

@ -4,7 +4,7 @@ from ...core.main import Step
from ...core.sdk import ContinueSDK
from ...steps.core.core import WaitForUserInputStep
from ...steps.main import MessageStep
from .steps import SetupPipelineStep, ValidatePipelineStep
from .steps import SetupPipelineStep, ValidatePipelineStep, RunQueryStep
class CreatePipelineRecipe(Step):
@ -26,5 +26,6 @@ class CreatePipelineRecipe(Step):
)
await sdk.run_step(
SetupPipelineStep(api_description=text_observation.text) >>
ValidatePipelineStep()
ValidatePipelineStep() >>
RunQueryStep()
)

View file

@ -134,15 +134,16 @@ class ValidatePipelineStep(Step):
# load the data into the DuckDB instance
await sdk.run(f'python3 {filename}', name="Load data into DuckDB", description=f"Running python3 {filename} to load data into DuckDB")
table_name = f"{source_name}_data.{source_name}_resource"
tables_query_code = dedent(f'''\
import duckdb
# connect to DuckDB instance
conn = duckdb.connect(database="{source_name}.duckdb")
conn.execute("SET search_path = '{source_name}_data';")
# get table names
rows = conn.execute("SELECT * FROM {table_name};").fetchall()
rows = conn.execute("SELECT * FROM _dlt_loads;").fetchall()
# print table names
for row in rows:
@ -150,4 +151,27 @@ class ValidatePipelineStep(Step):
query_filename = os.path.join(workspace_dir, "query.py")
await sdk.apply_filesystem_edit(AddFile(filepath=query_filename, content=tables_query_code), name="Add query.py file", description="Adding a file called `query.py` to the workspace that will run a test query on the DuckDB instance")
await sdk.run('env/bin/python3 query.py', name="Run test query", description="Running `env/bin/python3 query.py` to test that the data was loaded into DuckDB as expected")
class RunQueryStep(Step):
hide: bool = True
async def run(self, sdk: ContinueSDK):
output = await sdk.run('env/bin/python3 query.py', name="Run test query", description="Running `env/bin/python3 query.py` to test that the data was loaded into DuckDB as expected")
if "Traceback" in output or "SyntaxError" in output:
suggestion = sdk.models.gpt35.complete(dedent(f"""\
```python
{await sdk.ide.readFile(os.path.join(sdk.ide.workspace_directory, "query.py"))}
```
This above code is a query that runs on the DuckDB instance. While attempting to run the query, the following error occurred:
```ascii
{output}
```
This is a brief summary of the error followed by a suggestion on how it can be fixed:"""))
sdk.raise_exception(
title="Error while running query", message=output, with_step=MessageStep(name=f"Suggestion to solve error {AI_ASSISTED_STRING}", message=suggestion)
)

View file

@ -1,5 +1,6 @@
# This is a separate server from server/main.py
import asyncio
from functools import cached_property
import json
import os
from typing import Any, Dict, List, Type, TypeVar, Union
@ -199,6 +200,10 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
resp = await self._send_and_receive_json({}, WorkspaceDirectoryResponse, "workspaceDirectory")
return resp.workspaceDirectory
@cached_property
def workspace_directory(self) -> str:
return asyncio.run(self.getWorkspaceDirectory())
async def getHighlightedCode(self) -> List[RangeInFile]:
resp = await self._send_and_receive_json({}, HighlightedCodeResponse, "highlightedCode")
return resp.highlightedCode

View file

@ -1,5 +1,5 @@
from typing import Any, List
from abc import ABC, abstractmethod
from abc import ABC, abstractmethod, abstractproperty
from ..models.main import Traceback
from ..models.filesystem_edit import FileEdit, FileSystemEdit, EditDiff
@ -90,3 +90,7 @@ class AbstractIdeProtocolServer(ABC):
@abstractmethod
async def runCommand(self, command: str) -> str:
"""Run a command"""
@abstractproperty
def workspace_directory(self) -> str:
"""Get the workspace directory"""