配置全面迁移数据库:PromptConfig、TaskConfig动态调度、敏感词/清洗规则/趋势映射/平台标签/痛点模板全部可编辑
- 新增 PromptConfig 模型 + API,支持提示词在线编辑(16条默认) - 调度器动态读取 TaskConfig.schedule,admin 可调执行时间 - 新增 KeywordDomainMap、SensitiveWord、ContentCleanRule、TrendFieldMapping 表 - DOMAINS、TREND_DOMAIN_MAP、PLATFORM_TAGS、china_pains、RSS关键词、priority_weights 全部迁移到 DB - tasks.html 重构:卡片网格+配置/产出/历史/提示词四个Tab,折叠显示 - 清理冗余代码:DEFAULT_PROMPTS死代码、collector.py unreachable代码、compliance_checker bug - strip_thinking_html 改用 DB 规则优先
This commit is contained in:
@@ -22,7 +22,7 @@ TODAY = __import__('datetime').datetime.now().strftime("%Y-%m-%d")
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
TREND_DOMAIN_MAP = {
|
||||
DEFAULT_TREND_DOMAIN_MAP = {
|
||||
"远程工作": "未来工作方式",
|
||||
"AI工具": "AI与效率",
|
||||
"可持续生活": "可持续生活系统",
|
||||
@@ -37,11 +37,38 @@ TREND_DOMAIN_MAP = {
|
||||
"家庭教育": "科技人文交叉",
|
||||
}
|
||||
|
||||
_cached_trend_domain_map = None
|
||||
|
||||
def _load_trend_domain_map():
|
||||
global _cached_trend_domain_map
|
||||
if _cached_trend_domain_map is not None:
|
||||
return _cached_trend_domain_map
|
||||
try:
|
||||
from app.core.prompt_loader import _get_session
|
||||
from app.models import TrendFieldMapping
|
||||
session = _get_session()
|
||||
try:
|
||||
rows = session.query(TrendFieldMapping).filter(TrendFieldMapping.is_active == True).order_by(TrendFieldMapping.sort_order).all()
|
||||
if rows:
|
||||
_cached_trend_domain_map = {r.trend_keyword: r.field_name for r in rows}
|
||||
logger.info(f"从DB加载 {len(_cached_trend_domain_map)} 条 trend_domain_map")
|
||||
return _cached_trend_domain_map
|
||||
finally:
|
||||
session.close()
|
||||
except Exception as e:
|
||||
logger.warning(f"从DB加载 trend_domain_map 失败: {e}")
|
||||
_cached_trend_domain_map = DEFAULT_TREND_DOMAIN_MAP
|
||||
return _cached_trend_domain_map
|
||||
|
||||
def get_trend_domain_map():
|
||||
return _load_trend_domain_map()
|
||||
|
||||
def _topic_trend_score(topic: Dict, trend: Dict) -> float:
|
||||
field = (topic.get("field") or "").lower()
|
||||
title = (topic.get("title") or "").lower()
|
||||
core = (topic.get("core_concept") or "").lower()
|
||||
trend_domain = TREND_DOMAIN_MAP.get(trend.get("domain", ""), "")
|
||||
trend_domain_map = get_trend_domain_map()
|
||||
trend_domain = trend_domain_map.get(trend.get("domain", ""), "")
|
||||
keywords = [trend.get("topic", "")] + trend.get("hot_keywords", [])
|
||||
score = 0.0
|
||||
if trend_domain and trend_domain in field:
|
||||
|
||||
Reference in New Issue
Block a user