File size: 4,826 Bytes
f8b5d42 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
const { SystemSettings } = require("../models/systemSettings");
function utilEndpoints(app) {
if (!app) return;
app.get("/utils/metrics", async (_, response) => {
try {
const metrics = {
online: true,
version: getGitVersion(),
mode: (await SystemSettings.isMultiUserMode())
? "multi-user"
: "single-user",
vectorDB: process.env.VECTOR_DB || "lancedb",
storage: await getDiskStorage(),
appVersion: getDeploymentVersion(),
};
response.status(200).json(metrics);
} catch (e) {
console.error(e);
response.sendStatus(500).end();
}
});
}
function getGitVersion() {
if (process.env.ANYTHING_LLM_RUNTIME === "docker") return "--";
try {
return require("child_process")
.execSync("git rev-parse HEAD")
.toString()
.trim();
} catch (e) {
console.error("getGitVersion", e.message);
return "--";
}
}
function byteToGigaByte(n) {
return n / Math.pow(10, 9);
}
async function getDiskStorage() {
try {
const checkDiskSpace = require("check-disk-space").default;
const { free, size } = await checkDiskSpace("/");
return {
current: Math.floor(byteToGigaByte(free)),
capacity: Math.floor(byteToGigaByte(size)),
};
} catch {
return {
current: null,
capacity: null,
};
}
}
/**
* Returns the model tag based on the provider set in the environment.
* This information is used to identify the parent model for the system
* so that we can prioritize the correct model and types for future updates
* as well as build features in AnythingLLM directly for a specific model or capabilities.
*
* Disable with {@link https://github.com/Mintplex-Labs/anything-llm?tab=readme-ov-file#telemetry--privacy|Disable Telemetry}
* @returns {string} The model tag.
*/
function getModelTag() {
let model = null;
const provider = process.env.LLM_PROVIDER;
switch (provider) {
case "openai":
model = process.env.OPEN_MODEL_PREF;
break;
case "anthropic":
model = process.env.ANTHROPIC_MODEL_PREF;
break;
case "lmstudio":
model = process.env.LMSTUDIO_MODEL_PREF;
break;
case "ollama":
model = process.env.OLLAMA_MODEL_PREF;
break;
case "groq":
model = process.env.GROQ_MODEL_PREF;
break;
case "togetherai":
model = process.env.TOGETHER_AI_MODEL_PREF;
break;
case "azure":
model = process.env.OPEN_MODEL_PREF;
break;
case "koboldcpp":
model = process.env.KOBOLD_CPP_MODEL_PREF;
break;
case "localai":
model = process.env.LOCAL_AI_MODEL_PREF;
break;
case "openrouter":
model = process.env.OPENROUTER_MODEL_PREF;
break;
case "mistral":
model = process.env.MISTRAL_MODEL_PREF;
break;
case "generic-openai":
model = process.env.GENERIC_OPEN_AI_MODEL_PREF;
break;
case "perplexity":
model = process.env.PERPLEXITY_MODEL_PREF;
break;
case "textgenwebui":
model = "textgenwebui-default";
break;
case "bedrock":
model = process.env.AWS_BEDROCK_LLM_MODEL_PREFERENCE;
break;
case "fireworksai":
model = process.env.FIREWORKS_AI_LLM_MODEL_PREF;
break;
case "deepseek":
model = process.env.DEEPSEEK_MODEL_PREF;
break;
case "litellm":
model = process.env.LITE_LLM_MODEL_PREF;
break;
case "apipie":
model = process.env.APIPIE_LLM_MODEL_PREF;
break;
case "xai":
model = process.env.XAI_LLM_MODEL_PREF;
break;
case "novita":
model = process.env.NOVITA_LLM_MODEL_PREF;
break;
case "nvidia-nim":
model = process.env.NVIDIA_NIM_LLM_MODEL_PREF;
break;
case "ppio":
model = process.env.PPIO_MODEL_PREF;
break;
case "gemini":
model = process.env.GEMINI_LLM_MODEL_PREF;
break;
case "moonshotai":
model = process.env.MOONSHOT_AI_MODEL_PREF;
break;
default:
model = "--";
break;
}
return model;
}
/**
* Returns the deployment version.
* - Dev: reads from package.json
* - Prod: reads from ENV
* expected format: major.minor.patch
* @returns {string|null} The deployment version.
*/
function getDeploymentVersion() {
if (process.env.NODE_ENV === "development")
return require("../../package.json").version;
if (process.env.DEPLOYMENT_VERSION) return process.env.DEPLOYMENT_VERSION;
return null;
}
/**
* Returns the user agent for the AnythingLLM deployment.
* @returns {string} The user agent.
*/
function getAnythingLLMUserAgent() {
const version = getDeploymentVersion() || "unknown";
return `AnythingLLM/${version}`;
}
module.exports = {
utilEndpoints,
getGitVersion,
getModelTag,
getAnythingLLMUserAgent,
};
|