根据数据表回答
机器翻译
本页由英文原文机器翻译而来,尚未经过母语审校,欢迎在 GitHub 上提出修改。内容如有出入,以英文原文为准。
任务: 根据保存在数据库中的常见问题,回答有关账号的问题。
yaml
# Recipe: answer from the rows of a table — an FAQ kept in the database.
paths:
components: ./components
migrations: ./migrations
datasources:
db:
driver: sqlite
database: ./data/faq.db
llm:
model: phi3sql
CREATE TABLE faq (
id INTEGER PRIMARY KEY AUTOINCREMENT,
question TEXT NOT NULL,
answer TEXT NOT NULL
);
INSERT INTO faq (question, answer) VALUES
('Can I change my password?', 'Passwords are changed on the Account page, under Security.'),
('How do I export my invoices?', 'Invoices are exported as PDF from the Billing page, one per month.'),
('Is there a mobile app?', 'There is no mobile app; the site works on phones.');type="query" 来源把每一行变成一段待索引的文本。其中的所有内容由应用的所有用户共享—— 任何问题都可能检索到任何一行——所以只索引每个人都可以读的内容。
xml
<q:component name="Help">
<!-- A query source: each row becomes text to index. Every user can
retrieve any row, so index only what everyone may read. -->
<q:knowledge name="faq" persist="false">
<q:source type="query" datasource="db">
SELECT question || ' ' || answer AS content FROM faq
</q:source>
</q:knowledge>
<q:set name="question" value="{query.q}" default="" />
<q:if condition="question">
<q:llm name="answer" knowledge="faq" top="1" minRelevance="0.8">
<q:message role="user">{question}</q:message>
</q:llm>
</q:if>
<ui:window title="Help">
<ui:form>
<ui:input bind="q" value="{question}" placeholder="Ask about your account" />
<ui:button variant="primary">Ask</ui:button>
</ui:form>
<q:if condition="question">
<q:if condition="answer_result.found">
<ui:text>{answer}</ui:text>
<ui:text>From the FAQ: {answer_result.sources[0].text}</ui:text>
<q:else>
<ui:alert variant="info">The FAQ does not cover that yet.</ui:alert>
</q:else>
</q:if>
</q:if>
</ui:window>
</q:component>xml
<!-- Structural checks, never the model's exact words: the same tests run
against a real model before every release. -->
<q:test name="a question the FAQ covers" page="/">
<test:visit q="How can I export my invoices as PDF?" />
<test:expect text="From the FAQ: How do I export my invoices?" />
</q:test>
<q:test name="a question it does not" page="/">
<test:visit q="What is the weather tomorrow?" />
<test:expect text="The FAQ does not cover that yet." />
</q:test>text
tests/faq.test.q
PASS a question the FAQ covers
PASS a question it does not
2 passed, 0 failed已测试: 在 CI 中,这些测试针对一个替身模型服务器运行,它根据收到的第一个来源作答;每次发布前,它们针对真实模型运行(tests/live_ai/test_cookbook_ai.py)。因此它们检查的是结构——哪个来源、哪个工具、失败时页面显示什么——而从不检查模型的措辞。