Skip to content
Snippets Groups Projects
Select Git revision
  • dev/test_tobias
  • main default protected
  • sumlab
  • jack.rolph-main-patch-16563
  • jack.rolph-main-patch-96201
  • jack.rolph-main-patch-18340
  • jack.rolph-main-patch-15793
  • jack.rolph-main-patch-74592
  • 1.0.0
9 results

AdditionalPDFs.py

Blame
  • 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