make_enrich_input.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env python3
  2. """
  3. Generate a compact input file for web-UI LLM enrichment.
  4. Outputs: enrich_input.json — only subcategories missing description or examples.
  5. Usage:
  6. python -m bom_assistant.suppliers.lcsc.make_enrich_input # all
  7. python -m bom_assistant.suppliers.lcsc.make_enrich_input --limit 100 # batch 1
  8. python -m bom_assistant.suppliers.lcsc.make_enrich_input --skip 100 --limit 100 # batch 2
  9. python -m bom_assistant.suppliers.lcsc.make_enrich_input --skip 200 --limit 100 # batch 3
  10. # attach each enrich_input.json to claude.ai, apply output, move to next batch
  11. """
  12. from __future__ import annotations
  13. import argparse
  14. import json
  15. from pathlib import Path
  16. _CATS_PATH = Path(__file__).parent / "categories.json"
  17. _OUT_PATH = Path(__file__).parent / "enrich_input.json"
  18. def main() -> None:
  19. parser = argparse.ArgumentParser()
  20. parser.add_argument("--limit", type=int, default=None, help="max subcategories to include")
  21. parser.add_argument("--skip", type=int, default=0, help="skip first N subcategories")
  22. args = parser.parse_args()
  23. cats = json.loads(_CATS_PATH.read_text(encoding="utf-8"))
  24. needed: list[dict] = []
  25. for cat in cats:
  26. for sub in cat["subcategories"]:
  27. missing_desc = not sub.get("description")
  28. missing_ex = not sub.get("examples")
  29. if not missing_desc and not missing_ex:
  30. continue
  31. entry: dict = {
  32. "id": sub["id"],
  33. "category": cat["category"],
  34. "name": sub["name"],
  35. }
  36. if sub.get("examples"):
  37. entry["examples"] = sub["examples"]
  38. if missing_ex:
  39. entry["need_examples"] = True
  40. needed.append(entry)
  41. needed = needed[args.skip :]
  42. if args.limit:
  43. needed = needed[: args.limit]
  44. _OUT_PATH.write_text(
  45. json.dumps(needed, indent=2, ensure_ascii=False), encoding="utf-8"
  46. )
  47. need_ex = sum(1 for e in needed if e.get("need_examples"))
  48. total_needed = sum(
  49. 1 for c in cats for s in c["subcategories"]
  50. if not s.get("description") or not s.get("examples")
  51. )
  52. remaining = total_needed - args.skip - len(needed)
  53. print(f"Wrote {len(needed)} subcategories to {_OUT_PATH.name}")
  54. print(f" {len(needed)} need description, {need_ex} also need examples")
  55. if remaining > 0:
  56. print(f" {remaining} more remaining after this batch")
  57. if __name__ == "__main__":
  58. main()