#!/usr/bin/env python3 # -*- coding: utf-8 -*- """作业 6 · 验收:拉 Langfuse + GPU,生成报告并推送钉钉。""" from __future__ import annotations import sys import _bootstrap # noqa: F401 from 作业6_weekly_report import ( fetch_gpu_weekly, fetch_langfuse_tokens, qwen_weekly_report, run_weekly, send_dingtalk_markdown, build_facts, ) import _config as C def main() -> int: token_stats = fetch_langfuse_tokens(days=int(C.HOMEWORK6_DAYS)) if not token_stats.get("daily"): print("[FAIL] Langfuse 无 daily 数据") return 1 gpu_stats = fetch_gpu_weekly(days=int(C.HOMEWORK6_DAYS)) if not gpu_stats.get("current"): print("[FAIL] GPU 采样失败") return 1 facts = build_facts(token_stats, gpu_stats) report = qwen_weekly_report(facts) if len(report) < 100: print("[FAIL] Qwen 周报过短") return 1 if "Token" not in report and "token" not in report.lower(): print("[WARN] 周报可能未提及 Token") ding = send_dingtalk_markdown(C.HOMEWORK6_REPORT_TITLE, report) if ding.get("errcode") != 0: print("[FAIL] 钉钉推送失败", ding) return 1 print("[PASS] Langfuse=%s tokens, GPU avg=%s%%, 钉钉 errcode=0" % ( token_stats.get("total_tokens"), gpu_stats.get("avg_utilization_pct"), )) return 0 if __name__ == "__main__": sys.exit(main())