mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-17 14:04:27 +01:00
Attempt to improve JSON handling in GPT-3
This commit is contained in:
@@ -26,7 +26,7 @@ def chat_with_ai(
|
|||||||
full_message_history,
|
full_message_history,
|
||||||
permanent_memory,
|
permanent_memory,
|
||||||
token_limit,
|
token_limit,
|
||||||
debug=False):
|
debug=True):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
"""
|
"""
|
||||||
@@ -62,7 +62,7 @@ def chat_with_ai(
|
|||||||
print("----------- END OF CONTEXT ----------------")
|
print("----------- END OF CONTEXT ----------------")
|
||||||
|
|
||||||
response = openai.ChatCompletion.create(
|
response = openai.ChatCompletion.create(
|
||||||
model="gpt-4",
|
model="gpt-3.5-turbo",#model="gpt-4",
|
||||||
messages=current_context,
|
messages=current_context,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ class Argument(Enum):
|
|||||||
CONTINUOUS_MODE = "continuous-mode"
|
CONTINUOUS_MODE = "continuous-mode"
|
||||||
SPEAK_MODE = "speak-mode"
|
SPEAK_MODE = "speak-mode"
|
||||||
|
|
||||||
|
# normally 6000 for gpt-4
|
||||||
|
TOKEN_LIMIT=4000
|
||||||
|
|
||||||
|
|
||||||
def print_to_console(
|
def print_to_console(
|
||||||
title,
|
title,
|
||||||
@@ -30,6 +33,8 @@ def print_to_console(
|
|||||||
speak.say_text(f"{title}. {content}")
|
speak.say_text(f"{title}. {content}")
|
||||||
print(title_color + title + " " + Style.RESET_ALL, end="")
|
print(title_color + title + " " + Style.RESET_ALL, end="")
|
||||||
if content:
|
if content:
|
||||||
|
if isinstance(content, list):
|
||||||
|
content = " ".join(content)
|
||||||
words = content.split()
|
words = content.split()
|
||||||
for i, word in enumerate(words):
|
for i, word in enumerate(words):
|
||||||
print(word, end="", flush=True)
|
print(word, end="", flush=True)
|
||||||
@@ -138,7 +143,7 @@ def construct_prompt():
|
|||||||
print_to_console(
|
print_to_console(
|
||||||
"Enter up to 5 goals for your AI: ",
|
"Enter up to 5 goals for your AI: ",
|
||||||
Fore.GREEN,
|
Fore.GREEN,
|
||||||
"For example: \nIncrease net worth \nGrow Twitter Account \nDevelop and manage multiple businesses autonomously'")
|
"For example: \nIncrease net worth, Grow Twitter Account, Develop and manage multiple businesses autonomously'")
|
||||||
print("Enter nothing to load defaults, enter nothing when finished.", flush=True)
|
print("Enter nothing to load defaults, enter nothing when finished.", flush=True)
|
||||||
ai_goals = []
|
ai_goals = []
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
@@ -186,11 +191,12 @@ cfg = Config()
|
|||||||
parse_arguments()
|
parse_arguments()
|
||||||
ai_name = ""
|
ai_name = ""
|
||||||
prompt = construct_prompt()
|
prompt = construct_prompt()
|
||||||
|
print(prompt)
|
||||||
# Initialize variables
|
# Initialize variables
|
||||||
full_message_history = []
|
full_message_history = []
|
||||||
token_limit = 6000 # The maximum number of tokens allowed in the API call
|
token_limit = TOKEN_LIMIT # The maximum number of tokens allowed in the API call
|
||||||
result = None
|
result = None
|
||||||
user_input = "NEXT COMMAND"
|
user_input = "GENERATE NEXT COMMAND JSON"
|
||||||
|
|
||||||
# Interaction Loop
|
# Interaction Loop
|
||||||
while True:
|
while True:
|
||||||
@@ -203,6 +209,7 @@ while True:
|
|||||||
mem.permanent_memory,
|
mem.permanent_memory,
|
||||||
token_limit)
|
token_limit)
|
||||||
|
|
||||||
|
print("assistant reply: "+assistant_reply)
|
||||||
# Print Assistant thoughts
|
# Print Assistant thoughts
|
||||||
print_assistant_thoughts(assistant_reply)
|
print_assistant_thoughts(assistant_reply)
|
||||||
|
|
||||||
@@ -227,7 +234,7 @@ while 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 = "NEXT COMMAND"
|
user_input = "GENERATE NEXT COMMAND JSON"
|
||||||
break
|
break
|
||||||
elif console_input.lower() == "n":
|
elif console_input.lower() == "n":
|
||||||
user_input = "EXIT"
|
user_input = "EXIT"
|
||||||
@@ -235,7 +242,7 @@ while True:
|
|||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if user_input != "NEXT COMMAND":
|
if user_input != "GENERATE NEXT COMMAND JSON":
|
||||||
print("Exiting...", flush=True)
|
print("Exiting...", flush=True)
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -250,7 +257,7 @@ 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}")
|
||||||
|
|
||||||
# Exectute command
|
# Execute command
|
||||||
if command_name.lower() != "error":
|
if command_name.lower() != "error":
|
||||||
result = f"Command {command_name} returned: {cmd.execute_command(command_name, arguments)}"
|
result = f"Command {command_name} returned: {cmd.execute_command(command_name, arguments)}"
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user