mirror of
https://github.com/stardrophere/InsightRadar.git
synced 2026-06-06 00:00:05 +08:00
backend 去ai化
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
# app/services/summary_service.py
|
||||
"""
|
||||
摘要服务:调用 LLM 生成统一标题、综合摘要、话题标签
|
||||
定时任务:对热度达标且未摘要的事件批量处理
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
from datetime import timedelta
|
||||
@@ -26,12 +21,16 @@ from app.prompts.summary_prompts import (
|
||||
)
|
||||
from app.services.fetcher_service import embedder_model
|
||||
|
||||
# AI辅助生成:deepseek-v3-2,2026年3月20日
|
||||
|
||||
HOT_SCORE_THRESHOLD = int(os.getenv("HOT_SCORE_THRESHOLD", 3))
|
||||
TOPIC_TAG_MIN_HOT_SCORE = int(os.getenv("TOPIC_TAG_MIN_HOT_SCORE", HOT_SCORE_THRESHOLD))
|
||||
TOPIC_SIMILARITY_THRESHOLD = float(os.getenv("TOPIC_SIMILARITY_THRESHOLD", 0.82))
|
||||
TOPIC_TAG_MAX_COUNT = int(os.getenv("TOPIC_TAG_MAX_COUNT", 8))
|
||||
AI_API_KEY = os.getenv("AI_API_KEY", "")
|
||||
|
||||
# AI生成结束
|
||||
|
||||
|
||||
deepseek_client = AsyncOpenAI(
|
||||
api_key=AI_API_KEY,
|
||||
@@ -184,7 +183,6 @@ async def generate_unified_summaries():
|
||||
"""定时任务:对热度达标且未摘要的事件刷新标题、摘要、标签"""
|
||||
print(f"[{utcnow()}] Start unified summary generation task...")
|
||||
|
||||
# 先提取需要处理的事件 ID,尽早释放 session,不长期占用 db session
|
||||
with SessionLocal() as db:
|
||||
recent_threshold = utcnow() - timedelta(days=3)
|
||||
events = db.query(UnifiedEvent).filter(
|
||||
@@ -197,11 +195,9 @@ async def generate_unified_summaries():
|
||||
print("No events require summary update in this round.")
|
||||
return
|
||||
|
||||
# 复制出需要的信息,脱离 session
|
||||
event_ids = [e.id for e in events]
|
||||
event_hot_scores = {e.id: e.hot_score for e in events}
|
||||
|
||||
# 外层循环:针对每个 event_id 开启一个极短生命周期的 session 获取依赖数据
|
||||
for event_id in event_ids:
|
||||
platform_dict: dict[str, set[str]] = {}
|
||||
with SessionLocal() as db:
|
||||
|
||||
Reference in New Issue
Block a user