54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""Deep 编译流水线的唯一命令行入口。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from scripts.provider_router import parse_model_reference
|
|
|
|
from .pipeline import DeepLoop
|
|
|
|
|
|
def _provider_model(value: str) -> str:
|
|
try:
|
|
return parse_model_reference(value).value
|
|
except ValueError as exc:
|
|
raise argparse.ArgumentTypeError(str(exc)) from exc
|
|
|
|
|
|
def _parser() -> argparse.ArgumentParser:
|
|
parser = argparse.ArgumentParser(prog="python -m scripts.dynamic_compile.deep")
|
|
commands = parser.add_subparsers(dest="command", required=True)
|
|
run = commands.add_parser("run", help="run Deep Loop from a skill and its BenchFlow traces")
|
|
run.add_argument("--skill", type=Path, required=True)
|
|
run.add_argument("--traces", type=Path, required=True)
|
|
run.add_argument("--output", type=Path)
|
|
run.add_argument(
|
|
"--model",
|
|
required=True,
|
|
type=_provider_model,
|
|
help="all external model calls use this provider/model",
|
|
)
|
|
resume = commands.add_parser("resume", help="resume a Deep Loop run")
|
|
resume.add_argument("--run", type=Path, required=True)
|
|
return parser
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
args = _parser().parse_args(argv)
|
|
try:
|
|
loop = (
|
|
DeepLoop.create(args.skill, args.traces, args.output, model=args.model)
|
|
if args.command == "run"
|
|
else DeepLoop(args.run)
|
|
)
|
|
print(loop.drive())
|
|
return 0
|
|
except (OSError, ValueError, RuntimeError) as exc:
|
|
print(f"error: {exc}", file=sys.stderr)
|
|
return 2
|
|
|
|
raise SystemExit(main())
|