配置全面迁移数据库: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:
Yuzhiran Dev
2026-05-22 11:18:23 +08:00
parent a8e0a76e07
commit 1855f190f5
31 changed files with 2927 additions and 1127 deletions
+57 -37
View File
@@ -39,7 +39,48 @@ logging.basicConfig(
logging.StreamHandler()
]
)
logger = logging.getLogger(__name__)
DEFAULT_CHINA_PAINS = {
"循环消费": "以旧换新流程繁琐、二手商品信任缺失、租赁市场不规范",
"低碳出行": "新能源车充电设施不足、城市规划不支持骑行、通勤距离长",
"干净饮食": "有机食品价格高、真伪难辨、外卖为主的生活方式难以改变",
"零浪费生活": "环保产品溢价高、可持续选择不便、漂绿营销难以分辨",
"绿色家电与节能": "绿色家电初期投入高、节能效果难量化、老旧小区改造难",
"碳普惠": "碳账户普及率低、减排量兑换吸引力不足、公众认知有限",
"环保科技产品": "绿色产品溢价68%难以承受、缺乏统一认证标准、担心漂绿",
"AI与效率": "AI工具选择困难、数据隐私担忧、学习成本高、实际效果难验证"
}
_cached_china_pains = None
def _load_china_pains():
global _cached_china_pains
if _cached_china_pains is not None:
return _cached_china_pains
try:
from app.database import SessionLocal
from app.models import CollectorCategory
db = SessionLocal()
try:
cats = db.query(CollectorCategory).filter(
CollectorCategory.is_active == True,
CollectorCategory.pain_template.isnot(None),
CollectorCategory.pain_template != ""
).all()
if cats:
_cached_china_pains = {c.name: c.pain_template for c in cats}
logger.info(f"从DB加载 {len(_cached_china_pains)} 个类别的pain_template")
return _cached_china_pains
finally:
db.close()
except Exception as e:
logger.warning(f"从DB加载 china_pains 失败: {e}")
_cached_china_pains = DEFAULT_CHINA_PAINS
return _cached_china_pains
def _get_china_pain(category: str) -> str:
pains = _load_china_pains()
return pains.get(category, "中国相关数据不足,需本土化验证")
@dataclass
@@ -322,14 +363,8 @@ class SustainabilityCollector:
if not content:
content = title
# 关键词匹配(来源特定或全局)
keywords = source_keywords if source_keywords else [
'sustainable', 'green', 'eco', 'circular', 'climate', 'carbon',
'zero waste', 'renewable', 'recycle', '环保', '可持续', '碳中和',
'循环经济', '零浪费', '低碳', '生态'
]
search_text = (title + content).lower()
keywords = source_keywords if source_keywords else _load_rss_keywords()
if any(keyword.lower() in search_text for keyword in keywords):
articles.append({
'title': title,
@@ -445,6 +480,8 @@ class SustainabilityCollector:
logger.warning("LLM不可用,跳过AI选题生成")
return []
from prompt_loader import get_prompt, get_prompt_params
existing = self._get_existing_titles()
existing_hint = ""
if existing:
@@ -461,28 +498,21 @@ class SustainabilityCollector:
if cases:
case_lines = [f"- {c.title[:40]}({c.category})" for c in cases[:5]]
data_section += "\n采集案例:\n" + "\n".join(case_lines) + "\n"
if not data_section:
data_section = "(当前无实时采集数据,请基于你对中文互联网趋势的了解直接生成)"
trend_context = self._get_trend_context()
prompt = f"""你是一个内容策略师。基于以下信息,为「{target_category}」类别生成一个高质量选题。
{data_section if data_section else "(当前无实时采集数据,请基于你对中文互联网趋势的了解直接生成)"}
{existing_hint}
{trend_context}
输出一个选题,格式JSON
{{{{
"title": "标题(20字内,含核心关键词)",
"core_concept": "核心观点(一句话)",
"audience_pain": "受众痛点",
"unique_angle": "差异化切入点",
"format": "内容形式(趋势洞察/实操指南/对比分析/案例解读)"
}}}}
只输出JSON。"""
prompt = get_prompt("topic_generate",
target_category=target_category,
data_section=data_section,
existing_hint=existing_hint,
trend_context=trend_context,
)
try:
resp = call_llm(prompt, temperature=0.7)
params = get_prompt_params("topic_generate")
resp = call_llm(prompt, temperature=params.get("temperature", 0.6), max_tokens=params.get("max_tokens", 2000))
resp = resp.strip()
if resp.startswith("```"):
resp = resp.split("\n", 1)[1].rsplit("\n", 1)[0]
@@ -570,18 +600,8 @@ class SustainabilityCollector:
# 实际应用中可用AI提取,这里用前100字符
core_idea = content[:200] if len(content) > 200 else content
# 生成中国痛点(基于类别模板)
china_pains = {
"循环消费": "以旧换新流程繁琐、二手商品信任缺失、租赁市场不规范",
"低碳出行": "新能源车充电设施不足、城市规划不支持骑行、通勤距离长",
"干净饮食": "有机食品价格高、真伪难辨、外卖为主的生活方式难以改变",
"零浪费生活": "环保产品溢价高、可持续选择不便、漂绿营销难以分辨",
"绿色家电与节能": "绿色家电初期投入高、节能效果难量化、老旧小区改造难",
"碳普惠": "碳账户普及率低、减排量兑换吸引力不足、公众认知有限",
"环保科技产品": "绿色产品溢价68%难以承受、缺乏统一认证标准、担心漂绿",
"AI与效率": "AI工具选择困难、数据隐私担忧、学习成本高、实际效果难验证"
}
china_pain = china_pains.get(category, "中国相关数据不足,需本土化验证")
# 生成中国痛点(基于类别模板,从DB读取pain_template)
china_pain = _get_china_pain(category)
# 生成案例
case = SustainabilityCase(