From fa0df12439b7beea91a46f08e7f6154900dc1047 Mon Sep 17 00:00:00 2001 From: Silen Naihin <silen.naihin@gmail.com> Date: Mon, 26 Jun 2023 09:27:20 -0400 Subject: [PATCH] mini agi attempt --- agbenchmark/conftest.py | 44 +++++++++++-------- .../tests/regression/regression_tests.json | 15 +------ agent/agbenchmark_run.py | 27 ++++++++++++ 3 files changed, 54 insertions(+), 32 deletions(-) create mode 100644 agent/agbenchmark_run.py diff --git a/agbenchmark/conftest.py b/agbenchmark/conftest.py index 78114c204..b3b69f194 100644 --- a/agbenchmark/conftest.py +++ b/agbenchmark/conftest.py @@ -7,6 +7,7 @@ import requests from requests.exceptions import RequestException from agbenchmark.mocks.MockManager import MockManager from agbenchmark.challenges.define_task_types import ChallengeData +import subprocess @pytest.fixture(scope="module") @@ -42,27 +43,34 @@ def server_response(request, config): else: task = request.param mock_function_name = None - # print(f"Server starting at {request.module}") - # try: - # response = requests.post( - # f"{config['hostname']}:{config['port']}", data={"task": task} - # ) - # response.raise_for_status() # This will raise an HTTPError if the status is 4xx or 5xx - # except RequestException: - # # If an exception occurs (could be connection, timeout, or HTTP errors), we use the mock - if mock_function_name: - mock_manager = MockManager( - task - ) # workspace doesn't need to be passed in, stays the same - print("Server unavailable, using mock", mock_function_name) - mock_manager.delegate(mock_function_name) - else: - print("No mock provided") + # get the current file's directory + current_dir = os.path.dirname(os.path.abspath(__file__)) + # construct the script's path + script_path = os.path.join(current_dir, "..", "agent", "agbenchmark_run.py") + + # form the command + command = ["python", script_path, task] + + # if mock_function_name: + # mock_manager = MockManager( + # task + # ) # workspace doesn't need to be passed in, stays the same + # print("Server unavailable, using mock", mock_function_name) + # mock_manager.delegate(mock_function_name) # else: - # # This code is run if no exception occurred - # print(f"Request succeeded with status code {response.status_code}") + # print("No mock provided") + + try: + # run the command and wait for it to complete + result = subprocess.run( + command, shell=True, check=True, text=True, capture_output=True + ) + return result + except subprocess.CalledProcessError as e: + print(f"Subprocess failed with the following error:\n{e}") + # If the subprocess returns a non-zero exit status regression_json = "agbenchmark/tests/regression/regression_tests.json" diff --git a/agbenchmark/tests/regression/regression_tests.json b/agbenchmark/tests/regression/regression_tests.json index c84fc9c99..9e26dfeeb 100644 --- a/agbenchmark/tests/regression/regression_tests.json +++ b/agbenchmark/tests/regression/regression_tests.json @@ -1,14 +1 @@ -{ - "TestWriteFile": { - "difficulty": "basic", - "dependencies": [], - "test": "agbenchmark/tests/basic_abilities/write_file/write_file_test.py::TestWriteFile::test_write_file[regression_data0-server_response0]" - }, - "TestReadFile": { - "difficulty": "basic", - "dependencies": [ - "test_write_file" - ], - "test": "agbenchmark/tests/basic_abilities/read_file/read_file_test.py::TestReadFile::test_read_file[regression_data0-server_response0]" - } -} \ No newline at end of file +{} \ No newline at end of file diff --git a/agent/agbenchmark_run.py b/agent/agbenchmark_run.py new file mode 100644 index 000000000..f509f5e66 --- /dev/null +++ b/agent/agbenchmark_run.py @@ -0,0 +1,27 @@ +import argparse +import subprocess +import os + + +def main(objective): + # get the current directory + current_dir = os.path.dirname(os.path.abspath(__file__)) + + # form the command + command = ( + f"python {os.path.join(current_dir, 'mini-agi', 'miniagi.py')} {objective}" + ) + + # run the command + subprocess.run(command, shell=True) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Run miniagi.py with an objective.") + parser.add_argument( + "objective", type=str, help="The objective to pass to miniagi.py" + ) + + args = parser.parse_args() + + main(args.objective)