27 lines
1002 B
JavaScript
27 lines
1002 B
JavaScript
'use strict';
|
|
|
|
// 信息型页面 LLM 提炼成 FAQ(旧 bridge faq/llmRefiner.js 的移植)。
|
|
function createFaqRefiner(llm) {
|
|
const SYSTEM = `You turn website page content into a clean FAQ knowledge base entry.
|
|
Rules: output 3-8 "### Q: ..." / answer pairs based ONLY on the page content; never invent facts, numbers, or policies; answers 1-4 sentences; English; output only the FAQ body, no code fences.`;
|
|
|
|
async function refineToFaq(rawMarkdown, category) {
|
|
const text = String(rawMarkdown || '').slice(0, 6000);
|
|
if (!text.trim()) return null;
|
|
const res = await llm.chat({
|
|
messages: [
|
|
{ role: 'system', content: SYSTEM },
|
|
{ role: 'user', content: `Page category: ${category || 'general'}\n\nRaw page content:\n${text}` },
|
|
],
|
|
temperature: 0.2,
|
|
maxTokens: 800,
|
|
});
|
|
const faq = String(res.content || '').trim();
|
|
return faq.includes('### Q:') ? faq : null;
|
|
}
|
|
|
|
return { refineToFaq };
|
|
}
|
|
|
|
module.exports = { createFaqRefiner };
|