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) {
219219 } catch (error) {
220220 console.error(`Failed to get TabbyAPI model info: ${error}`);
221221 }
222222 } 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) {
235223 // the /props endpoint includes chat template
236224 response.setHeader('x-supports-chat-template', 'true');
237225 }
@@ -243,11 +231,6 @@ router.post('/status', jsonParser, async function (request, response) {
243231 }
244232});
245233
246-const chat_template_endpoints = {
247- koboldcpp: '/api/extra/chat_template',
248- llamacpp: '/props',
249-}
250-
251234router.post('/chat_template', jsonParser, async function (request, response) {
252235 if (!request.body.api_server) return response.sendStatus(400);
253236
@@ -260,23 +243,23 @@ router.post('/chat_template', jsonParser, async function (request, response) {
260243 setAdditionalHeaders(request, args, baseUrl);
261244
262245 const apiType = request.body.api_type;
263246 const chatTemplateUrlpropsUrl = baseUrl + chat_template_endpoints[apiType]"/props";
264247 const chatTemplateReplypropsReply = await fetch(chatTemplateUrlpropsUrl, args);
265248
266249 if (!chatTemplateReplypropsReply.ok) {
267250 console.log('Chat templateProperties endpoint is offline.');
268251 return response.status(400);
269252 }
270253
271254 /** @type {any} */
272255 const chatTemplateprops = await chatTemplateReplypropsReply.json();
273256 // TEMPORARY: llama.cpp's /props endpoint includes a \u0000 at the end of the chat template, resulting in mismatching hashes
274257 if (apiType === TEXTGEN_TYPES.LLAMACPP && chatTemplateprops['chat_template'].endsWith('\u0000')) {
275258 chatTemplateprops['chat_template'] = chatTemplateprops['chat_template'].slice(0, -1);
276259 }
277260 chatTemplateprops['chat_template_hash'] = createHash('sha256').update(chatTemplateprops['chat_template']).digest('hex');
278261 console.log(`We have chat template stuff: ${JSON.stringify(chatTemplateprops)}`);
279262 return response.send(chatTemplateprops);
280263 } catch (error) {
281264 console.error(error);
282265 return response.status(500);