feat: cancellable api request

This commit is contained in:
Wentao Lyu 2023-03-17 03:13:42 +08:00
parent 66ad54168a
commit ef9f1ee1cf
11 changed files with 93 additions and 67 deletions

View file

@ -90,6 +90,14 @@ const ask = async ({
try {
const progressCallback = createOnProgress();
const abortController = new AbortController();
res.on('close', () => {
console.log('The client has disconnected.');
// 执行其他操作
abortController.abort();
})
let gptResponse = await client({
text,
onProgress: progressCallback.call(null, model, { res, text }),
@ -98,7 +106,8 @@ const ask = async ({
conversationId,
...convo
},
...convo
...convo,
abortController
});
console.log('CLIENT RESPONSE', gptResponse);