forked from pinks/eris
1
0
Fork 0

faster progress refresh

This commit is contained in:
pinks 2023-10-01 23:47:29 +02:00
parent 01261b6f3a
commit adebd34db8
1 changed files with 17 additions and 14 deletions

View File

@ -120,6 +120,7 @@ async function processGenerationJob(
headers: { "Authorization": sdInstance.api.auth }, headers: { "Authorization": sdInstance.api.auth },
}); });
state.sdInstanceId = sdInstance.id; state.sdInstanceId = sdInstance.id;
state.progress = 0;
logger().debug(`Generation started for ${formatUserChat(state)}`); logger().debug(`Generation started for ${formatUserChat(state)}`);
await updateJob({ state: state }); await updateJob({ state: state });
@ -204,6 +205,7 @@ async function processGenerationJob(
responsePromise.catch(() => undefined); responsePromise.catch(() => undefined);
// poll for progress while the generation request is pending // poll for progress while the generation request is pending
do { do {
const progressResponse = await workerSdClient.GET("/sdapi/v1/progress", { const progressResponse = await workerSdClient.GET("/sdapi/v1/progress", {
params: {}, params: {},
@ -217,21 +219,22 @@ async function processGenerationJob(
); );
} }
state.progress = progressResponse.data.progress; if (progressResponse.data.progress > state.progress) {
await updateJob({ state: state }); state.progress = progressResponse.data.progress;
await updateJob({ state: state });
await bot.api.sendChatAction(state.chat.id, "upload_photo", { maxAttempts: 1 })
.catch(() => undefined);
await bot.api.editMessageText(
state.replyMessage.chat.id,
state.replyMessage.message_id,
`Generating your prompt now... ${
(progressResponse.data.progress * 100).toFixed(0)
}% using ${sdInstance.name || sdInstance.id}`,
{ maxAttempts: 1 },
).catch(() => undefined);
}
await bot.api.sendChatAction(state.chat.id, "upload_photo", { maxAttempts: 1 }) await Promise.race([delay(1000), responsePromise]).catch(() => undefined);
.catch(() => undefined);
await bot.api.editMessageText(
state.replyMessage.chat.id,
state.replyMessage.message_id,
`Generating your prompt now... ${(progressResponse.data.progress * 100).toFixed(0)}% using ${
sdInstance.name || sdInstance.id
}`,
{ maxAttempts: 1 },
).catch(() => undefined);
await Promise.race([delay(3000), responsePromise]).catch(() => undefined);
} while (await promiseState(responsePromise) === "pending"); } while (await promiseState(responsePromise) === "pending");
// check response // check response