Select Git revision
AdditionalPDFs.py
-
Tobias Quadfasel authored
Some minor bug fixes and re-formatting to PEP8 style. Double-checked that reformatting does not influence results by comparing output of
Tobias Quadfasel authoredSome minor bug fixes and re-formatting to PEP8 style. Double-checked that reformatting does not influence results by comparing output of
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
AI.js 5.33 KiB
import { Ollama } from 'ollama';
import Chat from "../models/Chat.js";
import { aiDeleteModel, aiGetModels, aiGetModel, aiInstallModel, aiIsRunning, summarizeText } from "../utils/handleAI.js";
import { mapStoredMessagesToChatMessages } from "@langchain/core/messages";
import { createRecord, findOneRecord, findRecordByID, findRecords } from '../utils/handleDB.js';
import { prefillDocumentObject } from '../utils/handleSchemes.js';
import { performance } from "node:perf_hooks";
// PROVIDE OLLAMA CONNECTION TO ALL ROUTES
export const ollama = new Ollama({ host: process.env.AI_API_URL });
/** *******************************************************
* CHECK RUNNING
*/
export const getStatus = async (req, res, next) => {
// check if ollama is reachable
const running = await aiIsRunning();
// NOT reachable
if (!running) return res.status(404).json({ running });
// reachable
return res.json({ running });
};
/** *******************************************************
* GET MODELS
*/
export const getModels = async (req, res, next) => {
try {
const foundModels = await aiFilterModelsByName(req.body.filter);
return res.json(foundModels);
} catch (error) {
next(error);
}
};
/** *******************************************************
* GET MODEL
*/
export const getModel = async (req, res, next) => {
try {
const model = await aiGetModel(req.body.model);
return res.json(model);
} catch (error) {
next(error);
}
};
/** *******************************************************
* INSTALL SINGLE
*/
export const installModel = async (req, res, next) => {
try {
const response = await aiInstallModel(req.body.model);
const model = await aiFilterModelsByName(req.body.model);
return res.json({ message: response.message, model });
} catch (error) {
next(error);
}
};
/** *******************************************************
* DELETE SINGLE