mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-02-10 18:05:06 +08:00
Fix streaming with helper (md)
This commit is contained in:
@ -17,7 +17,7 @@
|
||||
},
|
||||
|
||||
"guid" : "asc.{9DC93CDB-B576-4F0C-B55E-FCC9C48DD007}",
|
||||
"version": "3.0.2",
|
||||
"version": "3.0.3",
|
||||
"minVersion" : "8.2.0",
|
||||
|
||||
"variations" : [
|
||||
|
||||
@ -171,16 +171,14 @@ window.addSupportAgentMode = function(editorVersion) {
|
||||
});
|
||||
}
|
||||
|
||||
let markdownStreamer = new MarkDownStreamer();
|
||||
|
||||
let isSupportStreaming = window.EditorHelper.isSupportStreaming;
|
||||
let dataStream = "";
|
||||
async function onStreamEvent(data, end) {
|
||||
if (isSupportStreaming)
|
||||
await Asc.Library.PasteText(data);
|
||||
dataStream += data;
|
||||
if (true === end && "" !== dataStream) {
|
||||
await Asc.Library.PasteText(dataStream);
|
||||
dataStream = "";
|
||||
}
|
||||
await markdownStreamer.onStreamChunk(data, end);
|
||||
else if (end)
|
||||
await Asc.Library.PasteText(data);
|
||||
}
|
||||
|
||||
let result = await requestEngine.chatRequest(copyMessages, false, async function(data) {
|
||||
@ -203,14 +201,18 @@ window.addSupportAgentMode = function(editorVersion) {
|
||||
await onStreamEvent(data);
|
||||
});
|
||||
|
||||
if (!isSupportStreaming)
|
||||
buffer = result;
|
||||
|
||||
if (checkBuffer && !buffer.startsWith(bufferWait)) {
|
||||
checkBuffer = false;
|
||||
await onStreamEvent(buffer, true);
|
||||
}
|
||||
|
||||
if (!isSupportStreaming) {
|
||||
await onStreamEvent("", true);
|
||||
}
|
||||
if (!isSupportStreaming && !checkBuffer)
|
||||
await onStreamEvent(buffer, true);
|
||||
|
||||
if (isSupportStreaming)
|
||||
markdownStreamer.onStreamEnd();
|
||||
|
||||
await checkEndAction();
|
||||
|
||||
|
||||
@ -608,7 +608,7 @@
|
||||
Library.prototype.getMarkdownResult = function(data) {
|
||||
let markdownEscape = data.indexOf("```md");
|
||||
if (-1 !== markdownEscape && markdownEscape < 5)
|
||||
data = data.substring(markdownEscape + 5);
|
||||
data = data.substring(markdownEscape + 5);
|
||||
return this.trimResult(data);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user