mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	Add some llama.cpp-specific endpoints
This commit is contained in:
		| @@ -473,6 +473,76 @@ llamacpp.post('/caption-image', jsonParser, async function (request, response) { | |||||||
|     } |     } | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | llamacpp.post('/props', jsonParser, async function (request, response) { | ||||||
|  |     try { | ||||||
|  |         if (!request.body.server_url) { | ||||||
|  |             return response.sendStatus(400); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         console.log('LlamaCpp props request:', request.body); | ||||||
|  |         const baseUrl = trimV1(request.body.server_url); | ||||||
|  |  | ||||||
|  |         const fetchResponse = await fetch(`${baseUrl}/props`, { | ||||||
|  |             method: 'GET', | ||||||
|  |             timeout: 0, | ||||||
|  |         }); | ||||||
|  |  | ||||||
|  |         if (!fetchResponse.ok) { | ||||||
|  |             console.log('LlamaCpp props error:', fetchResponse.status, fetchResponse.statusText); | ||||||
|  |             return response.status(500).send({ error: true }); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         const data = await fetchResponse.json(); | ||||||
|  |         console.log('LlamaCpp props response:', data); | ||||||
|  |  | ||||||
|  |         return response.send(data); | ||||||
|  |  | ||||||
|  |     } catch (error) { | ||||||
|  |         console.error(error); | ||||||
|  |         return response.status(500); | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | llamacpp.post('/slots', jsonParser, async function (request, response) { | ||||||
|  |     try { | ||||||
|  |         if (!request.body.server_url) { | ||||||
|  |             return response.sendStatus(400); | ||||||
|  |         } | ||||||
|  |         if (!/^\d+$/.test(request.body.id_slot)) { | ||||||
|  |             return response.sendStatus(400); | ||||||
|  |         } | ||||||
|  |         if (!/^(erase|restore|save)$/.test(request.body.action)) { | ||||||
|  |             return response.sendStatus(400); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         console.log('LlamaCpp slots request:', request.body); | ||||||
|  |         const baseUrl = trimV1(request.body.server_url); | ||||||
|  |  | ||||||
|  |         const fetchResponse = await fetch(`${baseUrl}/slots/${request.body.id_slot}?action=${request.body.action}`, { | ||||||
|  |             method: 'POST', | ||||||
|  |             headers: { 'Content-Type': 'application/json' }, | ||||||
|  |             timeout: 0, | ||||||
|  |             body: JSON.stringify({ | ||||||
|  |                 filename: `${request.body.filename}`, | ||||||
|  |             }), | ||||||
|  |         }); | ||||||
|  |  | ||||||
|  |         if (!fetchResponse.ok) { | ||||||
|  |             console.log('LlamaCpp slots error:', fetchResponse.status, fetchResponse.statusText); | ||||||
|  |             return response.status(500).send({ error: true }); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         const data = await fetchResponse.json(); | ||||||
|  |         console.log('LlamaCpp slots response:', data); | ||||||
|  |  | ||||||
|  |         return response.send(data); | ||||||
|  |  | ||||||
|  |     } catch (error) { | ||||||
|  |         console.error(error); | ||||||
|  |         return response.status(500); | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  |  | ||||||
| router.use('/ollama', ollama); | router.use('/ollama', ollama); | ||||||
| router.use('/llamacpp', llamacpp); | router.use('/llamacpp', llamacpp); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user