summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--continuedev/src/continuedev/core/policy.py4
-rw-r--r--continuedev/src/continuedev/libs/steps/main.py108
-rw-r--r--continuedev/src/continuedev/models/main.py2
3 files changed, 74 insertions, 40 deletions
diff --git a/continuedev/src/continuedev/core/policy.py b/continuedev/src/continuedev/core/policy.py
index 5a6652f4..504d5ff1 100644
--- a/continuedev/src/continuedev/core/policy.py
+++ b/continuedev/src/continuedev/core/policy.py
@@ -6,7 +6,7 @@ from ..models.main import ContinueBaseModel
from ..libs.steps.ty import CreatePipelineStep
from .main import Step, Validator, History, Policy
from .observation import Observation, TracebackObservation, UserInputObservation
-from ..libs.steps.main import EditHighlightedCodeStep, SolveTracebackStep, RunCodeStep
+from ..libs.steps.main import EditHighlightedCodeStep, SolveTracebackStep, RunCodeStep, FasterEditHighlightedCodeStep
from ..libs.steps.nate import WritePytestsStep, CreateTableStep
from ..libs.steps.chroma import AnswerQuestionChroma, EditFileChroma
from ..libs.steps.continue_step import ContinueStepStep
@@ -32,7 +32,7 @@ class DemoPolicy(Policy):
return EditFileChroma(request=" ".join(observation.user_input.split(" ")[1:]))
elif "/step" in observation.user_input:
return ContinueStepStep(prompt=" ".join(observation.user_input.split(" ")[1:]))
- return EditHighlightedCodeStep(user_input=observation.user_input)
+ return FasterEditHighlightedCodeStep(user_input=observation.user_input)
state = history.get_current()
if state is None or not self.ran_code_last:
diff --git a/continuedev/src/continuedev/libs/steps/main.py b/continuedev/src/continuedev/libs/steps/main.py
index f28cb23f..59df114e 100644
--- a/continuedev/src/continuedev/libs/steps/main.py
+++ b/continuedev/src/continuedev/libs/steps/main.py
@@ -77,41 +77,45 @@ class FasterEditHighlightedCodeStep(Step):
hide = True
_completion: str = "Edit Code"
_edit_diffs: Union[List[EditDiff], None] = None
- _prompt: str = dedent("""Below is the code before changes:
-
-{code}
-
-This is the user request:
-
-{user_input}
-
-Edit the code to perfectly satifsfy the user request. Format the changes you want to make as a comma-separated array of JSON objects of the form:
-{{
- "edits": [{{
- "filepath": <FILEPATH>,
- "replace_me": <CODE_TO_REPLACE>,
- "replace_with": <CODE_TO_REPLACE_WITH>
- }}]
-}}
-
-For example, if you want to replace the code `x = 1` with `x = 2` in main.py, you would write:
-{{
- "edits": [{{
- "filepath": "main.py",
- "replace_me": "x = 1",
- "replace_with": "x = 2"
- }}]
-}}
-If you wanted to delete the code `def sum(a, b):\\n return a + b` in main.py, you would write:
-{{
- "edits": [{{
- "filepath": "main.py",
- "replace_me": "def sum(a, b):\\n return a + b",
- "replace_with": ""
- }}]
-}}
-
-Respond with only as many edits as needed, and output only the list of json objects, no other text.
+ _prompt: str = dedent("""\
+ You will be given code to edit in order to perfectly satisfy the user request. All the changes you make must be described as replacements, which you should format in the following way:
+ FILEPATH
+ <FILE_TO_EDIT>
+ REPLACE_ME
+ <CODE_TO_REPLACE>
+ REPLACE_WITH
+ <CODE_TO_REPLACE_WITH>
+
+ where <CODE_TO_REPLACE> and <CODE_TO_REPLACE_WITH> can be multiple lines, but should be the mininum needed to make the edit. Be sure to maintain existing whitespace at the start of lines.
+
+ For example, if you want to replace the code `x = 1` with `x = 2` in main.py, you would write:
+ FILEPATH
+ main.py
+ REPLACE_ME
+ x = 1
+ REPLACE_WITH
+ x = 2
+ If you wanted to delete the code
+ ```
+ def sum(a, b):
+ return a + b
+ ```
+ in main.py, you would write:
+ FILEPATH
+ main.py
+ REPLACE_ME
+ def sum(a, b):
+ return a + b
+ REPLACE_WITH
+
+ You may need to make multiple edits; respond with exactly as many as needed.
+
+ Below is the code before changes:
+
+ {code}
+
+ This is the user request: "{user_input}"
+ Here is the description of changes to make:
""")
async def describe(self, llm: LLM) -> Coroutine[str, None, None]:
@@ -148,11 +152,41 @@ Respond with only as many edits as needed, and output only the list of json obje
# Temporarily doing this to generate description.
self._prompt = prompt
self._completion = completion
+ print(completion)
# ALTERNATIVE DECODING STEP HERE
+ raw_file_edits = []
+ lines = completion.split("\n")
+ current_edit = {}
+ status = "FILEPATH"
+ for i in range(0, len(lines)):
+ line = lines[i]
+ if line == "FILEPATH":
+ if "FILEPATH" in current_edit:
+ raw_file_edits.append(current_edit)
+ current_edit = {}
+ status = "FILEPATH"
+ elif line == "REPLACE_ME":
+ status = "REPLACE_ME"
+ elif line == "REPLACE_WITH":
+ status = "REPLACE_WITH"
+ elif status == "FILEPATH":
+ current_edit["filepath"] = line
+ elif status == "REPLACE_ME":
+ if "replace_me" in current_edit:
+ current_edit["replace_me"] += "\n" + line
+ else:
+ current_edit["replace_me"] = line
+ elif status == "REPLACE_WITH":
+ if "replace_with" in current_edit:
+ current_edit["replace_with"] += "\n" + line
+ else:
+ current_edit["replace_with"] = line
+ if "filepath" in current_edit:
+ raw_file_edits.append(current_edit)
+
file_edits = []
- obj = json.loads(completion.strip())
- for edit in obj["edits"]:
+ for edit in raw_file_edits:
filepath = edit["filepath"]
replace_me = edit["replace_me"]
replace_with = edit["replace_with"]
diff --git a/continuedev/src/continuedev/models/main.py b/continuedev/src/continuedev/models/main.py
index 7986b30c..5bd65a76 100644
--- a/continuedev/src/continuedev/models/main.py
+++ b/continuedev/src/continuedev/models/main.py
@@ -32,7 +32,7 @@ class Position(BaseModel):
def from_index(string: str, index: int) -> "Position":
"""Convert index in string to line and character"""
line = string.count("\n", 0, index)
- if line == 1:
+ if line == 0:
character = index
else:
character = index - string.rindex("\n", 0, index) - 1