v1.2.0: 数据源完整编辑(模态框所有配置可改) + 定制监控类型(无权重,推送标准由大模型判断推送)
This commit is contained in:
@@ -6,6 +6,8 @@ API:采集 / LLM分析 / 汇总 / 画像维护 / 设置维护
|
||||
"""
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import json
|
||||
|
||||
from flask import Flask, render_template, request, jsonify, redirect, url_for
|
||||
|
||||
import requests
|
||||
@@ -113,12 +115,16 @@ def api_sources():
|
||||
action = data.get("action")
|
||||
if action == "add":
|
||||
sid = db.add_source(data.get("name", ""), data.get("type", ""), data.get("url", ""),
|
||||
data.get("description", ""), float(data.get("weight", 1.0)))
|
||||
data.get("description", ""), float(data.get("weight", 1.0)),
|
||||
kind=data.get("kind", "normal"),
|
||||
monitor_standard=data.get("monitor_standard", ""))
|
||||
return jsonify({"ok": True, "id": sid})
|
||||
if action == "update":
|
||||
db.update_source(data["id"], name=data.get("name"), type=data.get("type"),
|
||||
url=data.get("url"), description=data.get("description"),
|
||||
weight=float(data.get("weight", 1.0)),
|
||||
kind=data.get("kind", "normal"),
|
||||
monitor_standard=data.get("monitor_standard", ""),
|
||||
enabled=1 if data.get("enabled") else 0)
|
||||
return jsonify({"ok": True})
|
||||
if action == "delete":
|
||||
@@ -128,6 +134,27 @@ def api_sources():
|
||||
s = db.get_source(data["id"])
|
||||
db.update_source(data["id"], enabled=0 if s["enabled"] else 1)
|
||||
return jsonify({"ok": True})
|
||||
if action == "test_standard":
|
||||
# 定制监控:用大模型测试「推送标准」是否好使(给一段示例内容看判不判得出)
|
||||
standard = (data.get("monitor_standard") or "").strip()
|
||||
sample = (data.get("sample") or "").strip()
|
||||
if not standard:
|
||||
return jsonify({"ok": False, "error": "请先填写推送标准"})
|
||||
prompt = (
|
||||
"你是一位资讯监控专员。用户配置了一个定制监控数据源,并设定了「推送标准」。\n"
|
||||
f"【推送标准】\n{standard}\n\n"
|
||||
f"【待判断内容】\n{sample or '(未提供示例内容,请自行用一句典型的需推送场景作答,说明是否达到标准)'}\n\n"
|
||||
"请判断该内容是否达到推送标准。只输出一个 JSON 对象(不要任何其他文字):\n"
|
||||
'{"meets_standard": true或false, "reason": "判断理由(40字内中文)"}'
|
||||
)
|
||||
try:
|
||||
content, _name = analysis._llm_chat(prompt)
|
||||
parsed = json.loads(content)
|
||||
return jsonify({"ok": True,
|
||||
"meets": bool(parsed.get("meets_standard")),
|
||||
"reason": parsed.get("reason", "")})
|
||||
except Exception as e:
|
||||
return jsonify({"ok": False, "error": str(e)})
|
||||
return jsonify({"ok": False, "error": "unknown action"})
|
||||
|
||||
|
||||
@@ -282,7 +309,9 @@ def main():
|
||||
# 首次初始化:写入默认数据源 / 兴趣画像 / 默认设置 / 模拟数据
|
||||
if db.get_setting("initialized") != 1:
|
||||
for s in config.DEFAULT_SOURCES:
|
||||
db.add_source(s["name"], s["type"], s["url"], s["description"], s["weight"])
|
||||
db.add_source(s["name"], s["type"], s["url"], s["description"], s["weight"],
|
||||
kind=s.get("kind", "normal"),
|
||||
monitor_standard=s.get("monitor_standard", ""))
|
||||
for kw, w in config.DEFAULT_KEYWORDS:
|
||||
db.add_keyword(kw, w)
|
||||
for d, w in config.DEFAULT_DOMAINS:
|
||||
|
||||
Reference in New Issue
Block a user