|
|
|
@ -175,7 +175,7 @@
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div class="container">
|
|
|
|
|
<h1>少惠林2025暑期读书营【少年读史记】知识问答</h1>
|
|
|
|
|
<h1>【少年读史记】知识问答</h1>
|
|
|
|
|
<div class="data-area" id="answerArea">
|
|
|
|
|
<div style="color:#666; padding:20px; text-align:center;">
|
|
|
|
|
<p>请在下方输入您的问题,答案将在此处显示</p>
|
|
|
|
@ -207,6 +207,7 @@
|
|
|
|
|
</div>
|
|
|
|
|
<button id="submitBtn" onclick="submitQuestion()"><span class="icon">💡</span>提问</button>
|
|
|
|
|
<button id="clearBtn" onclick="clearAll()"><span class="icon">🗑️</span>清空</button>
|
|
|
|
|
<button id="relationBtn" onclick="generateRelation()" style="background-color:#9c27b0"><span class="icon">👥</span>生成刘帮集团的人物关系图</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
@ -342,6 +343,65 @@
|
|
|
|
|
document.getElementById('questionInput').value = '';
|
|
|
|
|
document.getElementById('answerArea').innerHTML = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 在script部分添加新函数
|
|
|
|
|
function generateRelation() {
|
|
|
|
|
const answerArea = document.getElementById('answerArea');
|
|
|
|
|
answerArea.innerHTML = '<div class="loading-animation"><div class="spinner"></div><div>正在生成人物关系图...</div></div>';
|
|
|
|
|
|
|
|
|
|
fetch('/api/rag', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'text/event-stream'
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
query: "生成刘帮集团的人物关系图",
|
|
|
|
|
topic: "ShiJi",
|
|
|
|
|
mode: "hybrid",
|
|
|
|
|
output_model: "html"
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
|
|
|
|
const reader = response.body.getReader();
|
|
|
|
|
const decoder = new TextDecoder();
|
|
|
|
|
let buffer = '';
|
|
|
|
|
let accumulatedContent = '';
|
|
|
|
|
|
|
|
|
|
function processChunk() {
|
|
|
|
|
return reader.read().then(({done, value}) => {
|
|
|
|
|
if (done) return;
|
|
|
|
|
|
|
|
|
|
buffer += decoder.decode(value, {stream: true});
|
|
|
|
|
const lines = buffer.split('\n');
|
|
|
|
|
buffer = lines.pop();
|
|
|
|
|
|
|
|
|
|
for (const line of lines) {
|
|
|
|
|
if (line.includes('data:')) {
|
|
|
|
|
const jsonStr = line.replace(/^data:\s*/, '').replace(/^data:\s*/, '').trim();
|
|
|
|
|
if (jsonStr) {
|
|
|
|
|
try {
|
|
|
|
|
const data = JSON.parse(jsonStr);
|
|
|
|
|
if (data.reply) {
|
|
|
|
|
accumulatedContent += data.reply;
|
|
|
|
|
answerArea.innerHTML = marked.parse(accumulatedContent, markedOptions);
|
|
|
|
|
MathJax.typesetPromise();
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log('忽略解析错误:', e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return processChunk();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return processChunk();
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
answerArea.innerHTML = '<div style="color:red">生成关系图出错,请重试</div>';
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<script src="/static/mathjax/es5/tex-mml-chtml.js" id="MathJax-script" async></script>
|
|
|
|
|
<script src="/static/js/marked.min.js"></script>
|
|
|
|
|