Skip to content

Commit 79917e2

Browse files
committed
Use file type info and modification time when sending file context
In the 'prompts.py' file, the method of generating file context has been refactored to include more detailed information about each file, such as whether it's binary and when it was last modified. The 'arrow' library has been added to facilitate this change. This library has also been added to the 'requirements.in' and 'requirements.txt' files.
1 parent 057ed4f commit 79917e2

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

aicodebot/prompts.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pathlib import Path
77
from pydantic import BaseModel, Field
88
from types import SimpleNamespace
9-
import functools, os
9+
import arrow, functools, os
1010

1111
# ---------------------------------------------------------------------------- #
1212
# Personality helpers #
@@ -228,10 +228,15 @@ def generate_files_context(files):
228228

229229
files_context += "Here are the relevant files we are working with in this session:\n"
230230
for file_name in files:
231-
contents = Path(file_name).read_text()
232-
files_context += f"--- START OF FILE: {file_name} ---\n"
233-
files_context += contents
234-
files_context += f"\n--- END OF FILE: {file_name} ---\n\n"
231+
is_binary, file_info = Coder.get_file_info(file_name)
232+
modification_ago = arrow.get(Path(file_name).stat().st_mtime).humanize()
233+
if is_binary:
234+
files_context += f"Binary file: {file_name}, modified {modification_ago}\n"
235+
else:
236+
files_context += f"--- START OF FILE: {file_name} {file_info} file, modified {modification_ago} ---\n"
237+
contents = Path(file_name).read_text()
238+
files_context += contents
239+
files_context += f"\n--- END OF FILE: {file_name} ---\n\n"
235240

236241
return files_context
237242

requirements/requirements.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
# Keep this list sorted alphabetically.
77

8+
arrow
89
beautifulsoup4 # needed by langchain
9-
click # command line interface helpers
10-
faiss-cpu
10+
click
11+
faiss-cpu # for learn
1112
GitPython
1213
humanize
1314
langchain

requirements/requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ aiohttp==3.8.4
1010
# openai
1111
aiosignal==1.3.1
1212
# via aiohttp
13+
arrow==1.2.3
14+
# via -r requirements.in
1315
async-timeout==4.0.2
1416
# via aiohttp
1517
attrs==23.1.0
@@ -85,6 +87,8 @@ pydantic==1.10.9
8587
# openapi-schema-pydantic
8688
pygments==2.15.1
8789
# via rich
90+
python-dateutil==2.8.2
91+
# via arrow
8892
pyyaml==6.0.1
8993
# via
9094
# -r requirements.in
@@ -99,6 +103,8 @@ requests==2.31.0
99103
# tiktoken
100104
rich==13.4.2
101105
# via -r requirements.in
106+
six==1.16.0
107+
# via python-dateutil
102108
smmap==5.0.0
103109
# via gitdb
104110
soupsieve==2.4.1

0 commit comments

Comments
 (0)