From a107233e23a8a08924919bccf732e3509f31939d Mon Sep 17 00:00:00 2001 From: afourney Date: Mon, 4 Dec 2023 14:14:00 -0800 Subject: [PATCH] Testbed can now read the OPENAI_API_KEY in addition to the OAI_CONFIG_LIST (#848) Co-authored-by: Victor Dibia --- samples/tools/testbed/run_scenarios.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/samples/tools/testbed/run_scenarios.py b/samples/tools/testbed/run_scenarios.py index c8e8f0404..6020a7591 100644 --- a/samples/tools/testbed/run_scenarios.py +++ b/samples/tools/testbed/run_scenarios.py @@ -90,10 +90,15 @@ def run_scenarios(scenario, n_repeats, is_native, config_list, requirements, res expand_scenario(scenario_dir, instance, results_repetition) # Append the config list to the ENV file - config_list_json = json.dumps(config_list) with open(os.path.join(results_repetition, "ENV"), "at") as fh: + config_list_json = json.dumps(config_list) fh.write(f"export OAI_CONFIG_LIST='{config_list_json}'\n") + # If set, append the OpenAI API Key + openai_api_key = os.environ.get("OPENAI_API_KEY") + if openai_api_key is not None and len(openai_api_key.strip()) > 0: + fh.write(f"export OPENAI_API_KEY='{openai_api_key}'\n") + # Run the scenario if is_native: run_scenario_natively(results_repetition)