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 visualization code #30

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions github_resolver/io_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import json
from github_resolver.resolver_output import ResolverOutput


def load_resolver_output(output_jsonl: str, issue_number: int) -> ResolverOutput:
with open(output_jsonl, "r") as f:
for line in f:
data = json.loads(line)
if data["issue"]["number"] == issue_number:
return ResolverOutput.model_validate(data)
raise ValueError(f"Issue number {issue_number} not found in {output_jsonl}")
12 changes: 1 addition & 11 deletions github_resolver/send_pull_request.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import argparse
import os
import json
import shutil
from github_resolver.github_issue import GithubIssue
from github_resolver.resolver_output import ResolverOutput
from github_resolver.io_utils import load_resolver_output
import requests
import subprocess
import whatthepatch


def load_resolver_output(output_jsonl: str, issue_number: int) -> ResolverOutput:
with open(output_jsonl, 'r') as f:
for line in f:
data = json.loads(line)
if data['issue']['number'] == issue_number:
return ResolverOutput.model_validate(data)
raise ValueError(f"Issue number {issue_number} not found in {output_jsonl}")


def apply_patch(repo_dir: str, patch: str) -> None:
diffs = whatthepatch.parse_patch(patch)

Expand Down
1 change: 0 additions & 1 deletion github_resolver/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from openhands.events.action import Action
from openhands.events.action.message import MessageAction


def codeact_user_response(
state: State,
encapsulate_solution: bool = False,
Expand Down
42 changes: 42 additions & 0 deletions github_resolver/visualize_resolver_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import argparse
import os
from github_resolver.io_utils import load_resolver_output


def visualize_resolver_output(issue_number: int, output_dir: str, vis_method: str):
output_jsonl = os.path.join(output_dir, "output.jsonl")
resolver_output = load_resolver_output(output_jsonl, issue_number)
if vis_method == "json":
print(resolver_output.model_dump_json(indent=4))
else:
raise ValueError(f"Invalid visualization method: {vis_method}")


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Visualize a patch.")
parser.add_argument(
"--issue-number",
type=int,
required=True,
help="Issue number to send the pull request for.",
)
parser.add_argument(
"--output-dir",
type=str,
default="output",
help="Output directory to write the results.",
)
parser.add_argument(
"--vis-method",
type=str,
default="json",
choices=["json"],
help="Method to visualize the patch [json].",
)
my_args = parser.parse_args()

visualize_resolver_output(
issue_number=my_args.issue_number,
output_dir=my_args.output_dir,
vis_method=my_args.vis_method,
)
62 changes: 61 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ whatthepatch = "*"
[tool.poetry.group.dev.dependencies]
mypy = "*"
ruff = "*"
black = "*"
types-requests = "*"
types-whatthepatch = "*"

Expand Down
Loading