Skip to content

Commit

Permalink
Rename to openhands_resolver (#98)
Browse files Browse the repository at this point in the history
* Rename to openhands_resolver

* Update prompt
  • Loading branch information
neubig authored Sep 28, 2024
1 parent 3830acf commit 6bea373
Show file tree
Hide file tree
Showing 24 changed files with 51 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install git+https://github.com/all-hands-ai/github-resolver.git
pip install git+https://github.com/all-hands-ai/openhands-resolver.git
- name: Attempt to resolve issue
env:
Expand All @@ -46,7 +46,7 @@ jobs:
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
LLM_BASE_URL: ${{ secrets.LLM_BASE_URL }}
run: |
python -m github_resolver.resolve_issues \
python -m openhands_resolver.resolve_issues \
--repo ${{ github.repository }} \
--issue-numbers ${{ github.event.issue.number }}
Expand All @@ -68,12 +68,12 @@ jobs:
LLM_BASE_URL: ${{ secrets.LLM_BASE_URL }}
run: |
if [ "${{ steps.check_result.outputs.RESOLUTION_SUCCESS }}" == "true" ]; then
python -m github_resolver.send_pull_request \
python -m openhands_resolver.send_pull_request \
--issue-number ${{ github.event.issue.number }} \
--pr-type draft | tee pr_result.txt && \
grep "draft created" pr_result.txt | sed 's/.*\///g' > pr_number.txt
else
python -m github_resolver.send_pull_request \
python -m openhands_resolver.send_pull_request \
--issue-number ${{ github.event.issue.number }} \
--pr-type branch | tee branch_result.txt && \
grep "Branch" branch_result.txt | awk '{print $2}' > branch_name.txt
Expand Down Expand Up @@ -102,6 +102,6 @@ jobs:
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: `An attempt was made to automatically fix this issue, but it was unsuccessful. A branch named '${branchName}' has been created with the attempted changes. Manual intervention may be required.`
body: `An attempt was made to automatically fix this issue, but it was unsuccessful. A branch named '${branchName}' has been created with the attempted changes. You can view the branch [here](https://github.com/${context.repo.owner}/${context.repo.repo}/tree/${branchName}). Manual intervention may be required.`
});
}
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ First, make sure that you have `poetry`
then install the github resolver package:

```bash
git clone github.com/All-Hands-AI/github-resolver
cd github-resolver
git clone github.com/All-Hands-AI/openhands-resolver
cd openhands-resolver
poetry install
```

Expand Down Expand Up @@ -49,7 +49,7 @@ Run the following command to resolve issues in the `[OWNER]/[REPO]` repository.
For instance, if you want to resolve issues in this repo, you would run:

```bash
poetry run python github_resolver/resolve_issues.py --repo all-hands-ai/github-resolver
poetry run python openhands_resolver/resolve_issues.py --repo all-hands-ai/openhands-resolver
```

The output will be written to the `output/` directory.
Expand All @@ -58,7 +58,7 @@ Alternatively, if you only want to resolve a subset of the issues, you can speci
list of issues to resolve. For instance, if you want to resolve issues 100 and 101, you can run

```bash
poetry run python github_resolver/resolve_issues.py --repo all-hands-ai/github-resolver --issue-numbers 100,101
poetry run python openhands_resolver/resolve_issues.py --repo all-hands-ai/openhands-resolver --issue-numbers 100,101
```

## Visualizing successful PRs
Expand All @@ -72,7 +72,7 @@ grep '"success":true' output/output.jsonl | sed 's/.*\("number":[0-9]*\).*/\1/g'
Then you can go through and visualize the ones you'd like.

```bash
poetry run python github_resolver/visualize_resolver_output.py --issue-number ISSUE_NUMBER --vis-method json
poetry run python openhands_resolver/visualize_resolver_output.py --issue-number ISSUE_NUMBER --vis-method json
```

## Uploading PRs
Expand All @@ -85,13 +85,13 @@ There are three ways you can upload
3. `ready` - create a non-draft PR that's ready for review

```bash
poetry run python github_resolver/send_pull_request.py --issue-number ISSUE_NUMBER --github-username YOUR_GITHUB_USERNAME --pr-type draft
poetry run python openhands_resolver/send_pull_request.py --issue-number ISSUE_NUMBER --github-username YOUR_GITHUB_USERNAME --pr-type draft
```

If you want to upload to a fork, you can do so by specifying the `fork-owner`.

