feat: 日报事件多新闻源入库(news_event.sources 列)
- ExtractedEvent 增加 sources 字段(主源居首去重,旧产物兜底 [source_id]) - extract_event(_async) 增加 sources 参数;run_event_extraction 读取 deduped uniques 的 sources 透传 - reporter _load_events_from_dir 读取 sources → EventRow.sources - news_event 建表加 sources TEXT 列;init_schema 幂等迁移旧表(捕获 Duplicate column);save_report INSERT 写 JSON 多源 - 新增测试:ExtractedEvent/EventRow.sources 兜底与保序、_load_events_from_dir 多源
This commit is contained in:
@@ -109,6 +109,21 @@ def _load_article(p: Path) -> Article | None:
|
||||
return None
|
||||
|
||||
|
||||
def _load_sources(p: Path) -> list[str] | None:
|
||||
"""从输入 JSON 读取 sources 多源字段(deduped uniques 才有);无则返回 None。
|
||||
|
||||
None 表示无多源记录,由 extract_event 兜底为 [source_id]。
|
||||
"""
|
||||
try:
|
||||
data = json.loads(p.read_text(encoding="utf-8"))
|
||||
srcs = data.get("sources")
|
||||
if isinstance(srcs, list) and srcs:
|
||||
return [s for s in srcs if s]
|
||||
except (json.JSONDecodeError, OSError):
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
async def _run(args: argparse.Namespace) -> int:
|
||||
load_dotenv() # 读 .env 到 os.environ
|
||||
# scene=event_extraction: 读取 configs/llm_models.yaml 场景 1 配置,未配置字段回退 .env
|
||||
@@ -173,6 +188,7 @@ async def _run(args: argparse.Namespace) -> int:
|
||||
article = _load_article(fp)
|
||||
if article is None:
|
||||
return fp, None, "无法解析输入"
|
||||
sources = _load_sources(fp) # 多源记录(去重层),无则 None
|
||||
try:
|
||||
event = await extract_event_async(
|
||||
client=client,
|
||||
@@ -180,6 +196,7 @@ async def _run(args: argparse.Namespace) -> int:
|
||||
article=article,
|
||||
template=template,
|
||||
max_attempts=args.max_attempts,
|
||||
sources=sources,
|
||||
semaphore=semaphore,
|
||||
)
|
||||
return fp, event, None
|
||||
|
||||
Reference in New Issue
Block a user