知识库内问题示例:
@@ -227,37 +227,36 @@
-
@@ -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() {