mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-29 10:44:00 +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);
|
const json = JSON.parse(jsonString);
|
||||||
return json;
|
return json;
|
||||||
} catch {
|
} catch {
|
||||||
return '[ERROR]';
|
return jsonString;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -83,21 +83,25 @@ const useSubmit = () => {
|
||||||
);
|
);
|
||||||
const reader = stream.getReader();
|
const reader = stream.getReader();
|
||||||
let reading = true;
|
let reading = true;
|
||||||
|
let partial = '';
|
||||||
while (reading && useStore.getState().generating) {
|
while (reading && useStore.getState().generating) {
|
||||||
const { done, value } = await reader.read();
|
const { done, value } = await reader.read();
|
||||||
|
const result = parseEventSource(
|
||||||
const result = parseEventSource(new TextDecoder().decode(value));
|
partial + new TextDecoder().decode(value)
|
||||||
|
);
|
||||||
|
partial = '';
|
||||||
|
|
||||||
if (result === '[DONE]' || done) {
|
if (result === '[DONE]' || done) {
|
||||||
reading = false;
|
reading = false;
|
||||||
} else {
|
} else {
|
||||||
const resultString = result.reduce((output: string, curr) => {
|
const resultString = result.reduce((output: string, curr) => {
|
||||||
if (typeof curr === 'string') return output;
|
if (typeof curr === 'string') {
|
||||||
else {
|
partial += curr;
|
||||||
|
} else {
|
||||||
const content = curr.choices[0].delta.content;
|
const content = curr.choices[0].delta.content;
|
||||||
if (content) output += content;
|
if (content) output += content;
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
return output;
|
||||||
}, '');
|
}, '');
|
||||||
|
|
||||||
const updatedChats: ChatInterface[] = JSON.parse(
|
const updatedChats: ChatInterface[] = JSON.parse(
|
||||||
|
|
Loading…
Reference in a new issue