운영 지표와 지원 요청 저장소 추가
This commit is contained in:
parent
50fa4ad432
commit
e7ebb38177
20 changed files with 3038 additions and 39 deletions
46
scripts/report-ai-usage.py
Normal file
46
scripts/report-ai-usage.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env python
|
||||
"""Build a deterministic model-cost report from an admin usage JSON export."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
def _repo_root() -> Path:
|
||||
return Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def _load_builder():
|
||||
api_root = _repo_root() / "apps" / "api"
|
||||
sys.path.insert(0, str(api_root))
|
||||
from app.services.usage_report import build_model_cost_report
|
||||
|
||||
return build_model_cost_report
|
||||
|
||||
|
||||
def parse_args() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Create a model/provider AI usage cost report from AdminUsageResponse JSON.",
|
||||
)
|
||||
parser.add_argument("--input", required=True, help="Path to AdminUsageResponse JSON.")
|
||||
parser.add_argument("--output", help="Optional output JSON path. Defaults to stdout.")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main() -> int:
|
||||
args = parse_args()
|
||||
usage = json.loads(Path(args.input).read_text(encoding="utf-8"))
|
||||
report = _load_builder()(usage)
|
||||
payload = json.dumps(report, ensure_ascii=False, indent=2, sort_keys=True) + "\n"
|
||||
if args.output:
|
||||
Path(args.output).write_text(payload, encoding="utf-8")
|
||||
else:
|
||||
sys.stdout.write(payload)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue