Updated cli

This commit is contained in:
SwiftyOS
2023-09-18 17:56:23 +02:00
parent af7c5e0291
commit 7022eda1a3

60
cli.py
View File

@@ -270,7 +270,9 @@ def start(agent_name):
if os.path.exists(agent_dir) and os.path.isfile(run_command): if os.path.exists(agent_dir) and os.path.isfile(run_command):
subprocess.Popen([frontend_build], cwd=frontend_dir) subprocess.Popen([frontend_build], cwd=frontend_dir)
os.chdir(agent_dir) os.chdir(agent_dir)
if os.name == 'nt':
click.echo(click.style("😞 The script cannot be run on Windows.", fg="red"))
return
subprocess.Popen(["./run"], cwd=agent_dir) subprocess.Popen(["./run"], cwd=agent_dir)
click.echo(f"Agent '{agent_name}' started") click.echo(f"Agent '{agent_name}' started")
elif not os.path.exists(agent_dir): elif not os.path.exists(agent_dir):
@@ -350,7 +352,7 @@ def start(agent_name, subprocess_args):
script_dir = os.path.dirname(os.path.realpath(__file__)) script_dir = os.path.dirname(os.path.realpath(__file__))
agent_dir = os.path.join(script_dir, f"autogpts/{agent_name}") agent_dir = os.path.join(script_dir, f"autogpts/{agent_name}")
benchmark_script = os.path.join(agent_dir, "run_benchmark.sh") benchmark_script = os.path.join(agent_dir, "run_benchmark")
if os.path.exists(agent_dir) and os.path.isfile(benchmark_script): if os.path.exists(agent_dir) and os.path.isfile(benchmark_script):
os.chdir(agent_dir) os.chdir(agent_dir)
subprocess.Popen([benchmark_script, *subprocess_args], cwd=agent_dir) subprocess.Popen([benchmark_script, *subprocess_args], cwd=agent_dir)
@@ -392,16 +394,17 @@ def benchmark_categories_list():
) )
# Use it as the base for the glob pattern, excluding 'deprecated' directory # Use it as the base for the glob pattern, excluding 'deprecated' directory
for data_file in glob.glob(glob_path, recursive=True): for data_file in glob.glob(glob_path, recursive=True):
with open(data_file, "r") as f: if 'deprecated' not in data_file:
try: with open(data_file, "r") as f:
data = json.load(f) try:
categories.update(data.get("category", [])) data = json.load(f)
except json.JSONDecodeError: categories.update(data.get("category", []))
print(f"Error: {data_file} is not a valid JSON file.") except json.JSONDecodeError:
continue print(f"Error: {data_file} is not a valid JSON file.")
except IOError: continue
print(f"IOError: file could not be read: {data_file}") except IOError:
continue print(f"IOError: file could not be read: {data_file}")
continue
if categories: if categories:
click.echo(click.style("Available categories: 📚", fg="green")) click.echo(click.style("Available categories: 📚", fg="green"))
@@ -435,21 +438,22 @@ def benchmark_tests_list():
) )
# Use it as the base for the glob pattern, excluding 'deprecated' directory # Use it as the base for the glob pattern, excluding 'deprecated' directory
for data_file in glob.glob(glob_path, recursive=True): for data_file in glob.glob(glob_path, recursive=True):
with open(data_file, "r") as f: if 'deprecated' not in data_file:
try: with open(data_file, "r") as f:
data = json.load(f) try:
category = data.get("category", []) data = json.load(f)
test_name = data.get("name", "") category = data.get("category", [])
if category and test_name: test_name = data.get("name", "")
if category[0] not in tests: if category and test_name:
tests[category[0]] = [] if category[0] not in tests:
tests[category[0]].append(test_name) tests[category[0]] = []
except json.JSONDecodeError: tests[category[0]].append(test_name)
print(f"Error: {data_file} is not a valid JSON file.") except json.JSONDecodeError:
continue print(f"Error: {data_file} is not a valid JSON file.")
except IOError: continue
print(f"IOError: file could not be read: {data_file}") except IOError:
continue print(f"IOError: file could not be read: {data_file}")
continue
if tests: if tests:
click.echo(click.style("Available tests: 📚", fg="green")) click.echo(click.style("Available tests: 📚", fg="green"))
@@ -463,7 +467,7 @@ def benchmark_tests_list():
.replace(" ", " ") .replace(" ", " ")
) )
test_name_padded = f"{test_name:<40}" test_name_padded = f"{test_name:<40}"
click.echo(click.style(f"\t\t🔬 {test_name_padded} - Test{test}", fg="cyan")) click.echo(click.style(f"\t\t🔬 {test_name_padded} - {test}", fg="cyan"))
else: else:
click.echo(click.style("No tests found 😞", fg="red")) click.echo(click.style("No tests found 😞", fg="red"))