| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #!/usr/bin/env python3
- """
- Generate a compact input file for web-UI LLM enrichment.
- Outputs: enrich_input.json — only subcategories missing description or examples.
- Usage:
- python -m bom_assistant.suppliers.lcsc.make_enrich_input # all
- python -m bom_assistant.suppliers.lcsc.make_enrich_input --limit 100 # batch 1
- python -m bom_assistant.suppliers.lcsc.make_enrich_input --skip 100 --limit 100 # batch 2
- python -m bom_assistant.suppliers.lcsc.make_enrich_input --skip 200 --limit 100 # batch 3
- # attach each enrich_input.json to claude.ai, apply output, move to next batch
- """
- from __future__ import annotations
- import argparse
- import json
- from pathlib import Path
- _CATS_PATH = Path(__file__).parent / "categories.json"
- _OUT_PATH = Path(__file__).parent / "enrich_input.json"
- def main() -> None:
- parser = argparse.ArgumentParser()
- parser.add_argument("--limit", type=int, default=None, help="max subcategories to include")
- parser.add_argument("--skip", type=int, default=0, help="skip first N subcategories")
- args = parser.parse_args()
- cats = json.loads(_CATS_PATH.read_text(encoding="utf-8"))
- needed: list[dict] = []
- for cat in cats:
- for sub in cat["subcategories"]:
- missing_desc = not sub.get("description")
- missing_ex = not sub.get("examples")
- if not missing_desc and not missing_ex:
- continue
- entry: dict = {
- "id": sub["id"],
- "category": cat["category"],
- "name": sub["name"],
- }
- if sub.get("examples"):
- entry["examples"] = sub["examples"]
- if missing_ex:
- entry["need_examples"] = True
- needed.append(entry)
- needed = needed[args.skip :]
- if args.limit:
- needed = needed[: args.limit]
- _OUT_PATH.write_text(
- json.dumps(needed, indent=2, ensure_ascii=False), encoding="utf-8"
- )
- need_ex = sum(1 for e in needed if e.get("need_examples"))
- total_needed = sum(
- 1 for c in cats for s in c["subcategories"]
- if not s.get("description") or not s.get("examples")
- )
- remaining = total_needed - args.skip - len(needed)
- print(f"Wrote {len(needed)} subcategories to {_OUT_PATH.name}")
- print(f" {len(needed)} need description, {need_ex} also need examples")
- if remaining > 0:
- print(f" {remaining} more remaining after this batch")
- if __name__ == "__main__":
- main()
|