Skip to content

Commit

Permalink
fix(agent/setup): Fix revising constraints and best practices (Signif…
Browse files Browse the repository at this point in the history
…icant-Gravitas#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 <[email protected]>
Co-authored-by: Reinier van der Leer <[email protected]>
  • Loading branch information
3 people authored Feb 20, 2024
1 parent 6cfe229 commit 49a6d68
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions autogpts/autogpt/autogpt/app/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 49a6d68

Please sign in to comment.