nus-apr / auto-code-rover

A project structure aware autonomous software engineer aiming for autonomous program improvement. Resolved 30.67% tasks (pass@1) in SWE-bench lite with each task costs less than $0.7.
Other
2.37k stars 236 forks source link

Add a mode for running on new GitHub issues #25

Closed yuntongzhang closed 2 months ago

yuntongzhang commented 2 months ago

Add a new mode to make ACR generate patches for new GitHub issues outside of SWE-bench.

To use:

PYTHONPATH=. python app/main.py --mode fresh_issue --output-dir output --setup-dir setup --model gpt-4-0125-preview --model-temperature 0.2 --fresh-task-id <create own id> --clone-link <link for cloning the project> --commit-hash <any version that has the issue> --issue-link <link to issue page>

If successful, path to the generated patch will be printed after execution.

Here are some issues that have been tested on:

  1. https://github.com/langchain-ai/langchain/issues/20453

Run ACR with the following command:

PYTHONPATH=. python app/main.py --mode fresh_issue --output-dir output --setup-dir setup --model gpt-4-0125-preview --model-temperature 0.2 --fresh-task-id langchain-20453 --clone-link https://github.com/langchain-ai/langchain.git --commit-hash b66a4f4 --issue-link https://github.com/langchain-ai/langchain/issues/20453

ACR generates the following patch:

diff --git a/libs/community/langchain_community/chat_models/pai_eas_endpoint.py b/libs/community/langchain_community/chat_models/pai_eas_endpoint.py
index e438ad25e..d62545543 100644
--- a/libs/community/langchain_community/chat_models/pai_eas_endpoint.py
+++ b/libs/community/langchain_community/chat_models/pai_eas_endpoint.py
@@ -227,7 +227,7 @@ class PaiEasChatEndpoint(BaseChatModel):
                 f" and message {response.text}"
             )

-        return response.text
+        return response.content

     def _call_eas_stream(self, query_body: dict) -> Any:
         """Generate text from the eas service."""
  1. https://github.com/langchain-ai/langchain/issues/20445

Run ACR with the following command:

PYTHONPATH=. python app/main.py --mode fresh_issue --output-dir output --setup-dir setup --model gpt-4-0125-preview --model-temperature 0.2 --fresh-task-id langchain-20445 --clone-link https://github.com/langchain-ai/langchain.git --commit-hash b66a4f4 --issue-link https://github.com/langchain-ai/langchain/issues/20445

Running it for the first time did not produce a patch. After that, running it for a few more times produced the following patches (patch can be different in each run):

Patch 1:

diff --git a/libs/community/langchain_community/vectorstores/pgvector.py b/libs/community/langchain_community/vectorstores/pgvector.py
index 40fdfe655..8b06ae7d2 100644
--- a/libs/community/langchain_community/vectorstores/pgvector.py
+++ b/libs/community/langchain_community/vectorstores/pgvector.py
@@ -795,13 +795,13 @@ class PGVector(VectorStore):
             )
         elif OR in map(str.lower, value):
             or_clauses = [
-                self._create_filter_clause(key, sub_value)
+                self._create_filter_clause_deprecated(key, sub_value)
                 for sub_value in value_case_insensitive[OR]
             ]
             filter_by_metadata = sqlalchemy.or_(*or_clauses)
         elif AND in map(str.lower, value):
             and_clauses = [
-                self._create_filter_clause(key, sub_value)
+                self._create_filter_clause_deprecated(key, sub_value)
                 for sub_value in value_case_insensitive[AND]
             ]
             filter_by_metadata = sqlalchemy.and_(*and_clauses)

Patch 2:

diff --git a/libs/community/langchain_community/vectorstores/pgvector.py b/libs/community/langchain_community/vectorstores/pgvector.py
index 40fdfe655..449618920 100644
--- a/libs/community/langchain_community/vectorstores/pgvector.py
+++ b/libs/community/langchain_community/vectorstores/pgvector.py
@@ -795,13 +795,13 @@ class PGVector(VectorStore):
             )
         elif OR in map(str.lower, value):
             or_clauses = [
-                self._create_filter_clause(key, sub_value)
+                self._create_filter_clause({key: sub_value})  # Adjusted to pass a single dict
                 for sub_value in value_case_insensitive[OR]
             ]
             filter_by_metadata = sqlalchemy.or_(*or_clauses)
         elif AND in map(str.lower, value):
             and_clauses = [
-                self._create_filter_clause(key, sub_value)
+                self._create_filter_clause({key: sub_value})  # Adjusted to pass a single dict
                 for sub_value in value_case_insensitive[AND]
             ]
             filter_by_metadata = sqlalchemy.and_(*and_clauses)

For this issue, there is already a PR (not merged yet). Patch 1 is doing the same changes as the PR.

  1. https://github.com/psf/black/issues/4296

