update endpoint to reflect koboldcpp update

bb062f5ec9ac1bc62345e36e2b4c1d66e357c646

Karl-Johan Alm <karljohan-alm@garage.co.jp>

Signed
1 files changed, +11 -28Ignore whitespace
src/endpoints/backends/text-completions.js+11 -28
@@ -219,19 +219,7 @@ router.post('/status', jsonParser, async function (request, response) {
219 } catch (error) {219 } catch (error) {
220 console.error(`Failed to get TabbyAPI model info: ${error}`);220 console.error(`Failed to get TabbyAPI model info: ${error}`);
221 }221 }
222 } else if (apiType == TEXTGEN_TYPES.KOBOLDCPP) {222 } else if (apiType == TEXTGEN_TYPES.KOBOLDCPP || apiType == TEXTGEN_TYPES.LLAMACPP) {
223 try {
224 const chatTemplateUrl = baseUrl + '/api/extra/chat_template';
225 const chatTemplateReply = await fetch(chatTemplateUrl);
226 if (chatTemplateReply.ok) {
227 response.setHeader('x-supports-chat-template', 'true');
228 } else {
229 console.log(`chat_template error: ${JSON.stringify(chatTemplateReply)}`);
230 }
231 } catch (error) {
232 console.error(`Failed to fetch chat template info: ${error}`);
233 }
234 } else if (apiType == TEXTGEN_TYPES.LLAMACPP) {
235 // the /props endpoint includes chat template223 // the /props endpoint includes chat template
236 response.setHeader('x-supports-chat-template', 'true');224 response.setHeader('x-supports-chat-template', 'true');
237 }225 }
@@ -243,11 +231,6 @@ router.post('/status', jsonParser, async function (request, response) {
243 }231 }
244});232});
245233
246const chat_template_endpoints = {
247 koboldcpp: '/api/extra/chat_template',
248 llamacpp: '/props',
249}
250
251router.post('/chat_template', jsonParser, async function (request, response) {234router.post('/chat_template', jsonParser, async function (request, response) {
252 if (!request.body.api_server) return response.sendStatus(400);235 if (!request.body.api_server) return response.sendStatus(400);
253236
@@ -260,23 +243,23 @@ router.post('/chat_template', jsonParser, async function (request, response) {
260 setAdditionalHeaders(request, args, baseUrl);243 setAdditionalHeaders(request, args, baseUrl);
261244
262 const apiType = request.body.api_type;245 const apiType = request.body.api_type;
263 const chatTemplateUrl = baseUrl + chat_template_endpoints[apiType];246 const propsUrl = baseUrl + "/props";
264 const chatTemplateReply = await fetch(chatTemplateUrl, args);247 const propsReply = await fetch(propsUrl, args);
265248
266 if (!chatTemplateReply.ok) {249 if (!propsReply.ok) {
267 console.log('Chat template endpoint is offline.');250 console.log('Properties endpoint is offline.');
268 return response.status(400);251 return response.status(400);
269 }252 }
270253
271 /** @type {any} */254 /** @type {any} */
272 const chatTemplate = await chatTemplateReply.json();255 const props = await propsReply.json();
273 // TEMPORARY: llama.cpp's /props endpoint includes a \u0000 at the end of the chat template, resulting in mismatching hashes256 // TEMPORARY: llama.cpp's /props endpoint includes a \u0000 at the end of the chat template, resulting in mismatching hashes
274 if (apiType === TEXTGEN_TYPES.LLAMACPP && chatTemplate['chat_template'].endsWith('\u0000')) {257 if (apiType === TEXTGEN_TYPES.LLAMACPP && props['chat_template'].endsWith('\u0000')) {
275 chatTemplate['chat_template'] = chatTemplate['chat_template'].slice(0, -1);258 props['chat_template'] = props['chat_template'].slice(0, -1);
276 }259 }
277 chatTemplate['chat_template_hash'] = createHash('sha256').update(chatTemplate['chat_template']).digest('hex');260 props['chat_template_hash'] = createHash('sha256').update(props['chat_template']).digest('hex');
278 console.log(`We have chat template stuff: ${JSON.stringify(chatTemplate)}`);261 console.log(`We have chat template stuff: ${JSON.stringify(props)}`);
279 return response.send(chatTemplate);262 return response.send(props);
280 } catch (error) {263 } catch (error) {
281 console.error(error);264 console.error(error);
282 return response.status(500);265 return response.status(500);