-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add aider context retrieval + tool tracking rework
- Loading branch information
Showing
18 changed files
with
879 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
code_editing/agents/collect_edit/context_collectors/aider.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import logging | ||
import os.path | ||
from operator import itemgetter | ||
|
||
from langchain_core.runnables import RunnableLambda | ||
|
||
from code_editing.agents.collect_edit.editors.util import TagParser | ||
from code_editing.agents.context_providers.aider import AiderRepoMap | ||
from code_editing.agents.graph_factory import GraphFactory | ||
from code_editing.agents.run import RunOverviewManager | ||
from code_editing.agents.tools.common import read_file_full | ||
from code_editing.agents.utils import PromptWrapper | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class AiderRetrieval(GraphFactory): | ||
name = "aider_retrieval" | ||
|
||
def __init__(self, select_prompt: PromptWrapper, **kwargs): | ||
super().__init__() | ||
self.select_prompt = select_prompt | ||
|
||
def build(self, run_overview_manager: RunOverviewManager, *args, **kwargs): | ||
# noinspection PyTypeChecker | ||
aider: AiderRepoMap = run_overview_manager.get_ctx_provider("aider") | ||
repo_map = aider.get_repo_map() | ||
|
||
def to_viewed_lines(state: dict): | ||
files = set(state["matches"]) | ||
viewed_lines = {} | ||
for file in files: | ||
full_path = os.path.join(aider.repo_path, file) | ||
if not os.path.exists(full_path): | ||
logger.warning(f"File {full_path} does not exist") | ||
continue | ||
line_cnt = len(read_file_full(full_path).split("\n")) | ||
viewed_lines[file] = list(range(1, line_cnt + 1)) | ||
return {"collected_context": viewed_lines} | ||
|
||
return ( | ||
{"repo_map": lambda _: repo_map, "instruction": itemgetter("instruction")} | ||
| self.select_prompt.as_runnable() | ||
| self._llm | ||
| TagParser(tag="file") | ||
| RunnableLambda(to_viewed_lines, name="Convert to viewed lines") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from code_editing.agents.context_providers.aider.aider import AiderRepoMap | ||
|
||
__all__ = ["AiderRepoMap"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from code_editing.agents.context_providers.aider.repo_map import RepoMap, find_src_files | ||
from code_editing.agents.context_providers.context_provider import ContextProvider | ||
|
||
|
||
class AiderRepoMap(ContextProvider): | ||
def __init__(self, repo_path: str, data_path: str): | ||
self.repo_path = repo_path | ||
self.data_path = data_path | ||
|
||
self.rm = RepoMap( | ||
map_tokens=1024, | ||
root=repo_path, | ||
token_count=lambda x: len(x.split()) // 4, | ||
) | ||
|
||
def get_repo_map(self) -> str: | ||
fnames = find_src_files(self.repo_path) | ||
repo_map = self.rm.get_repo_map([], fnames) | ||
return repo_map |
Oops, something went wrong.