AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Added --test, consolidate files, reports working (#83)
Silen Naihin8df82909b293
diff --git a/agbenchmark/RegressionManager.py b/agbenchmark/ReportManager.pysimilarity index 75%rename from agbenchmark/RegressionManager.pyrename to agbenchmark/ReportManager.pyindex ac9efc6969..e6d8f62f63 100644--- a/agbenchmark/RegressionManager.py+++ b/agbenchmark/ReportManager.py@@ -1,12 +1,17 @@import json-from typing import Union+import os+import sys+import time+from datetime import datetime+from typing import Any, Dict, Union-class RegressionManager:+class ReportManager:"""Abstracts interaction with the regression tests file"""def __init__(self, filename: str):self.filename = filename+ self.start_time = time.time()self.load()def load(self) -> None:@@ -40,6 +45,18 @@ class RegressionManager:del self.tests[test_name]self.save()+ def end_info_report(self, config: Dict[str, Any]) -> None:+ command = " ".join(sys.argv)+ self.tests = {+ "command": command.split(os.sep)[-1],+ "completion_time": datetime.now().strftime("%Y-%m-%d-%H:%M"),+ "time_elapsed": str(round(time.time() - self.start_time, 2)) + " seconds",+ "tests": self.tests,+ "config": config,+ }++ self.save()+def replace_backslash(self, value: str) -> Union[str, list[str], dict]:if isinstance(value, str):return value.replace("\\\\", "/") # escape \ with \\diff --git a/agbenchmark/agent_interface.py b/agbenchmark/agent_interface.pyindex 1d43577c75..d058ad4c2c 100644--- a/agbenchmark/agent_interface.py+++ b/agbenchmark/agent_interface.py@@ -3,6 +3,7 @@ import shutilimport subprocessimport sysimport time+from pathlib import Pathfrom typing import Any, Dictfrom dotenv import load_dotenv@@ -21,6 +22,7 @@ def run_agent("""Calling to get a response"""if MOCK_FLAG:+ print("ITS A MOCK TEST", challenge_location)copy_artifacts_into_workspace(config["workspace"], "artifacts_out", challenge_location)@@ -30,19 +32,13 @@ def run_agent(f"Running Python function '{config['entry_path']}' with timeout {timeout}")- # Get the current working directory- cwd = os.path.join(os.getcwd(), config["home_path"])-- # Add current directory to Python's import path- sys.path.append(cwd)-command = [sys.executable, config["entry_path"], str(task)]process = subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,universal_newlines=True,- cwd=cwd,+ cwd=os.getcwd(),)start_time = time.time()@@ -79,7 +75,9 @@ def run_agent(def copy_artifacts_into_workspace(workspace: str, artifact_folder_name: str, challenge_dir_path: str) -> None:- source_dir = os.path.join(challenge_dir_path, artifact_folder_name)+ # this file is at agbenchmark\agent_interface.py+ script_dir = Path(__file__).resolve().parent.parent+ source_dir = os.path.join(script_dir, challenge_dir_path, artifact_folder_name)# Check if source_dir exists, if not then return immediately.if not os.path.exists(source_dir):diff --git a/agbenchmark/challenges/define_task_types.py b/agbenchmark/challenges/define_task_types.pyindex 94cba5b724..f4e3f2220e 100644--- a/agbenchmark/challenges/define_task_types.py+++ b/agbenchmark/challenges/define_task_types.py@@ -1,4 +1,5 @@import json+from pathlib import Pathfrom typing import List, Optionalfrom pydantic import BaseModel@@ -32,7 +33,12 @@ class ChallengeData(BaseModel):@staticmethoddef deserialize(path: str) -> "ChallengeData":+ # this script is in root/agbenchmark/challenges/define_task_types.py+ script_dir = Path(__file__).resolve().parent.parent.parent+ path = str(script_dir / path)+print("Deserializing", path)+with open(path, "r") as file:data = json.load(file)return ChallengeData(**data)diff --git a/agbenchmark/challenges/interface/search/data.json b/agbenchmark/challenges/interface/search/data.jsonindex 17ee1ac1a7..f59b2dc9b5 100644--- a/agbenchmark/challenges/interface/search/data.json+++ b/agbenchmark/challenges/interface/search/data.json@@ -2,7 +2,7 @@"name": "TestSearch","category": ["interface"],"task": "Open 'https://silennaihin.com/random/plain.html' and paste the text on the page in a .txt file",- "dependencies": [],+ "dependencies": ["TestWriteFile"],"ground": {"answer": "This is a Heading\nThis is a paragraph.","should_contain": ["Heading", "paragraph"],diff --git a/agbenchmark/challenges/test_all.py b/agbenchmark/challenges/test_all.pyindex 7dee0b2ab8..f8bb23471e 100644--- a/agbenchmark/challenges/test_all.py+++ b/agbenchmark/challenges/test_all.py@@ -19,7 +19,7 @@ load_dotenv()IMPROVE = os.getenv("IMPROVE", "False")-json_files = glob.glob(f"{CURRENT_DIRECTORY}/challenges/**/data.json", recursive=True)+json_files = glob.glob(f"{CURRENT_DIRECTORY}/**/data.json", recursive=True)def get_test_path(json_file: str) -> str:@@ -55,7 +55,7 @@ def generate_tests() -> None:)sys.path.append(str(custom_python_location))- for (module_loader, name, ispkg) in pkgutil.iter_modules(+ for module_loader, name, ispkg in pkgutil.iter_modules([str(custom_python_location)]):module = importlib.import_module(name)diff --git a/config.json b/agbenchmark/config.jsonsimilarity index 53%rename from config.jsonrename to agbenchmark/config.jsonindex 8bbcebdbd3..9dd8b16abc 100644--- a/config.json+++ b/agbenchmark/config.json@@ -1,6 +1,5 @@{"workspace": "${os.path.join(Path.home(), 'miniagi')}",- "entry_path": "benchmarks.py",- "home_path": "agent/mini-agi",+ "entry_path": "agbenchmark/benchmarks.py","cutoff": 60}diff --git a/agbenchmark/conftest.py b/agbenchmark/conftest.pyindex e321f5a26c..87fdc9c104 100644--- a/agbenchmark/conftest.py+++ b/agbenchmark/conftest.py@@ -6,9 +6,10 @@ from typing import Any, Dict, Generatorimport pytest-from agbenchmark.RegressionManager import RegressionManager+from agbenchmark.ReportManager import ReportManagerfrom agbenchmark.start_benchmark import (CONFIG_PATH,+ INFO_TESTS_PATH,REGRESSION_TESTS_PATH,get_regression_data,)@@ -106,7 +107,8 @@ def challenge_data(request: Any) -> None:return request.param-regression_manager = RegressionManager(REGRESSION_TESTS_PATH)+regression_manager = ReportManager(REGRESSION_TESTS_PATH)+info_manager = ReportManager(INFO_TESTS_PATH)def pytest_runtest_makereport(item: Any, call: Any) -> None:@@ -130,12 +132,21 @@ def pytest_runtest_makereport(item: Any, call: Any) -> None:print("pytest_runtest_makereport", test_details)if call.excinfo is None:regression_manager.add_test(item.nodeid.split("::")[1], test_details)+ test_details["success"] = Trueelse:regression_manager.remove_test(item.nodeid.split("::")[1])+ test_details["success"] = False+ test_details["fail_reason"] = str(call.excinfo.value)+ info_manager.add_test(item.nodeid.split("::")[1], test_details)-def pytest_sessionfinish() -> None:- """Called at the end of the session to save regression tests"""++def pytest_sessionfinish(session: Any) -> None:+ """Called at the end of the session to save regression tests and info"""+ with open(CONFIG_PATH, "r") as f:+ config = json.load(f)++ info_manager.end_info_report(config)regression_manager.save()diff --git a/regression_tests.json b/agbenchmark/regression_tests.jsonsimilarity index 61%rename from regression_tests.jsonrename to agbenchmark/regression_tests.jsonindex 0cf2d5f30a..68632a127d 100644--- a/regression_tests.json+++ b/agbenchmark/regression_tests.json@@ -1,90 +1,99 @@{- "TestBasicMemory": {+ "TestReadFile": {"difficulty": "basic","dependencies": [- "TestReadFile","TestWriteFile"],- "test": "agbenchmark/challenges/memory/m1"- },- "TestBasicRetrieval": {- "difficulty": "basic",- "dependencies": [- "TestWriteFile",- "TestSearch"- ],- "test": "agbenchmark/challenges/retrieval/r1"- },- "TestCreateSimpleWebServer": {- "difficulty": "basic",- "dependencies": [],- "test": "agbenchmark/challenges/code/d3"+ "test": "agbenchmark/challenges/interface/read_file",+ "success": true},- "TestDebugSimpleTypoWithGuidance": {+ "TestBasicMemory": {"difficulty": "basic","dependencies": ["TestReadFile","TestWriteFile"],- "test": "agbenchmark/challenges/code/d1"+ "test": "agbenchmark/challenges/memory/m1",+ "success": true},- "TestDebugSimpleTypoWithoutGuidance": {- "difficulty": "medium",+ "TestBasicRetrieval": {+ "difficulty": "basic","dependencies": [- "TestDebugSimpleTypoWithGuidance"+ "TestWriteFile",+ "TestSearch"],- "test": "agbenchmark/challenges/code/d2"+ "test": "agbenchmark/challenges/retrieval/r1",+ "success": true},- "TestReadFile": {+ "TestRememberMultipleIds": {"difficulty": "basic","dependencies": [- "TestWriteFile"+ "TestBasicMemory"],- "test": "agbenchmark/challenges/interface/read_file"+ "test": "agbenchmark/challenges/memory/m2",+ "success": true},- "TestRememberMultipleIds": {+ "TestRetrieval2": {"difficulty": "basic","dependencies": [- "TestBasicMemory"+ "TestBasicRetrieval"],- "test": "agbenchmark/challenges/memory/m2"+ "test": "agbenchmark/challenges/retrieval/r2",+ "success": true},"TestRememberMultipleIdsWithNoise": {"difficulty": "medium","dependencies": ["TestRememberMultipleIds"],- "test": "agbenchmark/challenges/memory/m3"+ "test": "agbenchmark/challenges/memory/m3",+ "success": true},- "TestRememberMultiplePhrasesWithNoise": {- "difficulty": "medium",+ "TestRetrieval3": {+ "difficulty": "basic","dependencies": [- "TestRememberMultipleIdsWithNoise"+ "TestRetrieval2"],- "test": "agbenchmark/challenges/memory/m4"+ "test": "agbenchmark/challenges/retrieval/r3",+ "success": true},- "TestRetrieval2": {- "difficulty": "basic",+ "TestRememberMultiplePhrasesWithNoise": {+ "difficulty": "medium","dependencies": [- "TestBasicRetrieval"+ "TestRememberMultipleIdsWithNoise"],- "test": "agbenchmark/challenges/retrieval/r2"+ "test": "agbenchmark/challenges/memory/m4",+ "success": true},- "TestRetrieval3": {+ "TestSearch": {"difficulty": "basic","dependencies": [- "TestRetrieval2"+ "TestWriteFile"],- "test": "agbenchmark/challenges/retrieval/r3"+ "test": "agbenchmark/challenges/interface/search",+ "success": true},- "TestSearch": {+ "TestWriteFile": {"difficulty": "basic","dependencies": [],- "test": "agbenchmark/challenges/interface/search"+ "test": "agbenchmark/challenges/interface/write_file",+ "success": true},- "TestWriteFile": {+ "TestDebugSimpleTypoWithGuidance": {"difficulty": "basic",- "dependencies": [],- "test": "agbenchmark/challenges/interface/write_file"+ "dependencies": [+ "TestReadFile",+ "TestWriteFile"+ ],+ "test": "agbenchmark/challenges/code/d1",+ "success": true+ },+ "TestDebugSimpleTypoWithoutGuidance": {+ "difficulty": "medium",+ "dependencies": [+ "TestDebugSimpleTypoWithGuidance"+ ],+ "test": "agbenchmark/challenges/code/d2",+ "success": true}}\ No newline at end of filediff --git a/agbenchmark/reports/1.json b/agbenchmark/reports/1.jsonnew file mode 100644index 0000000000..df07fb878d--- /dev/null+++ b/agbenchmark/reports/1.json@@ -0,0 +1,109 @@+{+ "command": "agbenchmark start --mock",+ "completion_time": "2023-07-10-21:19",+ "time_elapsed": "8.75 seconds",+ "tests": {+ "TestWriteFile": {+ "difficulty": "basic",+ "dependencies": [],+ "test": "agbenchmark/challenges/interface/write_file",+ "success": true+ },+ "TestReadFile": {+ "difficulty": "basic",+ "dependencies": [+ "TestWriteFile"+ ],+ "test": "agbenchmark/challenges/interface/read_file",+ "success": true+ },+ "TestSearch": {+ "difficulty": "basic",+ "dependencies": [+ "TestWriteFile"+ ],+ "test": "agbenchmark/challenges/interface/search",+ "success": true+ },+ "TestDebugSimpleTypoWithGuidance": {+ "difficulty": "basic",+ "dependencies": [+ "TestReadFile",+ "TestWriteFile"+ ],+ "test": "agbenchmark/challenges/code/d1",+ "success": true+ },+ "TestBasicMemory": {+ "difficulty": "basic",+ "dependencies": [+ "TestReadFile",+ "TestWriteFile"+ ],+ "test": "agbenchmark/challenges/memory/m1",+ "success": true+ },+ "TestBasicRetrieval": {+ "difficulty": "basic",+ "dependencies": [+ "TestWriteFile",+ "TestSearch"+ ],+ "test": "agbenchmark/challenges/retrieval/r1",+ "success": true+ },+ "TestDebugSimpleTypoWithoutGuidance": {+ "difficulty": "medium",+ "dependencies": [+ "TestDebugSimpleTypoWithGuidance"+ ],+ "test": "agbenchmark/challenges/code/d2",+ "success": true+ },+ "TestRememberMultipleIds": {+ "difficulty": "basic",+ "dependencies": [+ "TestBasicMemory"+ ],+ "test": "agbenchmark/challenges/memory/m2",+ "success": true+ },+ "TestRetrieval2": {+ "difficulty": "basic",+ "dependencies": [+ "TestBasicRetrieval"+ ],+ "test": "agbenchmark/challenges/retrieval/r2",+ "success": true+ },+ "TestRememberMultipleIdsWithNoise": {+ "difficulty": "medium",+ "dependencies": [+ "TestRememberMultipleIds"+ ],+ "test": "agbenchmark/challenges/memory/m3",+ "success": true+ },+ "TestRetrieval3": {+ "difficulty": "basic",+ "dependencies": [+ "TestRetrieval2"+ ],+ "test": "agbenchmark/challenges/retrieval/r3",+ "success": true+ },+ "TestRememberMultiplePhrasesWithNoise": {+ "difficulty": "medium",+ "dependencies": [+ "TestRememberMultipleIdsWithNoise"+ ],+ "test": "agbenchmark/challenges/memory/m4",+ "success": true+ }+ },+ "config": {+ "workspace": "${os.path.join(Path.home(), 'miniagi')}",+ "entry_path": "agbenchmark/benchmarks.py",+ "cutoff": 60+ }+}\ No newline at end of filediff --git a/agbenchmark/start_benchmark.py b/agbenchmark/start_benchmark.pyindex 68c7932be6..917cd4e8aa 100644--- a/agbenchmark/start_benchmark.py+++ b/agbenchmark/start_benchmark.py@@ -10,12 +10,16 @@ from dotenv import load_dotenvload_dotenv()+from agbenchmark.utils import calculate_info_test_path+CURRENT_DIRECTORY = Path(__file__).resolve().parent+benchmarks_folder_path = Path(os.getcwd()) / "agbenchmark"-CONFIG_PATH = str(Path(os.getcwd()) / "config.json")+CONFIG_PATH = str(benchmarks_folder_path / "config.json")+REGRESSION_TESTS_PATH = str(benchmarks_folder_path / "regression_tests.json")-REGRESSION_TESTS_PATH = str(Path(os.getcwd()) / "regression_tests.json")+INFO_TESTS_PATH = calculate_info_test_path(benchmarks_folder_path)@click.group()@@ -25,10 +29,11 @@ def cli() -> None:@cli.command()@click.option("--category", default=None, help="Specific category to run")[email protected]("--test", default=None, help="Specific test to run")@click.option("--maintain", is_flag=True, help="Runs only regression tests")@click.option("--improve", is_flag=True, help="Run only non-regression tests")@click.option("--mock", is_flag=True, help="Run with mock")-def start(category: str, maintain: bool, improve: bool, mock: bool) -> int:+def start(category: str, test: str, maintain: bool, improve: bool, mock: bool) -> int:"""Start the benchmark tests. If a category flag is provided, run the categories with that mark."""# Check if configuration file exists and is not emptyif maintain and improve:@@ -37,6 +42,16 @@ def start(category: str, maintain: bool, improve: bool, mock: bool) -> int:)return 1+ if test and (category or maintain or improve):+ print(+ "Error: If you're running a specific test make sure no other options are selected. Please just pass the --test."+ )+ return 1++ if not benchmarks_folder_path.exists():+ benchmarks_folder_path.mkdir(exist_ok=True)++ print(CONFIG_PATH, os.path.exists(CONFIG_PATH), os.stat(CONFIG_PATH).st_size)if not os.path.exists(CONFIG_PATH) or os.stat(CONFIG_PATH).st_size == 0:config = {}@@ -46,12 +61,12 @@ def start(category: str, maintain: bool, improve: bool, mock: bool) -> int:)config["entry_path"] = click.prompt(- "Please enter a the path to your run_specific_agent function implementation",- default="/benchmarks.py",+ "Please enter a the path to your run_specific_agent function implementation within the benchmarks folder",+ default="benchmarks.py",)config["cutoff"] = click.prompt(- "Please enter a hard cutoff runtime for your agent",+ "Please enter a hard cutoff runtime for your agent per test",default="60",)@@ -65,7 +80,11 @@ def start(category: str, maintain: bool, improve: bool, mock: bool) -> int:os.environ["MOCK_TEST"] = "True" if mock else "False"if not os.path.exists(REGRESSION_TESTS_PATH):- with open(REGRESSION_TESTS_PATH, "a"):+ with open(REGRESSION_TESTS_PATH, "w"):+ pass++ if not os.path.exists(INFO_TESTS_PATH):+ with open(INFO_TESTS_PATH, "w"):passprint("Current configuration:")@@ -73,18 +92,22 @@ def start(category: str, maintain: bool, improve: bool, mock: bool) -> int:print(f"{key}: {value}")pytest_args = ["-vs"]- if category:- pytest_args.extend(["-m", category])- print("Starting benchmark tests ", category)+ if test:+ print("Running specific test:", test)+ pytest_args.extend(["-k", test])else:- print("Running all categories")-- if maintain:- print("Running only regression tests")- pytest_args.append("--maintain")- elif improve:- print("Running only non-regression tests")- pytest_args.append("--improve")+ if category:+ pytest_args.extend(["-m", category])+ print("Running tests of category:", category)+ else:+ print("Running all categories")++ if maintain:+ print("Running only regression tests")+ pytest_args.append("--maintain")+ elif improve:+ print("Running only non-regression tests")+ pytest_args.append("--improve")if mock:pytest_args.append("--mock")diff --git a/agbenchmark/utils.py b/agbenchmark/utils.pyindex b05a7ac312..ffde0c6d35 100644--- a/agbenchmark/utils.py+++ b/agbenchmark/utils.py@@ -1 +1,17 @@# radio charts, logs, helper functions for tests, anything else relevant.+import glob+from pathlib import Path+++def calculate_info_test_path(benchmarks_folder_path: Path) -> str:+ INFO_TESTS_PATH = benchmarks_folder_path / "reports"++ if not INFO_TESTS_PATH.exists():+ INFO_TESTS_PATH.mkdir(parents=True, exist_ok=True)+ return str(INFO_TESTS_PATH / "1.json")+ else:+ json_files = glob.glob(str(INFO_TESTS_PATH / "*.json"))+ file_count = len(json_files)+ run_name = f"{file_count + 1}.json"+ new_file_path = INFO_TESTS_PATH / run_name+ return str(new_file_path)diff --git a/agent/Auto-GPT b/agent/Auto-GPTindex f360d503b1..dc2a76990c 160000--- a/agent/Auto-GPT+++ b/agent/Auto-GPT@@ -1 +1 @@-Subproject commit f360d503b113119f6b3ce0acff1dbb4dfae2223a+Subproject commit dc2a76990c75fafacbeaa76eb2e27d48de44cadddiff --git a/agent/SuperAGI b/agent/SuperAGIindex 7ab2994d4b..a28224d825 160000--- a/agent/SuperAGI+++ b/agent/SuperAGI@@ -1 +1 @@-Subproject commit 7ab2994d4b44fa008f9ac27b196f134d27878916+Subproject commit a28224d82572b598ccee1057086fabaf33e1aaa9diff --git a/agent/config_example.json b/agent/config_example.jsonindex ba2ec0b80b..7ab65bc202 100644--- a/agent/config_example.json+++ b/agent/config_example.json@@ -1,6 +1,5 @@{"workspace": "projects/my-new-project/workspace",- "entry_path": "benchmarks.py",- "home_path": "",+ "entry_path": "agbenchmark/benchmarks.py","cutoff": 60}diff --git a/agent/gpt-engineer b/agent/gpt-engineerindex 4af8c137e8..cde9be3e73 160000--- a/agent/gpt-engineer+++ b/agent/gpt-engineer@@ -1 +1 @@-Subproject commit 4af8c137e82cc51fdd31c23327ceffd64194b984+Subproject commit cde9be3e73212b3d8366a4ed149a18122bfe2333diff --git a/agent/mini-agi b/agent/mini-agiindex 4af8a7e608..ad2b345050 160000--- a/agent/mini-agi+++ b/agent/mini-agi@@ -1 +1 @@-Subproject commit 4af8a7e6085f0518f06180fbf87024a2c9db4c88+Subproject commit ad2b345050e07efb7ad0bde68c93bc2b4e2d7a92diff --git a/agent/smol-developer b/agent/smol-developerindex a1e4a9ff3a..c52b14b1d5 160000--- a/agent/smol-developer+++ b/agent/smol-developer@@ -1 +1 @@-Subproject commit a1e4a9ff3a75909c4a892e409a55f86a2c57b7c6+Subproject commit c52b14b1d5b1b74d886f08d9914e7f43437f609ddiff --git a/mypy.ini b/mypy.iniindex 764c239f1a..d35c6962d6 100644--- a/mypy.ini+++ b/mypy.ini@@ -15,5 +15,5 @@ ignore_errors = True[mypy-agbenchmark.mocks.tests.basic_mocks.*]ignore_errors = True-[mypy-agbenchmark.tests.regression.RegressionManager.*]+[mypy-agbenchmark.tests.regression.ReportManager.*]ignore_errors = True