Repository navigation
Expand file tree
/
Copy pathexample.py
More file actions
75 lines (59 loc) · 2.34 KB
/
Copy pathexample.py
File metadata and controls
75 lines (59 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Copyright 2026 Princeton AI for Accelerating Invention Lab
# Author: Aiden Yiliu Li
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the License);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an AS IS BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# See LICENSE.txt for the full license text.
import argparse
import asyncio
import os
import sys
from pathlib import Path
def _ensure_src_on_path() -> Path:
repo_root = Path(__file__).resolve().parent
src_dir = repo_root / "src"
sys.path.insert(0, str(src_dir))
return repo_root
async def main_async() -> int:
repo_root = _ensure_src_on_path()
from avenir_web.runner import AvenirWebRunner
parser = argparse.ArgumentParser()
parser.add_argument("--config", default=str(repo_root / "src" / "config" / "batch_experiment.toml"))
parser.add_argument("--task", required=True)
parser.add_argument("--website", required=True)
parser.add_argument("--task-id", default=None)
parser.add_argument("--output-dir", default=str(repo_root / "outputs"))
parser.add_argument("--mode", default=None, help="Browser mode: headless, headed, or demo")
args = parser.parse_args()
config_path = Path(args.config).resolve()
runner = AvenirWebRunner.from_toml(config_path)
if isinstance(runner.config, dict):
runner.config.setdefault("basic", {})
runner.config["basic"]["save_file_dir"] = str(Path(args.output_dir).resolve())
if args.mode is not None:
runner.config.setdefault("playwright", {})
runner.config["playwright"]["mode"] = args.mode
if not os.getenv("OPENROUTER_API_KEY"):
raise SystemExit("Missing OPENROUTER_API_KEY in environment")
result = await runner(
confirmed_task=args.task,
website=args.website,
task_id=args.task_id,
)
print(result)
return 0
def main() -> None:
raise SystemExit(asyncio.run(main_async()))
if __name__ == "__main__":
main()