improve sse fetch

This commit is contained in:
josc146
2023-07-25 15:59:37 +08:00
parent 5ae683e915
commit 211ae342af
2 changed files with 10 additions and 6 deletions

View File

@@ -219,7 +219,7 @@ const CompletionPanel: FC = observer(() => {
signal: completionSseController?.signal,
onmessage(e) {
scrollToBottom();
if (e.data === '[DONE]') {
if (e.data.trim() === '[DONE]') {
commonStore.setCompletionGenerating(false);
return;
}
@@ -231,8 +231,8 @@ const CompletionPanel: FC = observer(() => {
return;
}
if (data.choices && Array.isArray(data.choices) && data.choices.length > 0) {
answer += data.choices[0].text;
setPrompt(prompt + answer.trim() + params.injectEnd.replaceAll('\\n', '\n'));
answer += data.choices[0]?.text || data.choices[0]?.delta?.content || '';
setPrompt(prompt + answer.replace(/\s+$/, '') + params.injectEnd.replaceAll('\\n', '\n'));
}
},
async onopen(response) {