```bash
poetry run python github_resolver/send_pull_request.py --issue-number ISSUE_NUMBER --github-username YOUR_GITHUB_USERNAME --pr-type draft --fork-owner YOUR_GITHUB_USERNAME
poetry run python openhands_resolver/send_pull_request.py --issue-number ISSUE_NUMBER --github-username YOUR_GITHUB_USERNAME --pr-type draft --fork-owner YOUR_GITHUB_USERNAME
```

## Troubleshooting
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from typing import Iterable
from github_resolver.resolver_output import ResolverOutput
from openhands_resolver.resolver_output import ResolverOutput


def load_all_resolver_outputs(output_jsonl: str) -> Iterable[ResolverOutput]:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

from litellm import completion

from github_resolver.github_issue import GithubIssue
from github_resolver.resolver_output import ResolverOutput
from openhands_resolver.github_issue import GithubIssue
from openhands_resolver.resolver_output import ResolverOutput
import openhands
from openhands.core.main import create_runtime, run_controller
from openhands.controller.state.state import State
Expand All @@ -37,7 +37,7 @@
)
from openhands.core.config import LLMConfig
from openhands.runtime.runtime import Runtime
from github_resolver.utils import (
from openhands_resolver.utils import (
codeact_user_response,
reset_logger_for_multiprocessing,
)
Expand Down Expand Up @@ -651,7 +651,7 @@ async def run_with_semaphore(task):
parser.add_argument(
"--prompt-file",
type=str,
default="github_resolver/prompts/resolve/basic-with-tests.jinja",
default="openhands_resolver/prompts/resolve/basic-with-tests.jinja",
help="Path to the prompt template file in Jinja format.",
)
parser.add_argument(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any
from litellm import BaseModel
from github_resolver.github_issue import GithubIssue
from openhands_resolver.github_issue import GithubIssue


class ResolverOutput(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import argparse
import os
import shutil
from github_resolver.github_issue import GithubIssue
from github_resolver.io_utils import (
from openhands_resolver.github_issue import GithubIssue
from openhands_resolver.io_utils import (
load_all_resolver_outputs,
load_single_resolver_output,
)
from github_resolver.patching import parse_patch, apply_diff
from openhands_resolver.patching import parse_patch, apply_diff
import requests
import subprocess

from github_resolver.resolver_output import ResolverOutput
from openhands_resolver.resolver_output import ResolverOutput


def apply_patch(repo_dir: str, patch: str) -> None:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
import os
from github_resolver.io_utils import load_single_resolver_output
from openhands_resolver.io_utils import load_single_resolver_output


def visualize_resolver_output(issue_number: int, output_dir: str, vis_method: str):
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "github-resolver"
name = "openhands-resolver"
version = "0.1.0"
description = "OpenHands Issue Resolver"
authors = ["All Hands AI"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/All-Hands-AI/github-resolver"
repository = "https://github.com/All-Hands-AI/openhands-resolver"
include = ["poetry.lock"]
packages = [
{ include = "github_resolver" },
{ include = "openhands_resolver" },
]

[tool.poetry.dependencies]
Expand Down
34 changes: 17 additions & 17 deletions tests/test_resolve_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@


from unittest.mock import AsyncMock, patch, MagicMock, mock_open
from github_resolver.resolve_issues import (
from openhands_resolver.resolve_issues import (
create_git_patch,
initialize_runtime,
complete_runtime,
get_instruction,
process_issue,
download_issues_from_github,
)
from github_resolver.github_issue import GithubIssue
from openhands_resolver.github_issue import GithubIssue
from openhands.events.action import CmdRunAction
from openhands.events.observation import CmdOutputObservation, NullObservation
from github_resolver.resolver_output import ResolverOutput
from openhands_resolver.resolver_output import ResolverOutput
from openhands.core.config import LLMConfig


Expand Down Expand Up @@ -198,17 +198,17 @@ async def test_process_issue(mock_output_dir, mock_prompt_template):

# Patch the necessary functions
with patch(
"github_resolver.resolve_issues.create_runtime", mock_create_runtime
"openhands_resolver.resolve_issues.create_runtime", mock_create_runtime
), patch(
"github_resolver.resolve_issues.initialize_runtime", mock_initialize_runtime
"openhands_resolver.resolve_issues.initialize_runtime", mock_initialize_runtime
), patch(
"github_resolver.resolve_issues.run_controller", mock_run_controller
"openhands_resolver.resolve_issues.run_controller", mock_run_controller
), patch(
"github_resolver.resolve_issues.complete_runtime", mock_complete_runtime
"openhands_resolver.resolve_issues.complete_runtime", mock_complete_runtime
), patch(
"github_resolver.resolve_issues.guess_success", mock_guess_success
"openhands_resolver.resolve_issues.guess_success", mock_guess_success
), patch(
"github_resolver.resolve_issues.logger"
"openhands_resolver.resolve_issues.logger"
):

# Call the function
Expand Down Expand Up @@ -262,8 +262,8 @@ def test_file_instruction():
title="Test Issue",
body="This is a test issue",
)
# load prompt from github_resolver/prompts/resolve/basic.jinja
with open("github_resolver/prompts/resolve/basic.jinja", "r") as f:
# load prompt from openhands_resolver/prompts/resolve/basic.jinja
with open("openhands_resolver/prompts/resolve/basic.jinja", "r") as f:
prompt = f.read()
instruction = get_instruction(issue, prompt, None)
expected_instruction = """Please fix the following issue for the repository in /workspace.
Expand All @@ -287,11 +287,11 @@ def test_file_instruction_with_repo_instruction():
title="Test Issue",
body="This is a test issue",
)
# load prompt from github_resolver/prompts/resolve/basic.jinja
with open("github_resolver/prompts/resolve/basic.jinja", "r") as f:
# load prompt from openhands_resolver/prompts/resolve/basic.jinja
with open("openhands_resolver/prompts/resolve/basic.jinja", "r") as f:
prompt = f.read()
# load repo instruction from github_resolver/prompts/repo_instructions/all-hands-ai___github-resolver.txt
with open("github_resolver/prompts/repo_instructions/all-hands-ai___github-resolver.txt", "r") as f:
# load repo instruction from openhands_resolver/prompts/repo_instructions/all-hands-ai___openhands-resolver.txt
with open("openhands_resolver/prompts/repo_instructions/all-hands-ai___openhands-resolver.txt", "r") as f:
repo_instruction = f.read()
instruction = get_instruction(issue, prompt, repo_instruction)
expected_instruction = """Please fix the following issue for the repository in /workspace.
Expand Down Expand Up @@ -329,10 +329,10 @@ def test_repo_instruction_file(mock_workspace_dir):
f.write(instructions_content)

# Mock the necessary parts of the resolve_issues function
with patch('github_resolver.resolve_issues.os.path.join', side_effect=os.path.join), patch('github_resolver.resolve_issues.os.path.exists', return_value=True), patch('builtins.open', new_callable=mock_open, read_data=instructions_content):
with patch('openhands_resolver.resolve_issues.os.path.join', side_effect=os.path.join), patch('openhands_resolver.resolve_issues.os.path.exists', return_value=True), patch('builtins.open', new_callable=mock_open, read_data=instructions_content):

# Import the function we want to test
from github_resolver.resolve_issues import resolve_issues
from openhands_resolver.resolve_issues import resolve_issues

# Create a mock ArgumentParser object
mock_args = MagicMock()
Expand Down
16 changes: 8 additions & 8 deletions tests/test_send_pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import pytest
from unittest.mock import patch, MagicMock, call

from github_resolver.send_pull_request import (
from openhands_resolver.send_pull_request import (
apply_patch,
load_single_resolver_output,
initialize_repo,
process_single_issue,
send_pull_request,
process_all_successful_issues,
)
from github_resolver.resolver_output import ResolverOutput, GithubIssue
from openhands_resolver.resolver_output import ResolverOutput, GithubIssue


@pytest.fixture
Expand Down Expand Up @@ -354,10 +354,10 @@ def test_send_pull_request_permission_error(
mock_post.assert_called_once()


@patch("github_resolver.send_pull_request.initialize_repo")
@patch("github_resolver.send_pull_request.apply_patch")
@patch("github_resolver.send_pull_request.send_pull_request")
@patch("github_resolver.send_pull_request.make_commit")
@patch("openhands_resolver.send_pull_request.initialize_repo")
@patch("openhands_resolver.send_pull_request.apply_patch")
@patch("openhands_resolver.send_pull_request.send_pull_request")
@patch("openhands_resolver.send_pull_request.make_commit")
def test_process_single_issue(
mock_make_commit,
mock_send_pull_request,
Expand Down Expand Up @@ -420,8 +420,8 @@ def test_process_single_issue(
)


@patch("github_resolver.send_pull_request.load_all_resolver_outputs")
@patch("github_resolver.send_pull_request.process_single_issue")
@patch("openhands_resolver.send_pull_request.load_all_resolver_outputs")
@patch("openhands_resolver.send_pull_request.process_single_issue")
def test_process_all_successful_issues(
mock_process_single_issue, mock_load_all_resolver_outputs
):
Expand Down

0 comments on commit 6bea373

Please sign in to comment.