Add abort signal handling to request functions

This commit is contained in:
kwaroran
2025-03-24 17:02:42 +09:00
parent 669d677efd
commit 50842d5829

View File

@@ -283,6 +283,13 @@ export async function requestChatData(arg:requestDataArgument, model:ModelModeEx
} }
while(true){ while(true){
if(abortSignal?.aborted){
return {
type: 'fail',
result: 'Aborted'
}
}
if(pluginV2.replacerbeforeRequest.size > 0){ if(pluginV2.replacerbeforeRequest.size > 0){
for(const replacer of pluginV2.replacerbeforeRequest){ for(const replacer of pluginV2.replacerbeforeRequest){
@@ -317,6 +324,13 @@ export async function requestChatData(arg:requestDataArgument, model:ModelModeEx
...arg, ...arg,
staticModel: fallBackModels[fallbackIndex] staticModel: fallBackModels[fallbackIndex]
}, model, abortSignal) }, model, abortSignal)
if(abortSignal.aborted){
return {
type: 'fail',
result: 'Aborted'
}
}
if(da.type === 'success' && pluginV2.replacerafterRequest.size > 0){ if(da.type === 'success' && pluginV2.replacerafterRequest.size > 0){
for(const replacer of pluginV2.replacerafterRequest){ for(const replacer of pluginV2.replacerafterRequest){
@@ -1401,7 +1415,8 @@ async function requestOpenAILegacyInstruct(arg:RequestDataArgumentExtended):Prom
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": "Bearer " + (arg.key ?? db.openAIKey) "Authorization": "Bearer " + (arg.key ?? db.openAIKey)
}, },
chatId: arg.chatId chatId: arg.chatId,
abortSignal: arg.abortSignal
}); });
if(!response.ok){ if(!response.ok){
@@ -1552,7 +1567,8 @@ async function requestOpenAIResponseAPI(arg:RequestDataArgumentExtended):Promise
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": "Bearer " + (arg.key ?? db.openAIKey), "Authorization": "Bearer " + (arg.key ?? db.openAIKey),
}, },
chatId: arg.chatId chatId: arg.chatId,
abortSignal: arg.abortSignal
}); });
if(!response.ok){ if(!response.ok){
@@ -1669,7 +1685,7 @@ async function requestNovelAI(arg:RequestDataArgumentExtended):Promise<requestDa
"Authorization": "Bearer " + (arg.key ?? db.novelai.token) "Authorization": "Bearer " + (arg.key ?? db.novelai.token)
}, },
abortSignal, abortSignal,
chatId: arg.chatId chatId: arg.chatId,
}) })
if((!da.ok )|| (!da.data.output)){ if((!da.ok )|| (!da.data.output)){
@@ -1873,7 +1889,8 @@ async function requestOoba(arg:RequestDataArgumentExtended):Promise<requestDataR
const response = await globalFetch(urlStr, { const response = await globalFetch(urlStr, {
body: bodyTemplate, body: bodyTemplate,
chatId: arg.chatId chatId: arg.chatId,
abortSignal: arg.abortSignal
}) })
if(!response.ok){ if(!response.ok){
@@ -2366,6 +2383,7 @@ async function requestGoogleCloudVertex(arg:RequestDataArgumentExtended):Promise
body: JSON.stringify(body), body: JSON.stringify(body),
method: 'POST', method: 'POST',
chatId: arg.chatId, chatId: arg.chatId,
signal: arg.abortSignal
}) })
if(f.status !== 200){ if(f.status !== 200){
@@ -2668,7 +2686,8 @@ async function requestNovelList(arg:RequestDataArgumentExtended):Promise<request
method: 'POST', method: 'POST',
headers: headers, headers: headers,
body: send_body, body: send_body,
chatId: arg.chatId chatId: arg.chatId,
abortSignal: arg.abortSignal
}); });
if(!response.ok){ if(!response.ok){
@@ -2840,7 +2859,8 @@ async function requestCohere(arg:RequestDataArgumentExtended):Promise<requestDat
"Authorization": "Bearer " + (arg.key ?? db.cohereAPIKey), "Authorization": "Bearer " + (arg.key ?? db.cohereAPIKey),
"Content-Type": "application/json" "Content-Type": "application/json"
}, },
body: body body: body,
abortSignal: arg.abortSignal
}) })
if(!res.ok){ if(!res.ok){