From a1d1e2b9ca5b172b1ed7e460f9dda660a98b4bfb Mon Sep 17 00:00:00 2001 From: Anton Osika Date: Thu, 21 Mar 2024 19:37:32 +0100 Subject: [PATCH] Cleanup --- gpt_engineer/core/default/steps.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gpt_engineer/core/default/steps.py b/gpt_engineer/core/default/steps.py index 3a34e93630..eb0f9e2bb4 100644 --- a/gpt_engineer/core/default/steps.py +++ b/gpt_engineer/core/default/steps.py @@ -313,11 +313,11 @@ def improve_fn( def _improve_loop( ai: AI, files_dict: FilesDict, memory: BaseMemory, messages: List ) -> FilesDict: - for _ in range(MAX_EDIT_REFINEMENT_STEPS + 1): - messages = ai.next(messages, step_name=curr_fn()) - files_dict, errors = salvage_correct_hunks(messages, files_dict, memory) - if not errors: - break + messages = ai.next(messages, step_name=curr_fn()) + files_dict, errors = salvage_correct_hunks(messages, files_dict, memory) + + retries = 0 + while errors and retries < MAX_EDIT_REFINEMENT_STEPS: messages.append( HumanMessage( content="Some previously produced diffs were not on the requested format, or the code part was not found in the code. Details:\n" @@ -325,7 +325,11 @@ def _improve_loop( + "\n Only rewrite the problematic diffs, making sure that the failing ones are now on the correct format and can be found in the code. Make sure to not repeat past mistakes. \n" ) ) - return files_dict + messages = ai.next(messages, step_name=curr_fn()) + files_dict, errors = salvage_correct_hunks(messages, files_dict, memory) + retries += 1 + + return files_dict def salvage_correct_hunks(