Skip to content

Commit 17a3daf

Browse files
committed
Enhanced file context generation in prompts
This commit ain't just about adding or removing a few lines of code. It's about giving a damn about the context. We've added a function to generate a directory structure, and we're using it to provide a more comprehensive context for the sidekick prompt. Now, not only do you get the relevant files, but you also get a nice little map of the directory structure. Ain't that something? And let's not forget about the files. We've improved the way we handle them too. If there ain't no files, we don't just leave you hanging. We give you the directory structure and call it a day. But if there are files, oh boy, we give you the whole shebang. We read 'em, we count 'em, and we warn you if they're too damn big. So, in summary, we've made the file context generation in prompts more informative and more useful. And if you don't appreciate that, well, I don't know what to tell you.
1 parent 0064c80 commit 17a3daf

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

aicodebot/prompts.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from aicodebot.helpers import get_token_length, logger, read_config
1+
from aicodebot.helpers import generate_directory_structure, get_token_length, logger, read_config
22
from langchain import PromptTemplate
33
from pathlib import Path
44
from types import SimpleNamespace
@@ -92,8 +92,18 @@ def get_personality_prompt():
9292

9393

9494
def generate_files_context(files):
95-
"""Generate the files context for the sidekick prompt."""
96-
files_context = "Here are the relevant files we are working with in this session:\n"
95+
"""Generate the files context for the sidekick prompt.
96+
97+
This includes a directory structure and the contents of $files
98+
99+
"""
100+
files_context = "\nHere is the directory structure we are working with in this session:\n"
101+
files_context += generate_directory_structure(".", ignore_patterns=[".git"], use_gitignore=True)
102+
103+
if not files:
104+
return files_context
105+
106+
files_context += "Here are the relevant files we are working with in this session:\n"
97107
for file_name in files:
98108
contents = Path(file_name).read_text()
99109
token_length = get_token_length(contents)

0 commit comments

Comments
 (0)