fix: route compliance to opencode-go, others to nvidia; skip status on force-pass
1. DB active provider switched to nvidia (stepfun-ai/step-3.5-flash) → trends/collector/writer 默认用 nvidia 2. compliance_optimizer.py 固定 provider='opencode-go' → 合规审查用 deepseek-v4-flash(更好的模型) 3. force_passed 的选题不再更新为 'ready'(待发布) → 只有真正修复通过才更新状态
This commit is contained in:
@@ -160,17 +160,15 @@ def polish_with_llm(html: str, platform: str, remaining_issues: Optional[List[Di
|
|||||||
"""用 LLM 优化文章内容,返回 (html, log_message_or_None)
|
"""用 LLM 优化文章内容,返回 (html, log_message_or_None)
|
||||||
如果指定 remaining_issues,则针对性修复合规问题
|
如果指定 remaining_issues,则针对性修复合规问题
|
||||||
LLM 失败时自动重试一次
|
LLM 失败时自动重试一次
|
||||||
|
固定使用 opencode-go (deepseek-v4-flash) — 审查用更好的模型
|
||||||
"""
|
"""
|
||||||
if not HAVE_LLM:
|
if not HAVE_LLM:
|
||||||
return html, None
|
return html, None
|
||||||
llm_cfg = get_llm_config()
|
|
||||||
for attempt in range(2):
|
for attempt in range(2):
|
||||||
try:
|
try:
|
||||||
model = llm_cfg.get('model') if llm_cfg else None
|
temperature = 0.5
|
||||||
temperature = llm_cfg.get('temperature', 0.5) if llm_cfg else 0.5
|
max_tokens = 4000
|
||||||
max_tokens = llm_cfg.get('max_tokens', 4000) if llm_cfg else 4000
|
system_prompt = "你是一个专业的内容合规与优化助手,擅长在保持文章质量和可读性的前提下修复合规问题。"
|
||||||
system_prompt = llm_cfg.get('system_prompt') if llm_cfg else "你是一个专业的内容合规与优化助手,擅长在保持文章质量和可读性的前提下修复合规问题。"
|
|
||||||
|
|
||||||
if remaining_issues:
|
if remaining_issues:
|
||||||
issues_desc = "\n".join(
|
issues_desc = "\n".join(
|
||||||
f"- [{i['type']}] {i.get('category','')}: {i.get('detail','')}"
|
f"- [{i['type']}] {i.get('category','')}: {i.get('detail','')}"
|
||||||
@@ -179,7 +177,7 @@ def polish_with_llm(html: str, platform: str, remaining_issues: Optional[List[Di
|
|||||||
prompt = get_prompt("compliance_fix", issues_desc=issues_desc, html=html)
|
prompt = get_prompt("compliance_fix", issues_desc=issues_desc, html=html)
|
||||||
else:
|
else:
|
||||||
prompt = get_prompt("compliance_polish", html=html)
|
prompt = get_prompt("compliance_polish", html=html)
|
||||||
polished = call_llm(prompt, model=model, temperature=temperature, max_tokens=max_tokens, system_prompt=system_prompt)
|
polished = call_llm(prompt, provider="opencode-go", temperature=temperature, max_tokens=max_tokens, system_prompt=system_prompt)
|
||||||
polished = clean_html_content(polished)
|
polished = clean_html_content(polished)
|
||||||
polished = strip_ai_preface(polished)
|
polished = strip_ai_preface(polished)
|
||||||
polished = strip_thinking_html(polished)
|
polished = strip_thinking_html(polished)
|
||||||
@@ -226,11 +224,7 @@ def _load_platform_configs() -> Dict[str, Dict]:
|
|||||||
|
|
||||||
def main(topic_ids: List[str] = None):
|
def main(topic_ids: List[str] = None):
|
||||||
logger.info("=== 合规审查与优化开始 ===")
|
logger.info("=== 合规审查与优化开始 ===")
|
||||||
llm_cfg = get_llm_config()
|
logger.info("LLM 配置: opencode-go (model=deepseek-v4-flash) — 固定用于合规审查")
|
||||||
if llm_cfg:
|
|
||||||
logger.info(f"LLM 配置: {llm_cfg['name']} (model={llm_cfg['model']})")
|
|
||||||
else:
|
|
||||||
logger.info("LLM 配置: 使用环境变量默认值")
|
|
||||||
|
|
||||||
platform_configs = _load_platform_configs()
|
platform_configs = _load_platform_configs()
|
||||||
logger.info(f"已加载 {len(platform_configs)} 个平台配置")
|
logger.info(f"已加载 {len(platform_configs)} 个平台配置")
|
||||||
@@ -251,6 +245,7 @@ def main(topic_ids: List[str] = None):
|
|||||||
|
|
||||||
topic_map = load_topic_map()
|
topic_map = load_topic_map()
|
||||||
results = []
|
results = []
|
||||||
|
force_passed_topics = set()
|
||||||
|
|
||||||
for html, platform_dir, topic_id in articles:
|
for html, platform_dir, topic_id in articles:
|
||||||
topic_data = topic_map.get(topic_id)
|
topic_data = topic_map.get(topic_id)
|
||||||
@@ -294,6 +289,7 @@ def main(topic_ids: List[str] = None):
|
|||||||
else:
|
else:
|
||||||
save_article(topic_id, platform_dir, current_html)
|
save_article(topic_id, platform_dir, current_html)
|
||||||
logger.warning(f"⚠️ {label} 仍有 {len(current_issues)} 个问题未修复,已强制通过(当前分 {current_score})")
|
logger.warning(f"⚠️ {label} 仍有 {len(current_issues)} 个问题未修复,已强制通过(当前分 {current_score})")
|
||||||
|
force_passed_topics.add(topic_id)
|
||||||
results.append(OptimizationResult(
|
results.append(OptimizationResult(
|
||||||
file=f"db:{platform_dir}_{topic_id}",
|
file=f"db:{platform_dir}_{topic_id}",
|
||||||
platform=platform_dir,
|
platform=platform_dir,
|
||||||
@@ -302,7 +298,7 @@ def main(topic_ids: List[str] = None):
|
|||||||
original_issues=len(issues),
|
original_issues=len(issues),
|
||||||
fixed_issues=len(issues) - len(current_issues),
|
fixed_issues=len(issues) - len(current_issues),
|
||||||
final_score=current_score,
|
final_score=current_score,
|
||||||
status="passed"
|
status="force_passed"
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
results.append(OptimizationResult(
|
results.append(OptimizationResult(
|
||||||
@@ -324,6 +320,9 @@ def main(topic_ids: List[str] = None):
|
|||||||
passed_scores[res.topic_id].append(res.final_score)
|
passed_scores[res.topic_id].append(res.final_score)
|
||||||
|
|
||||||
for tid, scores in passed_scores.items():
|
for tid, scores in passed_scores.items():
|
||||||
|
if tid in force_passed_topics:
|
||||||
|
logger.warning(f"选题 {tid} 仍有未修复问题,跳过状态更新(保留当前状态)")
|
||||||
|
continue
|
||||||
avg_score = sum(scores) // len(scores)
|
avg_score = sum(scores) // len(scores)
|
||||||
update_topic_status(tid, 'ready', compliance_score=avg_score, reviewed_at=datetime.datetime.now())
|
update_topic_status(tid, 'ready', compliance_score=avg_score, reviewed_at=datetime.datetime.now())
|
||||||
logger.info(f"选题 {tid} 状态 → ready(待发布), 合规分={avg_score}")
|
logger.info(f"选题 {tid} 状态 → ready(待发布), 合规分={avg_score}")
|
||||||
@@ -342,8 +341,8 @@ def main(topic_ids: List[str] = None):
|
|||||||
with open(report_file, 'w', encoding='utf-8') as f:
|
with open(report_file, 'w', encoding='utf-8') as f:
|
||||||
json.dump(report, f, ensure_ascii=False, indent=2)
|
json.dump(report, f, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
logger.info(f"✅ 合规审查完成: {len(results)} 篇文章全部通过")
|
logger.info(f"✅ 合规审查完成: {len(results)} 篇文章, 其中 {len([r for r in results if r.status=='force_passed'])} 篇强制通过")
|
||||||
print(f"OPTIMIZATION_COMPLETE: {len(results)} articles, all passed")
|
print(f"OPTIMIZATION_COMPLETE: {len(results)} articles, {len(force_passed_topics)} topics skipped status update")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user