Giter Site home page Giter Site logo

Comments (1)

ErikBjare avatar ErikBjare commented on June 19, 2024

🚀 Here's the PR! #81

See Sweep's progress at the progress dashboard!
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: None)
Install Sweep Configs: Pull Request

Tip

I can email you next time I complete a pull request if you set up your email here!


Actions (click)

  • ↻ Restart Sweep

Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description.

"""
Gives the LLM agent the ability to patch files, by using a adapted version git conflict markers.
Example:
.. chat::
User: patch the file `hello.py` to ask for the name of the user
Assistant:
```patch hello.py
<<<<<<< ORIGINAL
print("Hello world")
=======
name = input("What is your name? ")
print(f"hello {name}")
>>>>>>> UPDATED
```
System: Patch applied
Inspired by aider.
"""
import re
from collections.abc import Generator
from pathlib import Path
from ..message import Message
from ..util import ask_execute
instructions = """
To patch/modify files, we can use an adapted version of git conflict markers.
This can be used to make changes to files we have written in the past, without having to rewrite the whole file.
Only one Patches should written one per codeblock. Do not continue the codeblock after the UPDATED marker.
Try to keep the patch as small as possible.
We can also append to files by prefixing the filename with `append`."""
examples = """
> User: patch the file `hello.py` to ask for the name of the user
```patch hello.py
<<<<<<< ORIGINAL
print("Hello world")
=======
name = input("What is your name? ")
print(f"hello {name}")
>>>>>>> UPDATED
```
> User: run the function when the script is run
```append hello.py
if __name__ == "__main__":
hello()
```
""".strip()
ORIGINAL = "\n<<<<<<< ORIGINAL\n"
DIVIDER = "\n=======\n"
UPDATED = ">>>>>>> UPDATED\n"
def apply(codeblock: str, content: str) -> str:
"""
Applies the patch in ``codeblock`` to ``content``.
"""
# TODO: support multiple patches in one codeblock,
# or make it clear that only one patch per codeblock is supported
codeblock = codeblock.strip()
# get the original and modified chunks
if ORIGINAL not in codeblock: # pragma: no cover
raise ValueError(f"invalid patch, no `{ORIGINAL.strip()}`", codeblock)
original = re.split(ORIGINAL, codeblock)[1]
if DIVIDER not in original: # pragma: no cover
raise ValueError(f"invalid patch, no `{DIVIDER.strip()}`", codeblock)
original, modified = re.split(DIVIDER, original)
if UPDATED not in modified: # pragma: no cover
raise ValueError(f"invalid patch, no `{UPDATED.strip()}`", codeblock)
modified = re.split(UPDATED, modified)[0].rstrip("\n")
# TODO: maybe allow modified chunk to contain "// ..." to refer to chunks in the original,
# and then replace these with the original chunks?
# replace the original chunk with the modified chunk
new = content.replace(original, modified)
if new == content: # pragma: no cover
raise ValueError("patch did not change the file")
return new
def apply_file(codeblock, filename):
codeblock = codeblock.strip()
_patch, filename = codeblock.splitlines()[0].split()
if not _patch == "```patch":
raise ValueError(
"invalid patch, codeblock is missing leading ```patch", codeblock
)
if not Path(filename).exists():
raise FileNotFoundError(filename)
with open(filename) as f:
content = f.read()
result = apply(codeblock, content)
with open(filename, "w") as f:
f.write(result)
print(f"Applied patch to {filename}")
def execute_patch(codeblock: str, fn: str, ask: bool) -> Generator[Message, None, None]:
"""
Applies the patch.
"""
if ask:
confirm = ask_execute("Apply patch?")
if not confirm:
print("Patch not applied")
return
try:
apply_file(codeblock, fn)
yield Message("system", "Patch applied")
except (ValueError, FileNotFoundError) as e:


Step 2: ⌨️ Coding

Modify gptme/tools/patch.py with contents:
• Inside the `apply` function, after extracting the `original` and `modified` chunks from the codeblock (right after line 80), add logic to escape backslashes in the `modified` chunk. This can be achieved by replacing single backslashes (`\`) with double backslashes (`\\`). This ensures that when the modified chunk is interpreted as a string in Python, the backslashes are treated correctly.
• Specifically, add the following line of code after line 80: ```python modified = modified.replace("\\", "\\\\") ```
• This change ensures that any backslashes in the modified chunk are correctly escaped, preventing errors when the patched content is interpreted as TOML or any other format that may be sensitive to unescaped backslashes.
--- 
+++ 
@@ -79,6 +79,7 @@
     if UPDATED not in modified:  # pragma: no cover
         raise ValueError(f"invalid patch, no `{UPDATED.strip()}`", codeblock)
     modified = re.split(UPDATED, modified)[0].rstrip("\n")
+    modified = modified.replace("\\", "\\\\")
 
     # TODO: maybe allow modified chunk to contain "// ..." to refer to chunks in the original,
     #       and then replace these with the original chunks?
  • Running GitHub Actions for gptme/tools/patch.pyEdit
Check gptme/tools/patch.py with contents:

Ran GitHub Actions for 93ca0919d95db85cbeaa8005d58b95e219e60601:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/edit_fails_to_parse_some_messages_with_i.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description.
Something wrong? Let us know.

This is an automated message generated by Sweep AI.

from gptme.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.