Skip to content
Snippets Groups Projects
Commit 1a0d08e1 authored by Embruch, Gerd's avatar Embruch, Gerd
Browse files

fixed some things for the frontend

parent 9c852fae
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,41 @@ exports[`ai pull model > given required fields are missing > should respond with ...@@ -35,6 +35,41 @@ exports[`ai pull model > given required fields are missing > should respond with
exports[`ai pull model > given the inputs are valid > should respond with a proper body 1`] = ` exports[`ai pull model > given the inputs are valid > should respond with a proper body 1`] = `
{ {
"status": "success", "model": [
{
"details": {
"families": [
"llama",
],
"family": "llama",
"format": "gguf",
"parameter_size": "8.0B",
"parent_model": "",
"quantization_level": "Q4_0",
},
"digest": "62757c860e01d552d4e46b09c6b8d5396ef9015210105427e05a8b27d7727ed2",
"model": "llama3.1:latest",
"modified_at": "2024-08-05T18:15:28.145879883+02:00",
"name": "llama3.1:latest",
"size": 4661226402,
},
{
"details": {
"families": [
"llama",
],
"family": "llama",
"format": "gguf",
"parameter_size": "8.0B",
"parent_model": "",
"quantization_level": "Q4_0",
},
"digest": "365c0bd3c000a25d28ddbf732fe1c6add414de7275464c4e4d1c3b5fcb5d8ad1",
"model": "llama3:latest",
"modified_at": "2024-08-05T12:11:53.562412228+02:00",
"name": "llama3:latest",
"size": 4661224676,
},
],
} }
`; `;
...@@ -57,7 +57,9 @@ export const getModel = async (req, res, next) => { ...@@ -57,7 +57,9 @@ export const getModel = async (req, res, next) => {
export const installModel = async (req, res, next) => { export const installModel = async (req, res, next) => {
try { try {
const response = await aiInstallModel(req.body.model); const response = await aiInstallModel(req.body.model);
return res.json(response); const model = await aiFilterModelsByName(req.body.model);
return res.json({ message: response.message, model });
} catch (error) { } catch (error) {
next(error); next(error);
} }
......
...@@ -76,7 +76,7 @@ export const removeVectorDb = async (req, res, next) => { ...@@ -76,7 +76,7 @@ export const removeVectorDb = async (req, res, next) => {
} }
// exit if collection don't exist // exit if collection don't exist
if (! await isCollectionAvailable()) { if (! await isCollectionAvailable()) {
return res.status(404).json({ error: `VectorDB collection ${process.env['VECTOR_COLLECTION_NAME']} not found.` }); return res.status(404).json({ message: `VectorDB collection ${process.env['VECTOR_COLLECTION_NAME']} not found.` });
} }
// delete collection // delete collection
...@@ -111,40 +111,15 @@ export const getStatus = async (req, res, next) => { ...@@ -111,40 +111,15 @@ export const getStatus = async (req, res, next) => {
return res.json({ vectorDBrunning, collection, itemCount }); return res.json({ vectorDBrunning, collection, itemCount });
}; };
/** *******************************************************
* CREATE EMBEDDINGS
*/
export const createEmbeddings = async (req, res) => {
// check if collection is available
const collection = await isCollectionAvailable();
if (!collection) {
return res.status(500).json({ error: `VectorDB collection ${process.env['VECTOR_COLLECTION_NAME']} not found.` });
}
// test if model is available
const models = await aiFilterModelsByName(process.env['RAG_MODEL_NAME']);
// install model if missing
if (!models.length) {
console.info('Embedding Model not found. Installing ...');
await ollama.pull({ model: process.env['RAG_MODEL_NAME'] });
}
// console.log('collection count BEFORE', await collection.count());
// load RAG files
const docs = await directoryLoader();
// embed
const loadedDocs = await embedder(docs);
// console.log('collection count AFTER', await collection.count());
return res.json({ 'message': 'Embeddings created.' });
};
/** ******************************************************* /** *******************************************************
* UPDATE EMBEDDINGS * UPDATE EMBEDDINGS
*/ */
export const updateEmbeddings = async (req, res, next) => { export const updateEmbeddings = async (req, res, next) => {
// check if collection is available // check if collection is available
const collection = await isCollectionAvailable(); let collection = await isCollectionAvailable();
if (!collection) { if (!collection) {
return res.status(500).json({ error: `VectorDB collection ${process.env['VECTOR_COLLECTION_NAME']} not found.` }); // return res.status(500).json({ message: `VectorDB collection ${process.env['VECTOR_COLLECTION_NAME']} not found.` });
collection = await createCollection();
} }
// ################# // #################
......
...@@ -82,6 +82,7 @@ router.delete('/models', verifyAccessToken, gateKeeper, validate(deleteModelSche ...@@ -82,6 +82,7 @@ router.delete('/models', verifyAccessToken, gateKeeper, validate(deleteModelSche
* *
* @return {object} AI response & chat history record * @return {object} AI response & chat history record
*/ */
// TODO add cross encoder / reranker
router.post('/chat', verifyAccessToken, validate(chatSchema), checkRequestedModel, getChat, chat); router.post('/chat', verifyAccessToken, validate(chatSchema), checkRequestedModel, getChat, chat);
...@@ -91,6 +92,7 @@ router.post('/chat', verifyAccessToken, validate(chatSchema), checkRequestedMode ...@@ -91,6 +92,7 @@ router.post('/chat', verifyAccessToken, validate(chatSchema), checkRequestedMode
* @header {authorization} Bearer [required] access token * @header {authorization} Bearer [required] access token
* @return {object} list of found conversations, ordered by updated * @return {object} list of found conversations, ordered by updated
*/ */
// TODO sort chats by createdAt
router.get('/chats', verifyAccessToken, getChats); router.get('/chats', verifyAccessToken, getChats);
export default router; export default router;
\ No newline at end of file
...@@ -13,6 +13,7 @@ const router = Router(); ...@@ -13,6 +13,7 @@ const router = Router();
* *
* @return {object} related message * @return {object} related message
*/ */
// BUG after deletion and restoring, collection is not found till restart
router.delete('/', verifyAccessToken, gateKeeper, removeVectorDb); router.delete('/', verifyAccessToken, gateKeeper, removeVectorDb);
/** /**
......
...@@ -53,7 +53,8 @@ export const aiGetModel = async (model) => { ...@@ -53,7 +53,8 @@ export const aiGetModel = async (model) => {
*/ */
export const aiInstallModel = async (model) => { export const aiInstallModel = async (model) => {
try { try {
return await ollama.pull({ model, stream: false }); const message = await ollama.pull({ model, stream: false });
return { message: `model ${model} installed` };
} catch (error) { } catch (error) {
throw error; throw error;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment