Skip to content

Commit

Permalink
Refactor agent.py to improve JSON handling and validation
Browse files Browse the repository at this point in the history
  • Loading branch information
waynehamadi committed Apr 16, 2023
1 parent d934d22 commit bf24cd9
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions autogpt/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

from autogpt.chat import chat_with_ai, create_chat_message
from autogpt.config import Config
from autogpt.json_fixes.bracket_termination import (
attempt_to_fix_json_by_finding_outermost_brackets,
)
from autogpt.json_fixes.master_json_fix_method import fix_json_using_multiple_techniques
from autogpt.json_validation.validate_json import validate_json
from autogpt.logs import logger, print_assistant_thoughts
from autogpt.speech import say_text
from autogpt.spinner import Spinner
Expand Down Expand Up @@ -70,18 +69,20 @@ def start_interaction_loop(self):
cfg.fast_token_limit,
) # TODO: This hardcodes the model to use GPT3.5. Make this an argument

# Print Assistant thoughts
print_assistant_thoughts(self.ai_name, assistant_reply)
assistant_reply_json = fix_json_using_multiple_techniques(assistant_reply)

# Get command name and arguments
try:
command_name, arguments = get_command(
attempt_to_fix_json_by_finding_outermost_brackets(assistant_reply)
)
if cfg.speak_mode:
say_text(f"I want to execute {command_name}")
except Exception as e:
logger.error("Error: \n", str(e))
# Print Assistant thoughts
if assistant_reply_json != {}:
validate_json(assistant_reply_json, 'llm_response_format_1')
# Get command name and arguments
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"]
if cfg.speak_mode:
say_text(f"I want to execute {command_name}")
except Exception as e:
logger.error("Error: \n", str(e))

if not cfg.continuous_mode and self.next_action_count == 0:
### GET USER AUTHORIZATION TO EXECUTE COMMAND ###
Expand Down

0 comments on commit bf24cd9

Please sign in to comment.