Refactor AI daily report pipeline

This commit is contained in:
Mimikko-zeus
2026-06-04 15:21:56 +08:00
parent 94e18ce22d
commit 5a98696255
64 changed files with 4778 additions and 1316 deletions

18
ai_daily_report/llm.py Normal file
View File

@@ -0,0 +1,18 @@
from __future__ import annotations
import json
import re
from typing import Any, Callable
LlmCall = Callable[[str], str]
def parse_json_object(text: str) -> dict[str, Any]:
text = re.sub(r"^```(?:json)?\s*\n?", "", text.strip())
text = re.sub(r"\n?```\s*$", "", text)
match = re.search(r"\{.*\}\s*$", text, re.S)
if not match:
raise ValueError("LLM output does not contain a JSON object")
return json.loads(match.group(0))