Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command_name converted to lowercase #2326

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 24 additions & 32 deletions autogpt/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ def start_interaction_loop(self):
while True:
# Discontinue if continuous limit is reached
loop_count += 1
if (
cfg.continuous_mode
and cfg.continuous_limit > 0
and loop_count > cfg.continuous_limit
):
if cfg.continuous_mode and loop_count > cfg.continuous_limit > 0:
logger.typewriter_log(
"Continuous Limit Reached: ", Fore.YELLOW, f"{cfg.continuous_limit}"
)
Expand All @@ -78,7 +74,7 @@ def start_interaction_loop(self):
self.full_message_history,
self.memory,
cfg.fast_token_limit,
) # TODO: This hardcodes the model to use GPT3.5. Make this an argument
)

assistant_reply_json = fix_json_using_multiple_techniques(assistant_reply)

Expand All @@ -89,22 +85,25 @@ def start_interaction_loop(self):
try:
print_assistant_thoughts(self.ai_name, assistant_reply_json)
command_name, arguments = get_command(assistant_reply_json)
# command_name, arguments = assistant_reply_json_valid["command"]["name"], assistant_reply_json_valid["command"]["args"]
# command_name converted to lowercase
command_name = command_name.lower().strip()
if cfg.speak_mode:
say_text(f"I want to execute {command_name}")

except Exception as e:
logger.error("Error: \n", str(e))

# Print command
logger.typewriter_log(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these changes? Should probably be a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command name contains two types:
one is to be executed by the AI,
and the other is to compare the input by the user with the preset one and convert it to lowercase to increase the robustness of the code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these changes? Should probably be a separate PR

change to only command_name converted to lowercase.

"NEXT ACTION: ",
Fore.CYAN,
f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} "
f"ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}",
)

if not cfg.continuous_mode and self.next_action_count == 0:
### GET USER AUTHORIZATION TO EXECUTE COMMAND ###
# Get key press: Prompt the user to press enter to continue or escape
# to exit
logger.typewriter_log(
"NEXT ACTION: ",
Fore.CYAN,
f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} "
f"ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}",
)
# ### GET USER AUTHORIZATION TO EXECUTE COMMAND ###
# Get key press: Prompt the user to press enter to continue or escape to exit
print(
"Enter 'y' to authorise command, 'y -N' to run N continuous "
"commands, 'n' to exit program, or enter feedback for "
Expand All @@ -115,16 +114,18 @@ def start_interaction_loop(self):
console_input = clean_input(
Fore.MAGENTA + "Input:" + Style.RESET_ALL
)
if console_input.lower().strip() == "y":
# user input command converted to lowercase
console_command = console_input.lower().strip()
if console_command == "y":
user_input = "GENERATE NEXT COMMAND JSON"
break
elif console_input.lower().strip() == "":
elif console_command == "":
print("Invalid input format.")
continue
elif console_input.lower().startswith("y -"):
elif console_command.startswith("y -"):
try:
self.next_action_count = abs(
int(console_input.split(" ")[1])
int(console_command.split(" ")[1])
)
user_input = "GENERATE NEXT COMMAND JSON"
except ValueError:
Expand All @@ -134,7 +135,7 @@ def start_interaction_loop(self):
)
continue
break
elif console_input.lower() == "n":
elif console_command == "n":
user_input = "EXIT"
break
else:
Expand All @@ -151,17 +152,9 @@ def start_interaction_loop(self):
elif user_input == "EXIT":
print("Exiting...", flush=True)
break
else:
# Print command
logger.typewriter_log(
"NEXT ACTION: ",
Fore.CYAN,
f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL}"
f" ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}",
)

# Execute command
if command_name is not None and command_name.lower().startswith("error"):
if command_name.startswith("error"):
result = (
f"Command {command_name} threw the following error: {arguments}"
)
Expand All @@ -183,8 +176,7 @@ def start_interaction_loop(self):

self.memory.add(memory_to_add)

# Check if there's a result from the command append it to the message
# history
# Check if there's a result from the command append it to the message history
if result is not None:
self.full_message_history.append(create_chat_message("system", result))
logger.typewriter_log("SYSTEM: ", Fore.YELLOW, result)
Expand Down