mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-25 19:33:59 +01:00
fix: missing bytes when using api endpoint
This commit is contained in:
parent
1799c40ba3
commit
92f09c275b
|
@ -16,7 +16,7 @@ export const parseEventSource = (
|
|||
const json = JSON.parse(jsonString);
|
||||
return json;
|
||||
} catch {
|
||||
return '[ERROR]';
|
||||
return jsonString;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
|
|
|
@ -83,21 +83,25 @@ const useSubmit = () => {
|
|||
);
|
||||
const reader = stream.getReader();
|
||||
let reading = true;
|
||||
let partial = '';
|
||||
while (reading && useStore.getState().generating) {
|
||||
const { done, value } = await reader.read();
|
||||
|
||||
const result = parseEventSource(new TextDecoder().decode(value));
|
||||
const result = parseEventSource(
|
||||
partial + new TextDecoder().decode(value)
|
||||
);
|
||||
partial = '';
|
||||
|
||||
if (result === '[DONE]' || done) {
|
||||
reading = false;
|
||||
} else {
|
||||
const resultString = result.reduce((output: string, curr) => {
|
||||
if (typeof curr === 'string') return output;
|
||||
else {
|
||||
if (typeof curr === 'string') {
|
||||
partial += curr;
|
||||
} else {
|
||||
const content = curr.choices[0].delta.content;
|
||||
if (content) output += content;
|
||||
return output;
|
||||
}
|
||||
return output;
|
||||
}, '');
|
||||
|
||||
const updatedChats: ChatInterface[] = JSON.parse(
|
||||
|
|
Loading…
Reference in a new issue