带引用回答的客服知识库
将帮助文章存为文件,再通过回答接口提问。每个回答都引用所用的文件,带路径和版本;依据不足时放弃回答,不作猜测。
示例
安装 SDK(npm install @mirabase/sdk 或 pip install mirabase),并设置 MIRABASE_API_KEY。
import { Mirabase } from "@mirabase/sdk";
const mb = new Mirabase(); // reads MIRABASE_API_KEY
// waitSeconds holds the response for up to 10 seconds, until the file is indexed.
await mb.files.write("/help/refunds.md", "# Refunds\n\nRefunds are issued within 14 days of purchase.\n", {
contentType: "text/markdown",
waitSeconds: 10,
});
const reply = await mb.answer("How long do customers have to ask for a refund?");
if (reply.status === "answered") console.log(reply.answer, reply.citations);
else console.log("abstained:", reply.reason);
from mirabase import Mirabase
mb = Mirabase() # reads MIRABASE_API_KEY
# wait_seconds holds the response for up to 10 seconds, until the file is indexed.
mb.files.write(
"/help/refunds.md",
"# Refunds\n\nRefunds are issued within 14 days of purchase.\n",
content_type="text/markdown",
wait_seconds=10,
)
reply = mb.answer("How long do customers have to ask for a refund?")
if reply["status"] == "answered":
print(reply["answer"], reply["citations"])
else:
print("abstained:", reply.get("reason"))
引用带有文件的 path、entry_id、version_id 以及所依据的段落。如需使用自己的模型,改为调用 mb.context(...),在 token 预算内取得一组来源。详见 检索与上下文。