Fix koboldcpp abort generation error (#4693) * Enhance contribution guidelines for pull requests Added guidelines for maintaining workflow during PRs. * fix abort generation error when koboldcpp is set with a password * add parameter type, and remove unecessary line * oops, missing comma * eslint * remove header content type --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com> Co-authored-by: Your Name <you@example.com>
Signed| @@ -72,15 +72,20 @@ async function parseOllamaStream(jsonStream, request, response) { | |||
| 72 | 72 | ||
| 73 | /** | 73 | /** |
| 74 | * Abort KoboldCpp generation request. | 74 | * Abort KoboldCpp generation request. |
| 75 | * @param {import('express').Request} request the generation request | ||
| 75 | * @param {string} url Server base URL | 76 | * @param {string} url Server base URL |
| 76 | * @returns {Promise<void>} Promise resolving when we are done | 77 | * @returns {Promise<void>} Promise resolving when we are done |
| 77 | */ | 78 | */ |
| 78 | async function abortKoboldCppRequest(url) { | 79 | async function abortKoboldCppRequest(request, url) { |
| 79 | try { | 80 | try { |
| 80 | console.info('Aborting Kobold generation...'); | 81 | console.info('Aborting Kobold generation...'); |
| 81 | const abortResponse = await fetch(`${url}/api/extra/abort`, { | 82 | let args = { |
| 82 | method: 'POST', | 83 | method: 'POST', |
| 83 | }); | 84 | headers: {}, |
| 85 | }; | ||
| 86 | |||
| 87 | setAdditionalHeaders(request, args, url); | ||
| 88 | const abortResponse = await fetch(`${url}/api/extra/abort`, args); | ||
| 84 | 89 | ||
| 85 | if (!abortResponse.ok) { | 90 | if (!abortResponse.ok) { |
| 86 | console.error('Error sending abort request to Kobold:', abortResponse.status, abortResponse.statusText); | 91 | console.error('Error sending abort request to Kobold:', abortResponse.status, abortResponse.statusText); |
| @@ -275,7 +280,7 @@ router.post('/generate', async function (request, response) { | |||
| 275 | request.socket.removeAllListeners('close'); | 280 | request.socket.removeAllListeners('close'); |
| 276 | request.socket.on('close', async function () { | 281 | request.socket.on('close', async function () { |
| 277 | if (request.body.api_type === TEXTGEN_TYPES.KOBOLDCPP && !response.writableEnded) { | 282 | if (request.body.api_type === TEXTGEN_TYPES.KOBOLDCPP && !response.writableEnded) { |
| 278 | await abortKoboldCppRequest(trimV1(baseUrl)); | 283 | await abortKoboldCppRequest(request, trimV1(baseUrl)); |
| 279 | } | 284 | } |
| 280 | 285 | ||
| 281 | controller.abort(); | 286 | controller.abort(); |