Skip to content

Commit fbb2897

Browse files
authored
Allows users to specify a different requirements.txt file to install in Docker, to test other versions or branches of Autogen. Closes microsoft#662 (microsoft#671)
1 parent c835f78 commit fbb2897

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

samples/tools/testbed/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ options:
3737
-h, --help show this help message and exit
3838
3939
-r REPEAT, --repeat REPEAT
40-
The number of repetitions to run for each scenario (default: 10).
40+
The number of repetitions to run for each scenario (default: 1).
4141
4242
-c CONFIG, --config CONFIG
4343
The environment variable name or path to the OAI_CONFIG_LIST (default: OAI_CONFIG_LIST).
4444
45+
--requirements REQUIREMENTS
46+
The requirements file to pip install before running the scenario. This file must be found in
47+
the 'includes' directory. (default: requirements.txt)
48+
4549
--native Run the scenarios natively rather than in docker.
4650
NOTE: This is not advisable, and should be done with great caution.
4751
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pyautogen

samples/tools/testbed/run_scenarios.py

+33-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
INCLUDES_DIR = "includes"
1414

1515

16-
def run_scenarios(scenario, n_repeats, is_native, config_list, results_dir="results"):
16+
def run_scenarios(scenario, n_repeats, is_native, config_list, requirements, results_dir="results"):
1717
"""
1818
Run a set testbed scenarios a given number of times.
1919
@@ -107,7 +107,7 @@ def run_scenarios(scenario, n_repeats, is_native, config_list, results_dir="resu
107107
if is_native:
108108
run_scenario_natively(results_repetition)
109109
else:
110-
run_scenario_in_docker(results_repetition)
110+
run_scenario_in_docker(results_repetition, requirements)
111111

112112

113113
def expand_scenario(scenario_dir, scenario, output_file):
@@ -161,7 +161,7 @@ def run_scenario_natively(work_dir):
161161
return
162162

163163

164-
def run_scenario_in_docker(work_dir, timeout=600):
164+
def run_scenario_in_docker(work_dir, requirements, timeout=600):
165165
"""
166166
Run a scenario in a Docker environment.
167167
@@ -188,12 +188,15 @@ def run_scenario_in_docker(work_dir, timeout=600):
188188
# Prepare the run script
189189
with open(os.path.join(work_dir, "run.sh"), "wt") as f:
190190
f.write(
191-
"""#
191+
f"""#
192192
umask 000
193193
. ./ENV
194-
pip install pyautogen
194+
pip install -r {requirements}
195195
python scenario.py
196196
rm ENV
197+
if [ -d .cache ] ; then
198+
chmod -R a+rw .cache
199+
fi
197200
echo SCENARIO COMPLETE !#!#
198201
"""
199202
)
@@ -258,7 +261,15 @@ def run_scenario_in_docker(work_dir, timeout=600):
258261
default="OAI_CONFIG_LIST",
259262
)
260263
parser.add_argument(
261-
"-r", "--repeat", type=int, help="The number of repetitions to run for each scenario (default: 10).", default=10
264+
"-r", "--repeat", type=int, help="The number of repetitions to run for each scenario (default: 1).", default=1
265+
)
266+
parser.add_argument(
267+
"--requirements",
268+
type=str,
269+
help="The requirements file to pip install before running the scenario. This file must be found in the '"
270+
+ INCLUDES_DIR
271+
+ "' directory. (default: requirements.txt)",
272+
default=None,
262273
)
263274
parser.add_argument(
264275
"--native",
@@ -275,18 +286,31 @@ def run_scenario_in_docker(work_dir, timeout=600):
275286

276287
# Warn if running natively
277288
if args.native:
289+
if args.requirements is not None:
290+
sys.exit("--requirements is not compatible with --native. Exiting.")
291+
278292
choice = input(
279293
'WARNING: Running natively, without Docker, not only poses the usual risks of executing arbitrary AI generated code on your machine, it also makes it impossible to ensure that each test starts from a known and consistent set of initial conditions. For example, if the agents spend time debugging and installing Python libraries to solve the task, then those libraries will be available to all other runs. In other words, earlier runs can influence later runs, leading to many confounds in testing.\n\nAre you absolutely sure you want to continue with native execution? Type "Yes" exactly, and in full, to proceed: '
280294
)
281295

282296
if choice.strip().lower() != "yes":
283-
print("Received '" + choice + "'. Exiting.")
297+
sys.exit("Received '" + choice + "'. Exiting.")
298+
299+
# What requirements file are we working with?
300+
requirements = "requirements.txt"
301+
if args.requirements is not None:
302+
requirements = args.requirements
284303

285-
# Import docker if needed
286304
is_native = True if args.native else False
287305
if not is_native:
306+
# Import docker
288307
import docker
289308

309+
# Make sure the requirements file exists
310+
req_file = os.path.join(INCLUDES_DIR, requirements)
311+
if not os.path.isfile(req_file):
312+
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), req_file)
313+
290314
# Warn aboit a common error
291315
env_file = os.path.join(INCLUDES_DIR, "ENV")
292316
example_file = os.path.join(INCLUDES_DIR, "ENV.example")
@@ -296,4 +320,4 @@ def run_scenario_in_docker(work_dir, timeout=600):
296320
f"The environment file '{env_file}' does not exist (perhaps this is your first time setting up the testbed). A default environment file has been provided, but you may want to edit it to include your API keys and configurations.\n"
297321
)
298322

299-
run_scenarios(args.scenario, args.repeat, is_native, config_list)
323+
run_scenarios(args.scenario, args.repeat, is_native, config_list, requirements)

0 commit comments

Comments
 (0)