fix(ui): fix mauricio change

This commit is contained in:
nick-delirium 2024-02-23 18:07:06 +01:00
parent cf3e982b8a
commit c56bda106d
No known key found for this signature in database
GPG key ID: 93ABD695DF5FDBA0
2 changed files with 8 additions and 40 deletions

View file

@ -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);
}
};
}

View file

@ -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()
}
}