diff --git a/frontend/app/mstore/aiSummaryStore.ts b/frontend/app/mstore/aiSummaryStore.ts index b72d4bf66..f542e123f 100644 --- a/frontend/app/mstore/aiSummaryStore.ts +++ b/frontend/app/mstore/aiSummaryStore.ts @@ -12,48 +12,15 @@ export default class AiSummaryStore { this.text = text; } - appendText(text: string) { - this.text += text; - } - getSummary = async (sessionId: string) => { this.setText(''); - const respBody = await aiService.getSummary(sessionId); - if (!respBody) return; - - const reader = respBody.getReader(); - - let lastIncompleteWord = ''; - - const processTextChunk = (textChunk: string) => { - textChunk = lastIncompleteWord + textChunk; - const words = textChunk.split(' '); - - lastIncompleteWord = words.pop() || ''; - - words.forEach((word) => { - if(word) this.appendText(word + ' '); - }); - }; - try { - while (true) { - const { done, value } = await reader.read(); - if (done) { - // Processing any remaining incomplete word at the end of the stream - if (lastIncompleteWord) { - this.appendText(lastIncompleteWord + ' '); - } - break; - } - let textChunk = new TextDecoder().decode(value, { stream: true }); - if (this.text === '') { - textChunk = textChunk.trimStart() - } - processTextChunk(textChunk); - } - } catch (error) { - console.log(error); + const respText = await aiService.getSummary(sessionId); + if (!respText) return; + + this.setText(respText); + } catch (e) { + console.error(e); } }; } diff --git a/frontend/app/services/AiService.ts b/frontend/app/services/AiService.ts index b1ed55a1b..ec3835cf4 100644 --- a/frontend/app/services/AiService.ts +++ b/frontend/app/services/AiService.ts @@ -8,6 +8,7 @@ export default class AiService extends BaseService { const r = await this.client.post( `/sessions/${sessionId}/intelligent/summary`, ); - return r.body; + + return r.json() } }