Skip to content

fix: show line numbers in semantic_edit #549

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

Merged
merged 11 commits into from
Feb 19, 2025
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
16 changes: 5 additions & 11 deletions src/codegen/extensions/langchain/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@
from codegen import Codebase

from .tools import (
CommitTool,
CreateFileTool,
DeleteFileTool,
EditFileTool,
GithubCreatePRCommentTool,
GithubCreatePRReviewCommentTool,
GithubCreatePRTool,
GithubViewPRTool,
ListDirectoryTool,
MoveSymbolTool,
RenameFileTool,
Expand Down Expand Up @@ -69,11 +64,11 @@ def create_codebase_agent(
RevealSymbolTool(codebase),
SemanticEditTool(codebase),
SemanticSearchTool(codebase),
CommitTool(codebase),
GithubCreatePRTool(codebase),
GithubViewPRTool(codebase),
GithubCreatePRCommentTool(codebase),
GithubCreatePRReviewCommentTool(codebase),
# CommitTool(codebase),
# GithubCreatePRTool(codebase),
# GithubViewPRTool(codebase),
# GithubCreatePRCommentTool(codebase),
# GithubCreatePRReviewCommentTool(codebase),
]

prompt = ChatPromptTemplate.from_messages(
Expand Down Expand Up @@ -103,7 +98,6 @@ def create_codebase_agent(
- Preview changes before applying
- Ensure code quality with linting


4. Code Search:
- Text-based and semantic search
- Search within specific directories
Expand Down
21 changes: 17 additions & 4 deletions src/codegen/extensions/langchain/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
class ViewFileTool(BaseTool):
"""Tool for viewing file contents and metadata."""

name: ClassVar[str] = "view_file"

Check failure on line 52 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 53 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]] = ViewFileInput

Check failure on line 54 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 All @@ -72,9 +72,9 @@
class ListDirectoryTool(BaseTool):
"""Tool for listing directory contents."""

name: ClassVar[str] = "list_directory"

Check failure on line 75 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 76 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 77 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 All @@ -95,9 +95,9 @@
class SearchTool(BaseTool):
"""Tool for searching the codebase."""

name: ClassVar[str] = "search"

Check failure on line 98 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 text search"

Check failure on line 99 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

Check failure on line 100 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 @@ -234,10 +234,23 @@
return json.dumps(result, indent=2)


_SEMANTIC_EDIT_BRIEF = """Tool for semantic editing of files.
* Allows editing files by providing a draft of the new content
* For large files, specify line ranges to edit
* Will intelligently handle unchanged sections of code. Also supports appending to the end of a file."""
_SEMANTIC_EDIT_BRIEF = """Tool for file editing via an LLM delegate. Describe the changes you want to make and an expert will apply them to the file.

Specify the changes you want to make in the edit_content field, with helpful comments, like so:
```
# ... existing code ...

# edit: change function name and body
def function_redefinition():
return 'new_function_body'

# ... existing code ...
```

Another agent will be responsible for applying your edit and will only see the `edit_content` and the range you specify, so be clear what you are looking to change.

For large files, specify a range slightly larger than the edit you want to make, and be clear in your description what should and shouldn't change.
"""


class SemanticEditInput(BaseModel):
Expand Down
287 changes: 0 additions & 287 deletions src/codegen/extensions/tools/file_operations.py

This file was deleted.

6 changes: 3 additions & 3 deletions src/codegen/extensions/tools/semantic_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
Raises:
ValueError: If response is not properly formatted with code blocks
"""
# Find content between ``` markers
pattern = r"```(?:\w*\n)?(.*?)```"
matches = re.findall(pattern, llm_response, re.DOTALL)
# Find content between ``` markers, allowing for any language identifier
pattern = r"```[^`\n]*\n?(.*?)```"
matches = re.findall(pattern, llm_response.strip(), re.DOTALL)

Check warning on line 52 in src/codegen/extensions/tools/semantic_edit.py

View check run for this annotation

Codecov / codecov/patch

src/codegen/extensions/tools/semantic_edit.py#L51-L52

Added lines #L51 - L52 were not covered by tests

if not matches:
raise ValueError("LLM response must contain code wrapped in ``` blocks. Got response: " + llm_response[:200] + "...")
Expand Down Expand Up @@ -154,7 +154,7 @@

# Extract code from markdown code block
try:
modified_segment = _extract_code_block(response.content)

Check failure on line 157 in src/codegen/extensions/tools/semantic_edit.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument 1 to "_extract_code_block" has incompatible type "str | list[str | dict[Any, Any]]"; expected "str" [arg-type]
except ValueError as e:
msg = f"Failed to parse LLM response: {e!s}"
raise ValueError(msg)
Expand Down
Loading