Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a mode for running on new GitHub issues #25

Merged
merged 6 commits into from
Apr 17, 2024

Conversation

yuntongzhang
Copy link
Collaborator

@yuntongzhang yuntongzhang commented Apr 15, 2024

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. PaiEasChatEndpoint._call_eas should return bytes type instead of str type langchain-ai/langchain#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. PGVector deprecated create_filter_clause uses incorrect method. Can't filter by OR or AND conditions langchain-ai/langchain#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. Standalone comments still partially broken psf/black#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
Copy link

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
Copy link

jimwhite commented Apr 17, 2024

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
Copy link
Collaborator

crhf commented Apr 17, 2024

        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
Copy link
Collaborator Author

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

@yuntongzhang
Copy link
Collaborator Author

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

@yuntongzhang yuntongzhang merged commit 1e89e9c into nus-apr:main Apr 17, 2024
This was linked to issues Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to add issue from github Not working Make it easier to install
3 participants