Run ACR with the following command:

PYTHONPATH=. python app/main.py --mode fresh_issue --output-dir output --setup-dir setup --model gpt-4-0125-preview --model-temperature 0.2 --fresh-task-id black-4296 --clone-link https://github.com/psf/black.git --commit-hash 735733b --issue-link https://github.com/psf/black/issues/4296

ACR generates the following patch:

diff --git a/src/black/linegen.py b/src/black/linegen.py
index 2d9c27a..9e36625 100644
--- a/src/black/linegen.py
+++ b/src/black/linegen.py
@@ -1212,10 +1212,12 @@ def delimiter_split(
         if trailing_comma_safe and leaf.bracket_depth == lowest_depth:
             trailing_comma_safe = _can_add_trailing_comma(leaf, features)

+        # Adjusted to handle standalone comments more gracefully in list comprehensions
         if last_leaf.type == STANDALONE_COMMENT and leaf_idx == last_non_comment_leaf:
-            current_line = _safe_add_trailing_comma(
-                trailing_comma_safe, delimiter_priority, current_line
-            )
+            if not (line.inside_brackets and delimiter_priority in MIGRATE_COMMENT_DELIMITERS):
+                current_line = _safe_add_trailing_comma(
+                    trailing_comma_safe, delimiter_priority, current_line
+                )

         leaf_priority = bt.delimiters.get(id(leaf))
         if leaf_priority == delimiter_priority:
diff --git a/src/black/lines.py b/src/black/lines.py
index 6b65372..a639ec8 100644
--- a/src/black/lines.py
+++ b/src/black/lines.py
@@ -102,16 +102,17 @@ class Line:
         Raises ValueError when any `leaf` is appended after a standalone comment
         or when a standalone comment is not the first leaf on the line.
         """
+        # Modified to allow standalone comments in specific structures like list comprehensions and lambdas
         if (
             self.bracket_tracker.depth == 0
-            or self.bracket_tracker.any_open_for_or_lambda()
+            or (self.bracket_tracker.any_open_for_or_lambda() and not self.inside_brackets)
         ):
-            if self.is_comment:
-                raise ValueError("cannot append to standalone comments")
-
-            if self.leaves and leaf.type == STANDALONE_COMMENT:
+            if self.is_comment and not self.inside_brackets:
+                raise ValueError("cannot append to standalone comments outside of brackets")
+        
+            if self.leaves and leaf.type == STANDALONE_COMMENT and not self.inside_brackets:
                 raise ValueError(
-                    "cannot append standalone comments to a populated line"
+                    "cannot append standalone comments to a populated line outside of brackets"
                 )

         self.append(leaf, preformatted=preformatted)

Will merge this in after some more testing.

Resolves #1 , resolves #2 , resolves #16 .

jimwhite commented 2 months ago

This worked for me after I added requests to the ACR conda env:

diff --git a/environment.yml b/environment.yml
index 47ef8bab..8724d85d 100644
--- a/environment.yml
+++ b/environment.yml
@@ -43,6 +43,7 @@ dependencies:
       - pydantic==2.5.3
       - pydantic-core==2.14.6
       - python-dotenv==1.0.0
+      - requests==2.31.0
       - sniffio==1.3.0
       - soupsieve==2.5
       - tenacity==8.2.3
jimwhite commented 2 months ago

I also encountered a crash because a GitHub issue had an empty body. This is my fix:

diff --git a/app/fresh_issue/common.py b/app/fresh_issue/common.py
index f420b93b..1dc4a6a6 100644
--- a/app/fresh_issue/common.py
+++ b/app/fresh_issue/common.py
@@ -62,7 +62,7 @@ class FreshTask:
                 )
             else:
                 title, body, created_at = retrieved_issue
-                problem_stmt = title + "\n" + body
+                problem_stmt = f"{title}\n{body}"
                 # save this issue into a file for reference
                 problem_stmt_file = pjoin(self.task_output_dir, "problem_statement.txt")
                 with open(problem_stmt_file, "w") as f:
crhf commented 2 months ago
        pre_install_cmds: List[str] = [],
        ....
        testcases_passing: List[str] = [],
        testcases_failing: List[str] = [],

Mutable default arguments may cause problems, see here. Changing to this would be ok:

       pre_install_cmds: List[str] | None = None,
       ....
       testcases_passing: List[str] | None = None,
       testcases_failing: List[str] | None = None,

and in the body:

    pre_install_cmds = pre_install_cmds or []
    testcases_passing = testcases_passing or []
    testcases_failing = testcases_failing or []
yuntongzhang commented 2 months ago

Thank you all for your comments. I have integrated them.

yuntongzhang commented 2 months ago

Resolves #1, resolves #2, resolves #16.