Add proper processing of streaming aborting

This commit is contained in:
SillyLossy
2023-04-21 20:29:18 +03:00
parent 9af7c63d9c
commit f25ecbd95c
6 changed files with 62 additions and 10 deletions

View File

@ -86,7 +86,7 @@ function onBotChange() {
saveSettingsDebounced();
}
async function generatePoe(type, finalPrompt) {
async function generatePoe(type, finalPrompt, signal) {
if (poe_settings.auto_purge) {
let count_to_delete = -1;
@ -136,7 +136,7 @@ async function generatePoe(type, finalPrompt) {
finalPrompt = sentences.join('');
}
const reply = await sendMessage(finalPrompt, true);
const reply = await sendMessage(finalPrompt, true, signal);
got_reply = true;
return reply;
}
@ -160,7 +160,11 @@ async function purgeConversation(count = -1) {
return response.ok;
}
async function sendMessage(prompt, withStreaming) {
async function sendMessage(prompt, withStreaming, signal) {
if (!signal) {
signal = new AbortController().signal;
}
const body = JSON.stringify({
bot: poe_settings.bot,
token: poe_settings.token,
@ -175,6 +179,7 @@ async function sendMessage(prompt, withStreaming) {
},
body: body,
method: 'POST',
signal: signal,
});
if (withStreaming && poe_settings.streaming) {