@summarisation/summarise
Version:
cli for summariser
65 lines (64 loc) • 3.12 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.addValidateCommand = void 0;
const node_fs_1 = __importDefault(require("node:fs"));
const openai_1 = require("@summarisation/openai");
function addValidateCommand(tc) {
return {
cmd: 'validate',
description: `Validates the configuration file`,
options: {},
action: async () => {
async function validateDirectories(dirs) {
async function directory(name, words) {
try {
await node_fs_1.default.promises.access(dirs[name]);
console.log(` ${name.padEnd(10)} ${dirs[name].padEnd(30)} -- ok`);
}
catch (e) {
console.log(` ${name.padEnd(10)} ${dirs[name].padEnd(30)} -- ${words}`);
}
}
console.log('Directories');
await directory('inputs', 'does not exist. This needs is where you put the data to be summarised, so nothing works without this');
await directory('tika', 'does not exist. It should be created when you `summarise summary`');
await directory('text', 'does not exist. It should be created when you `summarise summary`');
await directory('summary', 'does not exist. It should be created when you `summarise summary`');
}
async function validateOpenAiConnectivity(env, ai) {
console.log('ai');
let problem = !env[ai.token];
if (problem)
console.log(` ${ai.token} is not set in the environment`);
else
console.log(` ${ai.token} is set in the environment`);
try {
const { axios, addAxiosInterceptors } = tc.context;
await (0, openai_1.openAiClient)((0, openai_1.defaultOpenAiConfig)(ai.url, env[ai.token], ai.model, axios, addAxiosInterceptors))([{ role: 'system', content: 'test' }]);
console.log(` ${ai.url} is reachable`);
}
catch (e) {
console.log(` ${ai.url} is not reachable`);
console.log(` error is`, e);
}
}
await validateDirectories(tc.config.directories);
async function validateTika(tika) {
console.log('tika');
try {
await node_fs_1.default.promises.access(tika.jar);
console.log(` ${tika.jar} exists`);
}
catch (e) {
console.log(` ${tika.jar} does not exist`);
}
}
await validateTika(tc.config.tika);
await validateOpenAiConnectivity(tc.context.env, tc.config.ai);
}
};
}
exports.addValidateCommand = addValidateCommand;