Skip to content

Commit 553c07f

Browse files
jayhacktawsifkamal
andauthored
fix: show line numbers in semantic_edit (#549)
The agent was hallucinating line numbers previously, which meant edits would get messed up. This seems to fix it for the most part. --------- Co-authored-by: tawsifkamal <[email protected]>
1 parent 037180c commit 553c07f

File tree

7 files changed

+79
-318
lines changed

7 files changed

+79
-318
lines changed

src/codegen/extensions/langchain/agent.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@
1313
from codegen import Codebase
1414

1515
from .tools import (
16-
CommitTool,
1716
CreateFileTool,
1817
DeleteFileTool,
1918
EditFileTool,
20-
GithubCreatePRCommentTool,
21-
GithubCreatePRReviewCommentTool,
22-
GithubCreatePRTool,
23-
GithubViewPRTool,
2419
ListDirectoryTool,
2520
MoveSymbolTool,
2621
RenameFileTool,
@@ -69,11 +64,11 @@ def create_codebase_agent(
6964
RevealSymbolTool(codebase),
7065
SemanticEditTool(codebase),
7166
SemanticSearchTool(codebase),
72-
CommitTool(codebase),
73-
GithubCreatePRTool(codebase),
74-
GithubViewPRTool(codebase),
75-
GithubCreatePRCommentTool(codebase),
76-
GithubCreatePRReviewCommentTool(codebase),
67+
# CommitTool(codebase),
68+
# GithubCreatePRTool(codebase),
69+
# GithubViewPRTool(codebase),
70+
# GithubCreatePRCommentTool(codebase),
71+
# GithubCreatePRReviewCommentTool(codebase),
7772
]
7873

7974
prompt = ChatPromptTemplate.from_messages(
@@ -103,7 +98,6 @@ def create_codebase_agent(
10398
- Preview changes before applying
10499
- Ensure code quality with linting
105100
106-
107101
4. Code Search:
108102
- Text-based and semantic search
109103
- Search within specific directories

src/codegen/extensions/langchain/tools.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,23 @@ def _run(
234234
return json.dumps(result, indent=2)
235235

236236

237-
_SEMANTIC_EDIT_BRIEF = """Tool for semantic editing of files.
238-
* Allows editing files by providing a draft of the new content
239-
* For large files, specify line ranges to edit
240-
* Will intelligently handle unchanged sections of code. Also supports appending to the end of a file."""
237+
_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.
238+
239+
Specify the changes you want to make in the edit_content field, with helpful comments, like so:
240+
```
241+
# ... existing code ...
242+
243+
# edit: change function name and body
244+
def function_redefinition():
245+
return 'new_function_body'
246+
247+
# ... existing code ...
248+
```
249+
250+
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.
251+
252+
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.
253+
"""
241254

242255

243256
class SemanticEditInput(BaseModel):

src/codegen/extensions/tools/file_operations.py

Lines changed: 0 additions & 287 deletions
This file was deleted.

src/codegen/extensions/tools/semantic_edit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def _extract_code_block(llm_response: str) -> str:
4747
Raises:
4848
ValueError: If response is not properly formatted with code blocks
4949
"""
50-
# Find content between ``` markers
51-
pattern = r"```(?:\w*\n)?(.*?)```"
52-
matches = re.findall(pattern, llm_response, re.DOTALL)
50+
# Find content between ``` markers, allowing for any language identifier
51+
pattern = r"```[^`\n]*\n?(.*?)```"
52+
matches = re.findall(pattern, llm_response.strip(), re.DOTALL)
5353

5454
if not matches:
5555
raise ValueError("LLM response must contain code wrapped in ``` blocks. Got response: " + llm_response[:200] + "...")

0 commit comments

Comments
 (0)