|
|
|
@ -84,7 +84,6 @@
|
|
|
|
|
margin-right: 5px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@keyframes spin {
|
|
|
|
|
0% {
|
|
|
|
|
transform: rotate(0deg);
|
|
|
|
@ -183,7 +182,8 @@
|
|
|
|
|
|
|
|
|
|
<div class="input-area">
|
|
|
|
|
<label for="questionInput"></label><textarea id="questionInput" placeholder="请输入您的问题..."></textarea>
|
|
|
|
|
<div class="examples">
|
|
|
|
|
|
|
|
|
|
<div class="examples">
|
|
|
|
|
<div class="example-category">
|
|
|
|
|
<h3>知识库内问题示例:</h3>
|
|
|
|
|
<div class="example-list">
|
|
|
|
@ -227,37 +227,36 @@
|
|
|
|
|
<button id="submitBtn" onclick="submitQuestion()"><span class="icon">💡</span>提问</button>
|
|
|
|
|
<button id="clearBtn" onclick="clearAll()"><span class="icon">🗑️</span>清空</button>
|
|
|
|
|
<button id="saveWordBtn" onclick="saveToWord()"><span class="icon">📄</span>保存为Word</button>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
// 禁用所有按钮
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
|
const buttons = document.querySelectorAll('button');
|
|
|
|
|
buttons.forEach(btn => btn.disabled = true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
MathJax = {
|
|
|
|
|
tex: {
|
|
|
|
|
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
|
|
|
|
displayMath: [['$$', '$$'], ['\\[', '\\]']]
|
|
|
|
|
},
|
|
|
|
|
svg: {
|
|
|
|
|
fontCache: 'global'
|
|
|
|
|
},
|
|
|
|
|
startup: {
|
|
|
|
|
pageReady: () => {
|
|
|
|
|
return MathJax.startup.defaultPageReady().then(() => {
|
|
|
|
|
console.log('MathJax initialized');
|
|
|
|
|
// 启用所有按钮
|
|
|
|
|
const buttons = document.querySelectorAll('button');
|
|
|
|
|
buttons.forEach(btn => btn.disabled = false);
|
|
|
|
|
return MathJax.typesetPromise();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
// 禁用所有按钮
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
|
const buttons = document.querySelectorAll('button');
|
|
|
|
|
buttons.forEach(btn => btn.disabled = true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
MathJax = {
|
|
|
|
|
tex: {
|
|
|
|
|
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
|
|
|
|
displayMath: [['$$', '$$'], ['\\[', '\\]']]
|
|
|
|
|
},
|
|
|
|
|
svg: {
|
|
|
|
|
fontCache: 'global'
|
|
|
|
|
},
|
|
|
|
|
startup: {
|
|
|
|
|
pageReady: () => {
|
|
|
|
|
return MathJax.startup.defaultPageReady().then(() => {
|
|
|
|
|
console.log('MathJax initialized');
|
|
|
|
|
// 启用所有按钮
|
|
|
|
|
const buttons = document.querySelectorAll('button');
|
|
|
|
|
buttons.forEach(btn => btn.disabled = false);
|
|
|
|
|
return MathJax.typesetPromise();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
<!--国内可以访问的JS,不要使用静态的本地的,因为文件不全的话没有好的显示效果!-->
|
|
|
|
|
<script src="https://cdn.bootcdn.net/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js" id="MathJax-script" async></script>
|
|
|
|
@ -299,47 +298,47 @@
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(data)
|
|
|
|
|
})
|
|
|
|
|
.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);
|
|
|
|
|
MathJax.typesetPromise();
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log('忽略解析错误:', e);
|
|
|
|
|
.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);
|
|
|
|
|
MathJax.typesetPromise();
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log('忽略解析错误:', e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return processChunk();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return processChunk();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return processChunk();
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.error('Error:', error);
|
|
|
|
|
});
|
|
|
|
|
return processChunk();
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.error('Error:', error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clearAll() {
|
|
|
|
|