1 · 客端紅線偵測(不打 LLM)
22 條 regex 預先擋下個人化占卜問題。
import re
REDLINE = [
r"拜得到", r"有沒有效", r"會不會應", r"該不該", r"可以求", r"能求嗎",
r"準不準", r"靈不靈", r"運勢", r"命運", r"命格", r"姻緣何時", r"幾時會",
r"流年", r"八字", r"紫微", r"占卜", r"解籤", r"籤詩", r"問事", r"問神",
]
RX = [re.compile(p) for p in REDLINE]
def is_redline(q: str) -> bool:
return any(rx.search(q) for rx in RX)2 · RAG-as-answer(不打 LLM 生成)
直接回 top-N hits,每條附原始連結。零幻覺。
import requests
def temple_bot(q: str):
if is_redline(q):
return {"kind": "redline", "reply": "涉及個人占卜,請洽合格道長。"}
res = requests.post("https://lius.cc/api/llm-rag",
json={"q": q, "n": 4, "types": ["deity", "ritual", "concept", "location"]}, timeout=10)
res.raise_for_status()
r = res.json()
return {"kind": "rag", "hits": [
{"name": h["name"], "type": h["type"], "url": h["url"],
"snippet": (h.get("summary") or h.get("content") or "")[:160] + "…"}
for h in r.get("hits", [])
]}