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

How we build /api/llm/generate (A2 / A3)

CC0

一個 endpoint,多 task 專屬 prompt;多 provider fallback;5 req/min。

RAG + LLMmulti-providerfallbackrate limit

對應 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 · 多 task 共用 endpoint

POST /api/llm/generate { task, topic } → output(含引用標號)+ provider + latency_ms + hits

import requests

for task, topic in [
    ("publishing", "中元 普渡 七月"),       # → A2 出版選題
    ("grant",      "在地宗教文化盤點"),     # → A3 文化部標案
]:
    r = requests.post("https://lius.cc/api/llm/generate",
                      json={"task": task, "topic": topic}, timeout=60).json()
    print(f"=== {task} {r['provider']} {r['latency_ms']}ms ===")
    print(r['output'][:200], '...')

2 · Provider fallback

Gemma 2.5 Flash → DeepSeek V4-Flash → OpenAI proxy (gpt-5.4-mini)

📜 本 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 索引

10 · How we build /api/llm/generate (A2 / A3) · Cookbook · 鼎稔道學館