Refactor AI daily report pipeline
This commit is contained in:
18
ai_daily_report/llm.py
Normal file
18
ai_daily_report/llm.py
Normal 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))
|
||||
|
||||
Reference in New Issue
Block a user