鼎稔道學館
← 開源 LLM/Cookbook/08
08

How we build a Temple Bot (A1)

CC0

RAG-only 對話 Bot,含 22 條 client-side 紅線 regex 守則 + LINE OA webhook 範例。

RAG botLINE OA紅線守則FastAPI

對應 Live Demo

🔒 重現條件鎖
MODEL    = "lius-cc/Daoism-Qwen3.5-9B"
DATASET  = "lius-cc/daoism-knowledge-rag@v1"
RAG_API  = "https://lius.cc/api/llm-rag"
SNAPSHOT = "2026-05-17"

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", [])
    ]}

📜 本 recipe 採 CC0 1.0 · 改一行 prompt → 寫到論文裡 → 引用 LIUS API

引用建議:We use the open-source Daoism-Qwen3.5-9B with the public RAG API at https://lius.cc/api/llm-rag (Liu & Dingren Daoxue Lab, 2026).

← 回 Cookbook 索引

08 · How we build a Temple Bot (A1) · Cookbook · 鼎稔道學館