Skip to content
Draft
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
2 changes: 1 addition & 1 deletion src/codegen/extensions/langchain/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@
class ViewFileTool(BaseTool):
"""Tool for viewing file contents and metadata."""

name: ClassVar[str] = "view_file"

Check failure on line 69 in src/codegen/extensions/langchain/tools.py

View workflow job for this annotation

GitHub Actions / mypy

error: Cannot override instance variable (previously declared on base class "BaseTool") with class variable [misc]
description: ClassVar[str] = """View the contents and metadata of a file in the codebase.

Check failure on line 70 in src/codegen/extensions/langchain/tools.py

View workflow job for this annotation

GitHub Actions / mypy

error: Cannot override instance variable (previously declared on base class "BaseTool") with class variable [misc]
For large files (>500 lines), content will be paginated. Use start_line and end_line to navigate through the file.
The response will indicate if there are more lines available to view."""
args_schema: ClassVar[type[BaseModel]] = ViewFileInput

Check failure on line 73 in src/codegen/extensions/langchain/tools.py

View workflow job for this annotation

GitHub Actions / mypy

error: Cannot override instance variable (previously declared on base class "BaseTool") with class variable [misc]
codebase: Codebase = Field(exclude=True)

def __init__(self, codebase: Codebase) -> None:
Expand Down Expand Up @@ -108,9 +108,9 @@
class ListDirectoryTool(BaseTool):
"""Tool for listing directory contents."""

name: ClassVar[str] = "list_directory"

Check failure on line 111 in src/codegen/extensions/langchain/tools.py

View workflow job for this annotation

GitHub Actions / mypy

error: Cannot override instance variable (previously declared on base class "BaseTool") with class variable [misc]
description: ClassVar[str] = "List contents of a directory in the codebase"

Check failure on line 112 in src/codegen/extensions/langchain/tools.py

View workflow job for this annotation

GitHub Actions / mypy

error: Cannot override instance variable (previously declared on base class "BaseTool") with class variable [misc]
args_schema: ClassVar[type[BaseModel]] = ListDirectoryInput

Check failure on line 113 in src/codegen/extensions/langchain/tools.py

View workflow job for this annotation

GitHub Actions / mypy

error: Cannot override instance variable (previously declared on base class "BaseTool") with class variable [misc]
codebase: Codebase = Field(exclude=True)

def __init__(self, codebase: Codebase) -> None:
Expand Down Expand Up @@ -138,8 +138,8 @@
class RipGrepTool(BaseTool):
"""Tool for searching the codebase via RipGrep."""

name: ClassVar[str] = "search"

Check failure on line 141 in src/codegen/extensions/langchain/tools.py

View workflow job for this annotation

GitHub Actions / mypy

error: Cannot override instance variable (previously declared on base class "BaseTool") with class variable [misc]
description: ClassVar[str] = "Search the codebase using `ripgrep` or regex pattern matching"

Check failure on line 142 in src/codegen/extensions/langchain/tools.py

View workflow job for this annotation

GitHub Actions / mypy

error: Cannot override instance variable (previously declared on base class "BaseTool") with class variable [misc]
args_schema: ClassVar[type[BaseModel]] = SearchInput
codebase: Codebase = Field(exclude=True)

Expand Down Expand Up @@ -546,7 +546,7 @@
"""Tool for getting PR data."""

name: ClassVar[str] = "view_pr"
description: ClassVar[str] = "View the diff and associated context for a pull request"
description: ClassVar[str] = "View the diff and associated context for a pull request on Github. Returns PR URL and repository name."
args_schema: ClassVar[type[BaseModel]] = GithubViewPRInput
codebase: Codebase = Field(exclude=True)

Expand Down
21 changes: 18 additions & 3 deletions src/codegen/extensions/tools/github/view_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
pr_id: int = Field(
description="ID of the PR",
)
repo_name: str = Field(
description="Name of the repository containing the PR",
)
pr_url: str = Field(
description="URL of the PR",
)
patch: str = Field(
description="The PR's patch/diff content",
)
Expand All @@ -25,7 +31,7 @@
description="Names of modified symbols in the PR",
)

str_template: ClassVar[str] = "PR #{pr_id}"
str_template: ClassVar[str] = "PR #{pr_id} in {repo_name}"


def view_pr(codebase: Codebase, pr_id: int) -> ViewPRObservation:
Expand All @@ -36,21 +42,30 @@
pr_id: Number of the PR to get the contents for
"""
try:
patch, file_commit_sha, moddified_symbols = codebase.get_modified_symbols_in_pr(pr_id)
patch, file_commit_sha, modified_symbols = codebase.get_modified_symbols_in_pr(pr_id)

Check failure on line 45 in src/codegen/extensions/tools/github/view_pr.py

View workflow job for this annotation

GitHub Actions / mypy

error: Too many values to unpack (3 expected, 4 provided) [misc]

# Get the PR object to extract URL and repository name
pr = codebase.op.remote_git_repo.get_pull(pr_id)

Check failure on line 48 in src/codegen/extensions/tools/github/view_pr.py

View workflow job for this annotation

GitHub Actions / mypy

error: "GitRepoClient" has no attribute "get_pull"; maybe "edit_pull" or "get_pull_safe"? [attr-defined]
repo_name = codebase.op.remote_git_repo.repo.full_name
pr_url = pr.html_url

return ViewPRObservation(
status="success",
pr_id=pr_id,
repo_name=repo_name,
pr_url=pr_url,
patch=patch,
file_commit_sha=file_commit_sha,
modified_symbols=moddified_symbols,
modified_symbols=modified_symbols,
)

except Exception as e:
return ViewPRObservation(
status="error",
error=f"Failed to view PR: {e!s}",
pr_id=pr_id,
repo_name="",
pr_url="",
patch="",
file_commit_sha={},
modified_symbols=[],
Expand Down