Add some llama.cpp-specific endpoints

This commit is contained in:
sasha0552 2024-04-10 08:11:59 +00:00 committed by GitHub
parent 0783264900
commit becd17d7d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 70 additions and 0 deletions

View File

@ -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);