配置全面迁移数据库: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:
@@ -7,15 +7,13 @@
|
||||
import re
|
||||
from typing import Dict, List, Tuple
|
||||
|
||||
# 敏感词库(示例,需要持续更新)
|
||||
SENSITIVE_WORDS = {
|
||||
"政治敏感": ["国家主席", "政治局", "常委", "军委", "统战部", "颠覆国家", "分裂主义", "台独", "疆独", "藏独"],
|
||||
"违禁内容": ["赌博", "毒品", "迷药", "枪支", "炸药", "色情", "低俗", "反动", "邪教"],
|
||||
"不实信息": [" guaranteed 赚钱", "一夜暴富", "100%有效", "包治百病", "绝对正确"],
|
||||
"领导人相关": ["主席", "总理", "总书记", "国家领导人"] # 需上下文判断
|
||||
"领导人相关": ["主席", "总理", "总书记", "国家领导人"]
|
||||
}
|
||||
|
||||
# 平台规则限制
|
||||
PLATFORM_RULES = {
|
||||
"zhihu": {
|
||||
"max_title_len": 100,
|
||||
@@ -37,6 +35,70 @@ PLATFORM_RULES = {
|
||||
}
|
||||
}
|
||||
|
||||
_cached_sensitive_words = None
|
||||
_cached_platform_rules = None
|
||||
|
||||
def _load_sensitive_words():
|
||||
global _cached_sensitive_words
|
||||
if _cached_sensitive_words is not None:
|
||||
return _cached_sensitive_words
|
||||
|
||||
try:
|
||||
from app.core.prompt_loader import _get_session
|
||||
from app.models import SensitiveWord
|
||||
session = _get_session()
|
||||
try:
|
||||
rows = session.query(SensitiveWord).filter(SensitiveWord.is_active == True).all()
|
||||
if rows:
|
||||
result = {}
|
||||
for r in rows:
|
||||
cat = r.category or "general"
|
||||
if cat not in result:
|
||||
result[cat] = []
|
||||
result[cat].append(r.word)
|
||||
_cached_sensitive_words = result
|
||||
return _cached_sensitive_words
|
||||
finally:
|
||||
session.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
_cached_sensitive_words = SENSITIVE_WORDS
|
||||
return _cached_sensitive_words
|
||||
|
||||
|
||||
def _load_platform_rules():
|
||||
global _cached_platform_rules
|
||||
if _cached_platform_rules is not None:
|
||||
return _cached_platform_rules
|
||||
|
||||
try:
|
||||
from app.core.prompt_loader import _get_session
|
||||
from app.models import PlatformConfig
|
||||
import json
|
||||
session = _get_session()
|
||||
try:
|
||||
rows = session.query(PlatformConfig).all()
|
||||
if rows:
|
||||
result = {}
|
||||
for r in rows:
|
||||
try:
|
||||
cfg = json.loads(r.config_data) if r.config_data else {}
|
||||
except:
|
||||
cfg = {}
|
||||
if cfg:
|
||||
result[r.platform] = cfg
|
||||
if result:
|
||||
_cached_platform_rules = result
|
||||
return _cached_platform_rules
|
||||
finally:
|
||||
session.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
_cached_platform_rules = PLATFORM_RULES
|
||||
return _cached_platform_rules
|
||||
|
||||
class ComplianceChecker:
|
||||
"""合规审查器"""
|
||||
|
||||
@@ -90,7 +152,8 @@ class ComplianceChecker:
|
||||
|
||||
def _check_sensitive_words(self, text: str):
|
||||
"""检查敏感词"""
|
||||
for category, words in SENSITIVE_WORDS.items():
|
||||
words_map = _load_sensitive_words()
|
||||
for category, words in words_map.items():
|
||||
for word in words:
|
||||
if word in text:
|
||||
self.issues.append({
|
||||
@@ -102,7 +165,8 @@ class ComplianceChecker:
|
||||
|
||||
def _check_platform_rules(self, text: str, platform: str):
|
||||
"""检查平台特定规则"""
|
||||
rules = PLATFORM_RULES.get(platform, {})
|
||||
rules_map = _load_platform_rules()
|
||||
rules = rules_map.get(platform, {})
|
||||
|
||||
# 标题长度(从HTML中提取)
|
||||
max_title_len = self._get_platform_rule('max_title_len', rules.get("max_title_len"))
|
||||
@@ -244,7 +308,7 @@ class ComplianceChecker:
|
||||
"""检查文章最小字数(去除HTML标签)"""
|
||||
plain = re.sub(r'<[^>]+>', '', text)
|
||||
word_count = len(plain.strip())
|
||||
min_words = self._get_platform_rule('min_word_count', PLATFORM_RULES.get(platform, {}).get("min_word_count", 1000))
|
||||
min_words = self._get_platform_rule('min_word_count', 1000)
|
||||
if word_count < min_words:
|
||||
self.issues.append({
|
||||
"type": "内容完整度",
|
||||
|
||||
Reference in New Issue
Block a user