2 Commits
7 changed files with 36 additions and 18 deletions
+1
View File
@@ -52,6 +52,7 @@ DEFAULT_CONFIG = {
], ensure_ascii=False),
"footer_text": "NBA球迷大全 · 数据为模拟演示数据(2025-26 赛季) · LLM: DeepSeek · 向量: Chroma + bge-large-zh",
"admin_password": "admin123",
"entity_mark_mode": "first", # 实体标记:first=只标记首次出现 / all=全部标记
}
SEARCHABLE = { # 每个表可搜索的 TEXT 字段
+2 -1
View File
@@ -78,7 +78,8 @@ def api_chat():
game_refs = [it for s in sources
if s.get("tool") in ("search_games", "get_game_detail")
for it in s.get("items", [])]
spans, cards = entity_linker.link_entities(reply, game_refs=game_refs)
mark_mode = admin_mod.get_config().get("entity_mark_mode", "first")
spans, cards = entity_linker.link_entities(reply, game_refs=game_refs, mark_mode=mark_mode)
return jsonify({"reply": reply, "sources": sources, "used_tools": used_tools,
"news_refs": news_refs, "entities": spans, "cards": cards})
except Exception as e:
+11 -1
View File
@@ -164,13 +164,23 @@ def _match_games(text, game_refs):
return cards
def link_entities(text, game_refs=None):
def link_entities(text, game_refs=None, mark_mode="first"):
"""主入口:扫描回答文本。
返回 (spans, cards)
spans: 实体命中区间(前端高亮标记用),按 start 升序、互不重叠
mark_mode="first" 时同一实体(type,id)只保留首次出现;"all" 时全部标记
cards: 快速查看卡片数据(每类限量,避免刷屏)
"""
spans = _find_spans(text or "")
if mark_mode == "first":
seen, kept = set(), []
for sp in spans: # spans 已按 start 升序 → 保留首次
key = (sp["type"], sp["id"])
if key in seen:
continue
seen.add(key)
kept.append(sp)
spans = kept
cards = []
seen_cards = set()
for sp in spans:
+5
View File
@@ -159,6 +159,11 @@ td.num { text-align:center; }
</div>
<div class="row2">
<div><label>管理员密码(留空则不修改)</label><input type="password" id="cfg-admin_password" placeholder="••••••"></div>
<div><label>实体标记模式</label><select id="cfg-entity_mark_mode">
<option value="first">只标记首次出现(推荐)</option>
<option value="all">全部标记</option>
</select>
<div class="tip">对话回答中球队/球员/人物等特殊标记策略</div></div>
</div>
<div class="form-actions">
<button class="btn" id="cfg-save">💾 保存配置</button>
+2
View File
@@ -207,6 +207,7 @@ async function loadConfig() {
$("#cfg-welcome_hint").value = d.welcome_hint || "";
$("#cfg-footer_text").value = d.footer_text || "";
$("#cfg-admin_password").value = "";
$("#cfg-entity_mark_mode").value = d.entity_mark_mode === "all" ? "all" : "first";
try { $("#cfg-suggestions").value = JSON.parse(d.suggestions || "[]").join("\n"); }
catch (e) { $("#cfg-suggestions").value = ""; }
$("#cfg-msg").textContent = "";
@@ -222,6 +223,7 @@ $("#cfg-save").addEventListener("click", async () => {
};
const pw = $("#cfg-admin_password").value;
if (pw) payload.admin_password = pw;
payload.entity_mark_mode = $("#cfg-entity_mark_mode").value;
try {
await api("/api/admin/config", { method: "PUT", body: JSON.stringify(payload) });
$("#cfg-msg").textContent = "✅ 保存成功,前台刷新后生效";
-1
View File
@@ -25,7 +25,6 @@
<button class="tab" data-view="persons">👥 人物</button>
<button class="tab" data-view="standings">🏆 排名</button>
</nav>
<a class="admin-link" href="/admin" title="管理后台">⚙️</a>
</header>
<main>
+15 -15
View File
@@ -30,32 +30,32 @@ main { flex: 1; width: 100%; max-width: 1200px; margin: 0 auto; padding: 20px 16
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--card); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 19px; flex-shrink: 0; }
.msg.user .avatar { background: linear-gradient(135deg, #f97316, #ea580c); border: none; }
.bubble { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; font-size: 14.5px; line-height: 1.75; white-space: pre-wrap; word-break: break-word; }
.msg.user .bubble { background: #2a1c10; border-color: #7c3a1e; }
.bubble { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; font-size: 14.5px; line-height: 1.55; white-space: normal; word-break: break-word; }
.msg.user .bubble { background: #2a1c10; border-color: #7c3a1e; white-space: pre-wrap; }
.bubble b { color: var(--orange2); }
.bubble em { color: var(--blue); font-style: normal; }
.bubble .hint { color: var(--sub); font-size: 13px; margin-top: 6px; }
.bubble .quick-q { color: var(--blue); cursor: pointer; text-decoration: none; border-bottom: 1px dashed var(--blue); }
.bubble .quick-q:hover { color: var(--orange2); border-bottom-color: var(--orange2); }
.bubble ul { margin: 6px 0 6px 18px; }
.bubble li { margin: 3px 0; }
.bubble ul { margin: 4px 0 4px 18px; }
.bubble li { margin: 2px 0; }
/* ---------- Markdown 渲染(需求3 ---------- */
.md { line-height: 1.8; }
.md h1, .md h2, .md h3, .md h4 { margin: 12px 0 6px; line-height: 1.4; }
.md h1 { font-size: 17px; } .md h2 { font-size: 16px; } .md h3, .md h4 { font-size: 15px; }
.md { line-height: 1.6; }
.md h1, .md h2, .md h3, .md h4 { margin: 10px 0 4px; line-height: 1.35; }
.md h1 { font-size: 16.5px; } .md h2 { font-size: 15.5px; } .md h3, .md h4 { font-size: 14.5px; }
.md h1::before, .md h2::before { content: ""; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0 6px 20px; }
.md li { margin: 3px 0; }
.md p { margin: 4px 0; }
.md ul, .md ol { margin: 4px 0 4px 20px; }
.md li { margin: 2px 0; }
.md code { background: #0d1117; border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; font-size: 12.5px; font-family: Consolas, monospace; color: var(--green); }
.md pre { background: #0d1117; border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow-x: auto; margin: 8px 0; }
.md pre { background: #0d1117; border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow-x: auto; margin: 6px 0; }
.md pre code { background: transparent; border: none; padding: 0; color: var(--txt); }
.md blockquote { border-left: 3px solid var(--orange2); padding: 2px 12px; margin: 8px 0; color: var(--sub); background: rgba(249,115,22,.06); border-radius: 0 8px 8px 0; }
.md table { display: block; width: 100%; overflow-x: auto; margin: 10px 0; }
.md table th, .md table td { padding: 7px 10px; font-size: 12.5px; }
.md blockquote { border-left: 3px solid var(--orange2); padding: 2px 12px; margin: 6px 0; color: var(--sub); background: rgba(249,115,22,.06); border-radius: 0 8px 8px 0; }
.md table { display: block; width: 100%; overflow-x: auto; margin: 8px 0; }
.md table th, .md table td { padding: 6px 9px; font-size: 12.5px; }
.md table th { background: var(--bg2); color: var(--orange2); }
.md hr { border: none; border-top: 1px solid var(--line); margin: 10px 0; }
.md hr { border: none; border-top: 1px solid var(--line); margin: 8px 0; }
.md a { color: var(--blue); text-decoration: none; }
.md a:hover { text-decoration: underline; }