AutoGPT icon indicating copy to clipboard operation
AutoGPT copied to clipboard

Use `@command()` function decorator

Open Androbin opened this issue 1 year ago • 3 comments

Background

See #1272 @rhernaus

Optimize the execute_command function. The original function used a series of if-elif statements to determine the appropriate action based on the given command name. This structure made the code lengthy, harder to read, and difficult to maintain. By refactoring the function to use a dictionary that maps command names to their respective functions, we can improve readability, conciseness, and maintainability.

Changes

See https://github.com/Significant-Gravitas/Auto-GPT/pull/1272#issuecomment-1510688932

Commands are now registered like this:

@command()
def start_agent(name: str, task: str, prompt: str) -> str:
    ...

Or alternatively:

@command(name="start_agent", aliases=["start_new_agent"])
def do_start_agent(name: str, task: str, prompt: str) -> str:
    ...

They're later called with command(**arguments) syntax, meaning arguments are assigned by name.

Documentation

Test Plan

PR Quality Checklist

  • [x] My pull request is atomic and focuses on a single change.
  • [x] I have thoroughly tested my changes with multiple different prompts.
  • [x] I have considered potential risks and mitigations for my changes.
  • [x] I have documented my changes clearly and comprehensively.
  • [X] I have not snuck in any "extra" small tweaks changes

Androbin avatar Apr 17 '23 05:04 Androbin

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Apr 17 '23 16:04 github-actions[bot]

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Apr 17 '23 16:04 github-actions[bot]

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

github-actions[bot] avatar Apr 17 '23 18:04 github-actions[bot]

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Apr 17 '23 19:04 github-actions[bot]

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

github-actions[bot] avatar Apr 17 '23 22:04 github-actions[bot]

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Apr 17 '23 22:04 github-actions[bot]

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

github-actions[bot] avatar Apr 17 '23 23:04 github-actions[bot]

This is a duplicate of the command registry that is included in #757 but less advanced. Sorry but this is going to make it.

BillSchumacher avatar Apr 19 '23 00:04 BillSchumacher