Merge branch 'main' into triple-backticks

This commit is contained in:
Paul Gauthier 2023-06-25 19:45:03 -07:00
commit f00a1e827a
2 changed files with 33 additions and 4 deletions

View file

@ -66,10 +66,11 @@ class WholeFileCoder(Coder):
# fname==None ... starting a new block
if i > 0:
fname = lines[i - 1].strip()
path_to = "path/to/"
# gpt-3.5 will sometimes crib /path/to from the one-shot example
if fname.startswith(path_to) and fname not in chat_files:
fname = fname[len(path_to) :]
# Did gpt prepend a bogus dir? It especially likes to
# include the path/to prefix from the one-shot example in
# the prompt.
if fname and fname not in chat_files and Path(fname).name in chat_files:
fname = Path(fname).name
if not fname: # blank line? or ``` was on first line i==0
if saw_fname:
fname = saw_fname

View file

@ -42,6 +42,34 @@ class TestWholeFileCoder(unittest.TestCase):
updated_content = f.read()
self.assertEqual(updated_content, "Updated content\n")
def test_update_files_bogus_path_prefix(self):
with tempfile.TemporaryDirectory() as temp_dir:
os.chdir(temp_dir)
# Create a sample file in the temporary directory
sample_file = "sample.txt"
with open(sample_file, "w") as f:
f.write("Original content\n")
# Initialize WholeFileCoder with the temporary directory
io = InputOutput(yes=True)
coder = WholeFileCoder(main_model=models.GPT35, io=io, fnames=[sample_file])
# Set the partial response content with the updated content
# With path/to/ prepended onto the filename
coder.partial_response_content = f"path/to/{sample_file}\n```\nUpdated content\n```"
# Call update_files method
edited_files = coder.update_files()
# Check if the sample file was updated
self.assertIn("sample.txt", edited_files)
# Check if the content of the sample file was updated
with open(sample_file, "r") as f:
updated_content = f.read()
self.assertEqual(updated_content, "Updated content\n")
def test_update_files_not_in_chat(self):
with tempfile.TemporaryDirectory() as temp_dir:
os.chdir(temp_dir)