fix(ui): fix mauricio change
This commit is contained in:
parent
cf3e982b8a
commit
c56bda106d
2 changed files with 8 additions and 40 deletions
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue