diff options
author | Thunder Drag <74146396+ThunderDrag@users.noreply.github.com> | 2024-02-20 15:36:30 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-20 11:06:30 +0100 |
commit | 49a6d68200253116a081edd825b9e5f0bfa25850 (patch) | |
tree | 4f2f7ed07e5c49890b62b95ae6fa512da8859295 | |
parent | feat(frontend): Allow sending a message with the enter key (#6378) (diff) | |
download | Auto-GPT-49a6d68200253116a081edd825b9e5f0bfa25850.tar.gz Auto-GPT-49a6d68200253116a081edd825b9e5f0bfa25850.tar.bz2 Auto-GPT-49a6d68200253116a081edd825b9e5f0bfa25850.zip |
fix(agent/setup): Fix revising constraints and best practices (#6777)
In a `for item in list` loop, removing items from the list while iterating causes it to skip over the next item. Fix: refactor `interactively_revise_ai_settings` routine to use while loop for iterating over constraints, resources, and best practices.
---------
Co-authored-by: Kripanshu Jindal <polaris@Polaris.local>
Co-authored-by: Reinier van der Leer <pwuts@agpt.co>
-rw-r--r-- | autogpts/autogpt/autogpt/app/setup.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/autogpts/autogpt/autogpt/app/setup.py b/autogpts/autogpt/autogpt/app/setup.py index 8a271d26f..df4e9436c 100644 --- a/autogpts/autogpt/autogpt/app/setup.py +++ b/autogpts/autogpt/autogpt/app/setup.py @@ -89,7 +89,9 @@ async def interactively_revise_ai_settings( ) # Revise constraints - for i, constraint in enumerate(directives.constraints): + i = 0 + while i < len(directives.constraints): + constraint = directives.constraints[i] print_attribute(f"Constraint {i+1}:", f'"{constraint}"') new_constraint = ( await clean_input( @@ -99,11 +101,15 @@ async def interactively_revise_ai_settings( ) or constraint ) + if new_constraint == "-": directives.constraints.remove(constraint) + continue elif new_constraint: directives.constraints[i] = new_constraint + i += 1 + # Add new constraints while True: new_constraint = await clean_input( @@ -115,7 +121,9 @@ async def interactively_revise_ai_settings( directives.constraints.append(new_constraint) # Revise resources - for i, resource in enumerate(directives.resources): + i = 0 + while i < len(directives.resources): + resource = directives.resources[i] print_attribute(f"Resource {i+1}:", f'"{resource}"') new_resource = ( await clean_input( @@ -127,9 +135,12 @@ async def interactively_revise_ai_settings( ) if new_resource == "-": directives.resources.remove(resource) + continue elif new_resource: directives.resources[i] = new_resource + i += 1 + # Add new resources while True: new_resource = await clean_input( @@ -141,7 +152,9 @@ async def interactively_revise_ai_settings( directives.resources.append(new_resource) # Revise best practices - for i, best_practice in enumerate(directives.best_practices): + i = 0 + while i < len(directives.best_practices): + best_practice = directives.best_practices[i] print_attribute(f"Best Practice {i+1}:", f'"{best_practice}"') new_best_practice = ( await clean_input( @@ -153,9 +166,12 @@ async def interactively_revise_ai_settings( ) if new_best_practice == "-": directives.best_practices.remove(best_practice) + continue elif new_best_practice: directives.best_practices[i] = new_best_practice + i += 1 + # Add new best practices while True: new_best_practice = await clean_input( |