From 96209d67e164f7dbf8db621f781057e5ccd7d489 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 8 Apr 2023 12:28:50 -0700 Subject: [PATCH] better --- coder.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/coder.py b/coder.py index 5d4fd7a54..ee1f3db18 100755 --- a/coder.py +++ b/coder.py @@ -306,7 +306,7 @@ The ``` delimiters are very important! return True def do_gpt_powered_replace(self, fname, edit): - print(f'Could not find CURRENT block in {fname}, asking GPT to make the edit...') + print(f'Could not find ORIGINAL block in {fname}, asking GPT to make the edit...') fname = Path(fname) content = fname.read_text() prompt = f''' @@ -335,7 +335,15 @@ Just the content of the file! dict(role = 'user', content = prompt), ] res = self.send(messages) + res = res.splitlines() + if res[0].strip == str(fname): + res = res[1:] + if res[0].strip() == '```' and res[-1].strip() == '```': + res = res[1:-1] + res = '\n'.join(res) + if res[-1] != '\n': + res += '\n' fname.write_text(res)