配置全面迁移数据库: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:
+59
-21
@@ -26,7 +26,34 @@ logging.basicConfig(
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
DOMAINS = ["远程工作", "AI工具", "可持续生活", "知识管理", "数字生活", "科技人文"]
|
||||
DEFAULT_DOMAINS = ["远程工作", "AI工具", "可持续生活", "知识管理", "数字生活", "科技人文"]
|
||||
_cached_domains = None
|
||||
|
||||
def _load_domains():
|
||||
global _cached_domains
|
||||
if _cached_domains is not None:
|
||||
return _cached_domains
|
||||
try:
|
||||
from app.core.prompt_loader import _get_session
|
||||
from app.models import SystemConfig
|
||||
session = _get_session()
|
||||
try:
|
||||
sc = session.query(SystemConfig).filter(SystemConfig.key == "trend_domains").first()
|
||||
if sc and sc.value:
|
||||
parsed = json.loads(sc.value)
|
||||
if isinstance(parsed, list) and parsed:
|
||||
_cached_domains = parsed
|
||||
logger.info(f"从DB加载 {len(_cached_domains)} 个trend_domains")
|
||||
return _cached_domains
|
||||
finally:
|
||||
session.close()
|
||||
except Exception as e:
|
||||
logger.warning(f"从DB加载 trend_domains 失败: {e}")
|
||||
_cached_domains = DEFAULT_DOMAINS
|
||||
return _cached_domains
|
||||
|
||||
def get_domains():
|
||||
return _load_domains()
|
||||
|
||||
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
|
||||
@@ -39,10 +66,35 @@ _KEYWORD_DOMAIN_MAP = [
|
||||
(r"科技|人文|教育|心理|哲学|社会学", "科技人文"),
|
||||
]
|
||||
|
||||
_cached_keyword_domain_map = None
|
||||
|
||||
def _load_keyword_domain_map():
|
||||
global _cached_keyword_domain_map
|
||||
if _cached_keyword_domain_map is not None:
|
||||
return _cached_keyword_domain_map
|
||||
|
||||
try:
|
||||
from app.core.prompt_loader import _get_session
|
||||
from app.models import KeywordDomainMap
|
||||
session = _get_session()
|
||||
try:
|
||||
rows = session.query(KeywordDomainMap).filter(KeywordDomainMap.is_active == True).order_by(KeywordDomainMap.sort_order).all()
|
||||
if rows:
|
||||
_cached_keyword_domain_map = [(r.pattern, r.domain) for r in rows]
|
||||
logger.info(f"从DB加载 {len(rows)} 条 keyword_domain_map 规则")
|
||||
return _cached_keyword_domain_map
|
||||
finally:
|
||||
session.close()
|
||||
except Exception as e:
|
||||
logger.warning(f"从DB加载 keyword_domain_map 失败: {e}")
|
||||
|
||||
_cached_keyword_domain_map = _KEYWORD_DOMAIN_MAP
|
||||
return _cached_keyword_domain_map
|
||||
|
||||
|
||||
def _guess_domain(topic: str, reason: str = "") -> str:
|
||||
text = (topic + " " + reason).lower()
|
||||
for pattern, domain in _KEYWORD_DOMAIN_MAP:
|
||||
for pattern, domain in _load_keyword_domain_map():
|
||||
if re.search(pattern, text, re.IGNORECASE):
|
||||
return domain
|
||||
return "科技人文"
|
||||
@@ -186,26 +238,12 @@ def fetch_baidu_hot() -> List[Dict]:
|
||||
|
||||
|
||||
def fetch_llm_trends() -> List[Dict]:
|
||||
prompt = f"""你是中文互联网趋势分析师。请列出今天(2026年5月)中文互联网上最值得创作的10个话题。
|
||||
|
||||
要求:
|
||||
1. 覆盖领域:{', '.join(DOMAINS)}
|
||||
2. 从真实用户角度出发
|
||||
3. 每个话题需包含:
|
||||
- "domain": 领域
|
||||
- "topic": 话题名称
|
||||
- "reason": 为什么现在讨论这个(1句话,有具体事件/数据支撑)
|
||||
- "hot_keywords": 3-5个搜索词(含1-2个长尾词)
|
||||
- "platform": 最适合分发的平台(知乎/小红书/微信/多平台)
|
||||
- "seo_angle": 从什么角度切入能获得搜索流量(1句话)
|
||||
- "engagement": 高/中/低
|
||||
|
||||
输出 JSON 数组:
|
||||
[{{"domain": "...", "topic": "...", "reason": "...", "hot_keywords": ["..."], "platform": "...", "seo_angle": "...", "engagement": "..."}}]
|
||||
|
||||
只输出 JSON,不要其他文字。"""
|
||||
try:
|
||||
resp = call_llm(prompt, temperature=0.4)
|
||||
from prompt_loader import get_prompt, get_prompt_params
|
||||
prompt = get_prompt("topics_trends", date=datetime.datetime.now().strftime("%Y年%m月%d"),
|
||||
domains=", ".join(get_domains()))
|
||||
params = get_prompt_params("topics_trends")
|
||||
resp = call_llm(prompt, temperature=params.get("temperature", 0.4), max_tokens=params.get("max_tokens", 2000))
|
||||
resp = resp.strip()
|
||||
if resp.startswith("```"):
|
||||
resp = resp.split("\n", 1)[1].rsplit("\n", 1)[0]
|
||||
|
||||
Reference in New Issue
Block a user