Merge pull request #233 from russellocean/master

Implement custom continuous task count with 'y -n' command
This commit is contained in:
Toran Bruce Richards
2023-04-06 12:27:41 +01:00
committed by GitHub

View File

@@ -277,6 +277,7 @@ prompt = construct_prompt()
# Initialize variables # Initialize variables
full_message_history = [] full_message_history = []
result = None result = None
next_action_count = 0
# Make a constant: # Make a constant:
user_input = "Determine which next command to use, and respond using the format specified above:" user_input = "Determine which next command to use, and respond using the format specified above:"
@@ -298,7 +299,6 @@ while True:
memory, memory,
cfg.fast_token_limit) # TODO: This hardcodes the model to use GPT3.5. Make this an argument cfg.fast_token_limit) # TODO: This hardcodes the model to use GPT3.5. Make this an argument
# print("assistant reply: "+assistant_reply)
# Print Assistant thoughts # Print Assistant thoughts
print_assistant_thoughts(assistant_reply) print_assistant_thoughts(assistant_reply)
@@ -308,7 +308,7 @@ while True:
except Exception as e: except Exception as e:
print_to_console("Error: \n", Fore.RED, str(e)) print_to_console("Error: \n", Fore.RED, str(e))
if not cfg.continuous_mode: if not cfg.continuous_mode and next_action_count == 0:
### GET USER AUTHORIZATION TO EXECUTE COMMAND ### ### GET USER AUTHORIZATION TO EXECUTE COMMAND ###
# Get key press: Prompt the user to press enter to continue or escape # Get key press: Prompt the user to press enter to continue or escape
# to exit # to exit
@@ -318,13 +318,21 @@ while True:
Fore.CYAN, Fore.CYAN,
f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}") f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}")
print( print(
f"Enter 'y' to authorise command or 'n' to exit program, or enter feedback for {ai_name}...", f"Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for {ai_name}...",
flush=True) flush=True)
while True: while True:
console_input = input(Fore.MAGENTA + "Input:" + Style.RESET_ALL) console_input = input(Fore.MAGENTA + "Input:" + Style.RESET_ALL)
if console_input.lower() == "y": if console_input.lower() == "y":
user_input = "GENERATE NEXT COMMAND JSON" user_input = "GENERATE NEXT COMMAND JSON"
break break
elif console_input.lower().startswith("y -"):
try:
next_action_count = abs(int(console_input.split(" ")[1]))
user_input = "GENERATE NEXT COMMAND JSON"
except ValueError:
print("Invalid input format. Please enter 'y -n' where n is the number of continuous tasks.")
continue
break
elif console_input.lower() == "n": elif console_input.lower() == "n":
user_input = "EXIT" user_input = "EXIT"
break break
@@ -355,6 +363,8 @@ while True:
result = f"Human feedback: {user_input}" result = f"Human feedback: {user_input}"
else: else:
result = f"Command {command_name} returned: {cmd.execute_command(command_name, arguments)}" result = f"Command {command_name} returned: {cmd.execute_command(command_name, arguments)}"
if next_action_count > 0:
next_action_count -= 1
memory_to_add = f"Assistant Reply: {assistant_reply} " \ memory_to_add = f"Assistant Reply: {assistant_reply} " \
f"\nResult: {result} " \ f"\nResult: {result} " \