mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-04 14:00:11 +01:00
f499f1ba59
* Using OpenAI API locally * Infinite prompt input and compression implementation (#332) * WIP on continuous prompt window summary * wip * Move chat out of VDB simplify chat interface normalize LLM model interface have compression abstraction Cleanup compressor TODO: Anthropic stuff * Implement compression for Anythropic Fix lancedb sources * cleanup vectorDBs and check that lance, chroma, and pinecone are returning valid metadata sources * Resolve Weaviate citation sources not working with schema * comment cleanup * disable import on hosted instances (#339) * disable import on hosted instances * Update UI on disabled import/export --------- Co-authored-by: timothycarambat <rambat1010@gmail.com> * Add support for gpt-4-turbo 128K model (#340) resolves #336 Add support for gpt-4-turbo 128K model * 315 show citations based on relevancy score (#316) * settings for similarity score threshold and prisma schema updated * prisma schema migration for adding similarityScore setting * WIP * Min score default change * added similarityThreshold checking for all vectordb providers * linting --------- Co-authored-by: shatfield4 <seanhatfield5@gmail.com> * rename localai to lmstudio * forgot files that were renamed * normalize model interface * add model and context window limits * update LMStudio tagline * Fully working LMStudio integration --------- Co-authored-by: Francisco Bischoff <984592+franzbischoff@users.noreply.github.com> Co-authored-by: Timothy Carambat <rambat1010@gmail.com> Co-authored-by: Sean Hatfield <seanhatfield5@gmail.com>
180 lines
5.5 KiB
JavaScript
180 lines
5.5 KiB
JavaScript
process.env.NODE_ENV === "development"
|
|
? require("dotenv").config({ path: `.env.${process.env.NODE_ENV}` })
|
|
: require("dotenv").config();
|
|
|
|
const prisma = require("../utils/prisma");
|
|
|
|
const SystemSettings = {
|
|
supportedFields: [
|
|
"multi_user_mode",
|
|
"users_can_delete_workspaces",
|
|
"limit_user_messages",
|
|
"message_limit",
|
|
"logo_filename",
|
|
"telemetry_id",
|
|
],
|
|
currentSettings: async function () {
|
|
const llmProvider = process.env.LLM_PROVIDER || "openai";
|
|
const vectorDB = process.env.VECTOR_DB || "pinecone";
|
|
return {
|
|
CanDebug: !!!process.env.NO_DEBUG,
|
|
RequiresAuth: !!process.env.AUTH_TOKEN,
|
|
AuthToken: !!process.env.AUTH_TOKEN,
|
|
JWTSecret: !!process.env.JWT_SECRET,
|
|
StorageDir: process.env.STORAGE_DIR,
|
|
MultiUserMode: await this.isMultiUserMode(),
|
|
VectorDB: vectorDB,
|
|
EmbeddingEngine: process.env.EMBEDDING_ENGINE,
|
|
...(vectorDB === "pinecone"
|
|
? {
|
|
PineConeEnvironment: process.env.PINECONE_ENVIRONMENT,
|
|
PineConeKey: !!process.env.PINECONE_API_KEY,
|
|
PineConeIndex: process.env.PINECONE_INDEX,
|
|
}
|
|
: {}),
|
|
...(vectorDB === "chroma"
|
|
? {
|
|
ChromaEndpoint: process.env.CHROMA_ENDPOINT,
|
|
ChromaApiHeader: process.env.CHROMA_API_HEADER,
|
|
ChromaApiKey: !!process.env.CHROMA_API_KEY,
|
|
}
|
|
: {}),
|
|
...(vectorDB === "weaviate"
|
|
? {
|
|
WeaviateEndpoint: process.env.WEAVIATE_ENDPOINT,
|
|
WeaviateApiKey: process.env.WEAVIATE_API_KEY,
|
|
}
|
|
: {}),
|
|
...(vectorDB === "qdrant"
|
|
? {
|
|
QdrantEndpoint: process.env.QDRANT_ENDPOINT,
|
|
QdrantApiKey: process.env.QDRANT_API_KEY,
|
|
}
|
|
: {}),
|
|
LLMProvider: llmProvider,
|
|
...(llmProvider === "openai"
|
|
? {
|
|
OpenAiKey: !!process.env.OPEN_AI_KEY,
|
|
OpenAiModelPref: process.env.OPEN_MODEL_PREF || "gpt-3.5-turbo",
|
|
}
|
|
: {}),
|
|
|
|
...(llmProvider === "azure"
|
|
? {
|
|
AzureOpenAiEndpoint: process.env.AZURE_OPENAI_ENDPOINT,
|
|
AzureOpenAiKey: !!process.env.AZURE_OPENAI_KEY,
|
|
AzureOpenAiModelPref: process.env.OPEN_MODEL_PREF,
|
|
AzureOpenAiEmbeddingModelPref: process.env.EMBEDDING_MODEL_PREF,
|
|
AzureOpenAiTokenLimit: process.env.AZURE_OPENAI_TOKEN_LIMIT || 4096,
|
|
}
|
|
: {}),
|
|
|
|
...(llmProvider === "anthropic"
|
|
? {
|
|
AnthropicApiKey: !!process.env.ANTHROPIC_API_KEY,
|
|
AnthropicModelPref: process.env.ANTHROPIC_MODEL_PREF || "claude-2",
|
|
|
|
// For embedding credentials when Anthropic is selected.
|
|
OpenAiKey: !!process.env.OPEN_AI_KEY,
|
|
AzureOpenAiEndpoint: process.env.AZURE_OPENAI_ENDPOINT,
|
|
AzureOpenAiKey: !!process.env.AZURE_OPENAI_KEY,
|
|
AzureOpenAiEmbeddingModelPref: process.env.EMBEDDING_MODEL_PREF,
|
|
}
|
|
: {}),
|
|
|
|
...(llmProvider === "lmstudio"
|
|
? {
|
|
LMStudioBasePath: process.env.LMSTUDIO_BASE_PATH,
|
|
LMStudioTokenLimit: process.env.LMSTUDIO_MODEL_TOKEN_LIMIT,
|
|
|
|
// For embedding credentials when lmstudio is selected.
|
|
OpenAiKey: !!process.env.OPEN_AI_KEY,
|
|
AzureOpenAiEndpoint: process.env.AZURE_OPENAI_ENDPOINT,
|
|
AzureOpenAiKey: !!process.env.AZURE_OPENAI_KEY,
|
|
AzureOpenAiEmbeddingModelPref: process.env.EMBEDDING_MODEL_PREF,
|
|
}
|
|
: {}),
|
|
};
|
|
},
|
|
|
|
get: async function (clause = {}) {
|
|
try {
|
|
const setting = await prisma.system_settings.findFirst({ where: clause });
|
|
return setting || null;
|
|
} catch (error) {
|
|
console.error(error.message);
|
|
return null;
|
|
}
|
|
},
|
|
|
|
where: async function (clause = {}, limit) {
|
|
try {
|
|
const settings = await prisma.system_settings.findMany({
|
|
where: clause,
|
|
take: limit || undefined,
|
|
});
|
|
return settings;
|
|
} catch (error) {
|
|
console.error(error.message);
|
|
return [];
|
|
}
|
|
},
|
|
|
|
updateSettings: async function (updates = {}) {
|
|
try {
|
|
const updatePromises = Object.keys(updates)
|
|
.filter((key) => this.supportedFields.includes(key))
|
|
.map((key) => {
|
|
return prisma.system_settings.upsert({
|
|
where: { label: key },
|
|
update: {
|
|
value: updates[key] === null ? null : String(updates[key]),
|
|
},
|
|
create: {
|
|
label: key,
|
|
value: updates[key] === null ? null : String(updates[key]),
|
|
},
|
|
});
|
|
});
|
|
|
|
await Promise.all(updatePromises);
|
|
return { success: true, error: null };
|
|
} catch (error) {
|
|
console.error("FAILED TO UPDATE SYSTEM SETTINGS", error.message);
|
|
return { success: false, error: error.message };
|
|
}
|
|
},
|
|
|
|
isMultiUserMode: async function () {
|
|
try {
|
|
const setting = await this.get({ label: "multi_user_mode" });
|
|
return setting?.value === "true";
|
|
} catch (error) {
|
|
console.error(error.message);
|
|
return false;
|
|
}
|
|
},
|
|
|
|
currentLogoFilename: async function () {
|
|
try {
|
|
const setting = await this.get({ label: "logo_filename" });
|
|
return setting?.value || null;
|
|
} catch (error) {
|
|
console.error(error.message);
|
|
return null;
|
|
}
|
|
},
|
|
|
|
canDeleteWorkspaces: async function () {
|
|
try {
|
|
const setting = await this.get({ label: "users_can_delete_workspaces" });
|
|
return setting?.value === "true";
|
|
} catch (error) {
|
|
console.error(error.message);
|
|
return false;
|
|
}
|
|
},
|
|
};
|
|
|
|
module.exports.SystemSettings = SystemSettings;
|