Send abort signal to koboldcpp server on abort, mk. 2

Implemented the abort request being sent through server.js instead
of the client endpoint.
This commit is contained in:
Zixaphir
2023-06-14 14:31:19 -07:00
parent 55fcebb4e1
commit 8f97d4a71b

View File

@@ -412,8 +412,20 @@ app.post("/generate", jsonParser, async function (request, response_generate = r
response = await fetch(url, { method: 'POST', timeout: 0, ...args }); response = await fetch(url, { method: 'POST', timeout: 0, ...args });
if (request.body.streaming) { if (request.body.streaming) {
request.socket.on('close', async function () {
request.socket.on('close', function () { if (controller.signal.aborted) {
try {
// send abort signal to koboldcpp
await fetch(`${api_server}/extra/abort`, {
method: 'POST',
});
} catch {
// likely endpoint not available on older versions of koboldcpp
if ('status' in error) {
console.log('Status Code from Kobold:', error.status);
}
}
}
response.body.destroy(); // Close the remote stream response.body.destroy(); // Close the remote stream
response_generate.end(); // End the Express response response_generate.end(); // End the Express response
}); });