| @@ -219,19 +219,7 @@ router.post('/status', jsonParser, async function (request, response) { | ||
| 219 | 219 | } catch (error) { |
| 220 | 220 | console.error(`Failed to get TabbyAPI model info: ${error}`); |
| 221 | 221 | } |
| 222 | 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 | 223 | // the /props endpoint includes chat template |
| 236 | 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 | }); |
| 245 | 233 | |
| 246 | -const chat_template_endpoints = { | |
| 247 | - koboldcpp: '/api/extra/chat_template', | |
| 248 | - llamacpp: '/props', | |
| 249 | -} | |
| 250 | - | |
| 251 | 234 | router.post('/chat_template', jsonParser, async function (request, response) { |
| 252 | 235 | if (!request.body.api_server) return response.sendStatus(400); |
| 253 | 236 | |
| @@ -260,23 +243,23 @@ router.post('/chat_template', jsonParser, async function (request, response) { | ||
| 260 | 243 | setAdditionalHeaders(request, args, baseUrl); |
| 261 | 244 | |
| 262 | 245 | const apiType = request.body.api_type; |
| 263 | 246 | const chatTemplateUrlpropsUrl = baseUrl + chat_template_endpoints[apiType]"/props"; |
| 264 | 247 | const chatTemplateReplypropsReply = await fetch(chatTemplateUrlpropsUrl, args); |
| 265 | 248 | |
| 266 | 249 | if (!chatTemplateReplypropsReply.ok) { |
| 267 | 250 | console.log('Chat templateProperties endpoint is offline.'); |
| 268 | 251 | return response.status(400); |
| 269 | 252 | } |
| 270 | 253 | |
| 271 | 254 | /** @type {any} */ |
| 272 | 255 | const chatTemplateprops = await chatTemplateReplypropsReply.json(); |
| 273 | 256 | // TEMPORARY: llama.cpp's /props endpoint includes a \u0000 at the end of the chat template, resulting in mismatching hashes |
| 274 | 257 | if (apiType === TEXTGEN_TYPES.LLAMACPP && chatTemplateprops['chat_template'].endsWith('\u0000')) { |
| 275 | 258 | chatTemplateprops['chat_template'] = chatTemplateprops['chat_template'].slice(0, -1); |
| 276 | 259 | } |
| 277 | 260 | chatTemplateprops['chat_template_hash'] = createHash('sha256').update(chatTemplateprops['chat_template']).digest('hex'); |
| 278 | 261 | console.log(`We have chat template stuff: ${JSON.stringify(chatTemplateprops)}`); |
| 279 | 262 | return response.send(chatTemplateprops); |
| 280 | 263 | } catch (error) { |
| 281 | 264 | console.error(error); |
| 282 | 265 | return response.status(500); |