fix: Update agent creation logic and error message

- Update the logic for checking if an agent name already exists to be case-insensitive.
- Update the error message when an agent with the same name already exists to specify that the name should be unique regardless of case.
This commit is contained in:
SwiftyOS
2023-10-30 15:36:14 +01:00
parent 2bd05827f9
commit d9fbd26b85

9
cli.py
View File

@@ -229,9 +229,11 @@ def create(agent_name):
return return
try: try:
new_agent_dir = f"./autogpts/{agent_name}" new_agent_dir = f"./autogpts/{agent_name}"
agent_json_file = f"./arena/{agent_name}.json" new_agent_name = f"{agent_name.lower()}.json"
if not os.path.exists(new_agent_dir) and not os.path.exists(agent_json_file): existing_arena_files = [name.lower() for name in os.listdir("./arena/")]
if not os.path.exists(new_agent_dir) and not new_agent_name in existing_arena_files:
shutil.copytree("./autogpts/forge", new_agent_dir) shutil.copytree("./autogpts/forge", new_agent_dir)
click.echo( click.echo(
click.style( click.style(
@@ -248,7 +250,7 @@ def create(agent_name):
else: else:
click.echo( click.echo(
click.style( click.style(
f"😞 Agent '{agent_name}' already exists. Enter a different name for your agent", f"😞 Agent '{agent_name}' already exists. Enter a different name for your agent, the name needs to be unique regardless of case",
fg="red", fg="red",
) )
) )
@@ -886,6 +888,5 @@ def update(agent_name, hash, branch):
) )
) )
if __name__ == "__main__": if __name__ == "__main__":
cli() cli()