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

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