| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- """本地跑需求生成:只写文件,不入库。
- 在项目根目录执行:
- .venv/bin/python examples/demand/run_local.py
- 默认:品类「早中晚好」,生成约 100 条。结果文件:
- examples/demand/result/早中晚好.json
- examples/demand/result/<execution_id>/execution_id_<execution_id>_demand_items.json
- 可选参数:
- .venv/bin/python examples/demand/run_local.py --cluster 早中晚好 --count 100
- """
- from __future__ import annotations
- import argparse
- import asyncio
- import os
- import sys
- from pathlib import Path
- ROOT = Path(__file__).resolve().parents[2]
- DEMAND_DIR = Path(__file__).resolve().parent
- sys.path.insert(0, str(ROOT))
- os.chdir(DEMAND_DIR)
- from examples.demand.run import main as run_demand
- def parse_args() -> argparse.Namespace:
- parser = argparse.ArgumentParser(description="本地生成需求并写入 JSON,不入库")
- parser.add_argument("--cluster", default="早中晚好", help="二级品类名")
- parser.add_argument("--platform", default="piaoquan", choices=["piaoquan", "changwen", "zengzhang"])
- parser.add_argument("--count", type=int, default=100, help="目标需求数量")
- return parser.parse_args()
- async def _run() -> None:
- args = parse_args()
- print(
- f"[local] cluster={args.cluster} platform={args.platform} "
- f"count={args.count} write_to_db=False",
- flush=True,
- )
- result = await run_demand(
- args.cluster,
- args.platform,
- args.count,
- write_to_db=False,
- )
- execution_id = result.get("execution_id")
- named_path = DEMAND_DIR / "result" / f"{args.cluster}.json"
- items_path = (
- DEMAND_DIR
- / "result"
- / str(execution_id)
- / f"execution_id_{execution_id}_demand_items.json"
- )
- print(f"[local] execution_id={execution_id}", flush=True)
- print(f"[local] 需求文件: {named_path}", flush=True)
- print(f"[local] Agent 原始结果: {items_path}", flush=True)
- if not execution_id:
- raise SystemExit("执行失败:未拿到 execution_id(请检查品类数据和数据库连接)")
- if __name__ == "__main__":
- asyncio.run(_run())
|