Refactor Class Name Logging (#4426)

* Add className property to various LLM and embedder classes to fix logging bug after minification

* Fix bug with this.log method by applying the missing private field symbol
This commit is contained in:
Marcello Fitton 2025-09-25 18:34:19 -07:00 committed by GitHub
parent 473ff9068a
commit 6855bbf695
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
30 changed files with 60 additions and 30 deletions

View File

@ -15,6 +15,7 @@ class AnthropicLLM {
if (!process.env.ANTHROPIC_API_KEY)
throw new Error("No Anthropic API key was set.");
this.className = "AnthropicLLM";
// Docs: https://www.npmjs.com/package/@anthropic-ai/sdk
const AnthropicAI = require("@anthropic-ai/sdk");
const anthropic = new AnthropicAI({
@ -37,7 +38,7 @@ class AnthropicLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
streamingEnabled() {

View File

@ -23,6 +23,7 @@ class ApiPieLLM {
if (!process.env.APIPIE_LLM_API_KEY)
throw new Error("No ApiPie LLM API key was set.");
this.className = "ApiPieLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.basePath = "https://apipie.ai/v1";
this.openai = new OpenAIApi({
@ -49,7 +50,7 @@ class ApiPieLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
// This checks if the .cached_at file has a timestamp that is more than 1Week (in millis)

View File

@ -24,6 +24,7 @@ class CometApiLLM {
if (!process.env.COMETAPI_LLM_API_KEY)
throw new Error("No CometAPI API key was set.");
this.className = "CometApiLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.basePath = "https://api.cometapi.com/v1";
this.openai = new OpenAIApi({
@ -55,7 +56,7 @@ class CometApiLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
/**

View File

@ -13,6 +13,7 @@ class DeepSeekLLM {
constructor(embedder = null, modelPreference = null) {
if (!process.env.DEEPSEEK_API_KEY)
throw new Error("No DeepSeek API key was set.");
this.className = "DeepSeekLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.openai = new OpenAIApi({
@ -35,7 +36,7 @@ class DeepSeekLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
#appendContext(contextTexts = []) {

View File

@ -13,6 +13,7 @@ class DellProAiStudioLLM {
if (!process.env.DPAIS_LLM_BASE_PATH)
throw new Error("No Dell Pro AI Studio Base Path was set.");
this.className = "DellProAiStudioLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.dpais = new OpenAIApi({
baseURL: DellProAiStudioLLM.parseBasePath(),
@ -50,7 +51,7 @@ class DellProAiStudioLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
#appendContext(contextTexts = []) {

View File

@ -29,6 +29,7 @@ class GeminiLLM {
if (!process.env.GEMINI_API_KEY)
throw new Error("No Gemini API key was set.");
this.className = "GeminiLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.model =
modelPreference ||
@ -71,7 +72,7 @@ class GeminiLLM {
}
#log(text, ...args) {
console.log(`\x1b[32m[GeminiLLM]\x1b[0m ${text}`, ...args);
console.log(`\x1b[32m[${this.className}]\x1b[0m ${text}`, ...args);
}
// This checks if the .cached_at file has a timestamp that is more than 1Week (in millis)

View File

@ -18,6 +18,7 @@ class GenericOpenAiLLM {
"GenericOpenAI must have a valid base path to use for the api."
);
this.className = "GenericOpenAiLLM";
this.basePath = process.env.GENERIC_OPEN_AI_BASE_PATH;
this.openai = new OpenAIApi({
baseURL: this.basePath,
@ -45,7 +46,7 @@ class GenericOpenAiLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
#appendContext(contextTexts = []) {

View File

@ -17,6 +17,7 @@ class KoboldCPPLLM {
"KoboldCPP must have a valid base path to use for the api."
);
this.className = "KoboldCPPLLM";
this.basePath = process.env.KOBOLD_CPP_BASE_PATH;
this.openai = new OpenAIApi({
baseURL: this.basePath,
@ -37,7 +38,7 @@ class KoboldCPPLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
#appendContext(contextTexts = []) {

View File

@ -15,6 +15,7 @@ class LiteLLM {
"LiteLLM must have a valid base path to use for the api."
);
this.className = "LiteLLM";
this.basePath = process.env.LITE_LLM_BASE_PATH;
this.openai = new OpenAIApi({
baseURL: this.basePath,
@ -35,7 +36,7 @@ class LiteLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
#appendContext(contextTexts = []) {

View File

@ -12,6 +12,7 @@ class MistralLLM {
if (!process.env.MISTRAL_API_KEY)
throw new Error("No Mistral API key was set.");
this.className = "MistralLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.openai = new OpenAIApi({
baseURL: "https://api.mistral.ai/v1",
@ -31,7 +32,7 @@ class MistralLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
#appendContext(contextTexts = []) {

View File

@ -12,6 +12,7 @@ class MoonshotAiLLM {
constructor(embedder = null, modelPreference = null) {
if (!process.env.MOONSHOT_AI_API_KEY)
throw new Error("No Moonshot AI API key was set.");
this.className = "MoonshotAiLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.openai = new OpenAIApi({
@ -36,7 +37,7 @@ class MoonshotAiLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
#appendContext(contextTexts = []) {

View File

@ -24,6 +24,7 @@ class NovitaLLM {
if (!process.env.NOVITA_LLM_API_KEY)
throw new Error("No Novita API key was set.");
this.className = "NovitaLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.basePath = "https://api.novita.ai/v3/openai";
this.openai = new OpenAIApi({
@ -57,7 +58,7 @@ class NovitaLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
/**

View File

@ -12,6 +12,7 @@ class NvidiaNimLLM {
if (!process.env.NVIDIA_NIM_LLM_BASE_PATH)
throw new Error("No NVIDIA NIM API Base Path was set.");
this.className = "NvidiaNimLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.nvidiaNim = new OpenAIApi({
baseURL: parseNvidiaNimBasePath(process.env.NVIDIA_NIM_LLM_BASE_PATH),
@ -33,7 +34,7 @@ class NvidiaNimLLM {
}
#log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
#appendContext(contextTexts = []) {

View File

@ -13,6 +13,7 @@ const {
class OpenAiLLM {
constructor(embedder = null, modelPreference = null) {
if (!process.env.OPEN_AI_KEY) throw new Error("No OpenAI API key was set.");
this.className = "OpenAiLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.openai = new OpenAIApi({
@ -33,7 +34,7 @@ class OpenAiLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
#appendContext(contextTexts = []) {

View File

@ -32,6 +32,7 @@ class OpenRouterLLM {
if (!process.env.OPENROUTER_API_KEY)
throw new Error("No OpenRouter API key was set.");
this.className = "OpenRouterLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.basePath = "https://openrouter.ai/api/v1";
this.openai = new OpenAIApi({
@ -88,7 +89,7 @@ class OpenRouterLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
/**

View File

@ -18,6 +18,7 @@ class PPIOLLM {
constructor(embedder = null, modelPreference = null) {
if (!process.env.PPIO_API_KEY) throw new Error("No PPIO API key was set.");
this.className = "PPIOLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.basePath = "https://api.ppinfra.com/v3/openai/";
this.openai = new OpenAIApi({
@ -50,7 +51,7 @@ class PPIOLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
async #syncModels() {

View File

@ -15,6 +15,7 @@ class TextGenWebUILLM {
"TextGenWebUI must have a valid base path to use for the api."
);
this.className = "TextGenWebUILLM";
this.basePath = process.env.TEXT_GEN_WEB_UI_BASE_PATH;
this.openai = new OpenAIApi({
baseURL: this.basePath,
@ -33,7 +34,7 @@ class TextGenWebUILLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
#appendContext(contextTexts = []) {

View File

@ -12,6 +12,7 @@ class XAiLLM {
constructor(embedder = null, modelPreference = null) {
if (!process.env.XAI_LLM_API_KEY)
throw new Error("No xAI API key was set.");
this.className = "XAiLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.openai = new OpenAIApi({
@ -34,7 +35,7 @@ class XAiLLM {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
#appendContext(contextTexts = []) {

View File

@ -8,6 +8,7 @@ class AzureOpenAiEmbedder {
if (!process.env.AZURE_OPENAI_KEY)
throw new Error("No Azure API key was set.");
this.className = "AzureOpenAiEmbedder";
this.apiVersion = "2024-12-01-preview";
const openai = new AzureOpenAI({
apiKey: process.env.AZURE_OPENAI_KEY,
@ -29,7 +30,7 @@ class AzureOpenAiEmbedder {
}
log(text, ...args) {
console.log(`\x1b[36m[AzureOpenAiEmbedder]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
async embedTextInput(textInput) {

View File

@ -11,6 +11,7 @@ class GeminiEmbedder {
if (!process.env.GEMINI_EMBEDDING_API_KEY)
throw new Error("No Gemini API key was set.");
this.className = "GeminiEmbedder";
const { OpenAI: OpenAIApi } = require("openai");
this.model = process.env.EMBEDDING_MODEL_PREF || "text-embedding-004";
this.openai = new OpenAIApi({
@ -29,7 +30,7 @@ class GeminiEmbedder {
}
log(text, ...args) {
console.log(`\x1b[36m[GeminiEmbedder]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
/**

View File

@ -6,6 +6,7 @@ class GenericOpenAiEmbedder {
throw new Error(
"GenericOpenAI must have a valid base path to use for the api."
);
this.className = "GenericOpenAiEmbedder";
const { OpenAI: OpenAIApi } = require("openai");
this.basePath = process.env.EMBEDDING_BASE_PATH;
this.openai = new OpenAIApi({
@ -25,7 +26,7 @@ class GenericOpenAiEmbedder {
}
log(text, ...args) {
console.log(`\x1b[36m[GenericOpenAiEmbedder]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
/**

View File

@ -8,6 +8,7 @@ class LMStudioEmbedder {
if (!process.env.EMBEDDING_MODEL_PREF)
throw new Error("No embedding model was set.");
this.className = "LMStudioEmbedder";
const { OpenAI: OpenAIApi } = require("openai");
this.lmstudio = new OpenAIApi({
baseURL: parseLMStudioBasePath(process.env.EMBEDDING_BASE_PATH),
@ -21,7 +22,7 @@ class LMStudioEmbedder {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
async #isAlive() {

View File

@ -30,6 +30,7 @@ class NativeEmbedder {
#fallbackHost = "https://cdn.anythingllm.com/support/models/";
constructor() {
this.className = "NativeEmbedder";
this.model = this.getEmbeddingModel();
this.modelInfo = this.getEmbedderInfo();
this.cacheDir = path.resolve(
@ -50,7 +51,7 @@ class NativeEmbedder {
}
log(text, ...args) {
console.log(`\x1b[36m[NativeEmbedder]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
/**

View File

@ -8,6 +8,7 @@ class OllamaEmbedder {
if (!process.env.EMBEDDING_MODEL_PREF)
throw new Error("No embedding model was set.");
this.className = "OllamaEmbedder";
this.basePath = process.env.EMBEDDING_BASE_PATH;
this.model = process.env.EMBEDDING_MODEL_PREF;
// Limit of how many strings we can process in a single pass to stay with resource or network limits
@ -20,7 +21,7 @@ class OllamaEmbedder {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
/**

View File

@ -3,6 +3,7 @@ const { toChunks } = require("../../helpers");
class OpenAiEmbedder {
constructor() {
if (!process.env.OPEN_AI_KEY) throw new Error("No OpenAI API key was set.");
this.className = "OpenAiEmbedder";
const { OpenAI: OpenAIApi } = require("openai");
this.openai = new OpenAIApi({
apiKey: process.env.OPEN_AI_KEY,
@ -17,7 +18,7 @@ class OpenAiEmbedder {
}
log(text, ...args) {
console.log(`\x1b[36m[OpenAiEmbedder]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
async embedTextInput(textInput) {

View File

@ -53,6 +53,7 @@ class MCPHypervisor {
constructor() {
if (MCPHypervisor._instance) return MCPHypervisor._instance;
MCPHypervisor._instance = this;
this.className = "MCPHypervisor";
this.log("Initializing MCP Hypervisor - subsequent calls will boot faster");
this.#setupConfigFile();
return this;
@ -88,7 +89,7 @@ class MCPHypervisor {
}
log(text, ...args) {
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
/**

View File

@ -28,6 +28,7 @@ class MSSQLConnector {
connectionString: null, // we will force into RFC-3986
}
) {
this.className = "MSSQLConnector";
this.connectionString = config.connectionString;
this._client = null;
this.#parseDatabase();
@ -72,7 +73,7 @@ class MSSQLConnector {
result.rows = query.recordset;
result.count = query.rowsAffected.reduce((sum, a) => sum + a, 0);
} catch (err) {
console.log(this.constructor.name, err);
console.log(this.className, err);
result.error = err.message;
} finally {
// Check client is connected before closing since we use this for validation

View File

@ -9,6 +9,7 @@ class MySQLConnector {
connectionString: null,
}
) {
this.className = "MySQLConnector";
this.connectionString = config.connectionString;
this._client = null;
this.database_id = this.#parseDatabase();
@ -39,7 +40,7 @@ class MySQLConnector {
result.rows = query;
result.count = query?.length;
} catch (err) {
console.log(this.constructor.name, err);
console.log(this.className, err);
result.error = err.message;
} finally {
// Check client is connected before closing since we use this for validation

View File

@ -8,6 +8,7 @@ class PostgresSQLConnector {
schema: null,
}
) {
this.className = "PostgresSQLConnector";
this.connectionString = config.connectionString;
this.schema = config.schema || "public";
this._client = new pgSql.Client({
@ -34,7 +35,7 @@ class PostgresSQLConnector {
result.rows = query.rows;
result.count = query.rowCount;
} catch (err) {
console.log(this.constructor.name, err);
console.log(this.className, err);
result.error = err.message;
} finally {
// Check client is connected before closing since we use this for validation

View File

@ -17,6 +17,7 @@ class GeminiProvider extends InheritMultiple([Provider, UnTooled]) {
constructor(config = {}) {
const { model = "gemini-2.0-flash-lite" } = config;
super();
this.className = "GeminiProvider";
const client = new OpenAI({
baseURL: "https://generativelanguage.googleapis.com/v1beta/openai/",
apiKey: process.env.GEMINI_API_KEY,
@ -134,7 +135,7 @@ class GeminiProvider extends InheritMultiple([Provider, UnTooled]) {
} catch (error) {
throw new APIError(
error?.message
? `${this.constructor.name} encountered an error while executing the request: ${error.message}`
? `${this.className} encountered an error while executing the request: ${error.message}`
: "There was an error with the Gemini provider executing the request"
);
}