code stringlengths 28 313k | docstring stringlengths 25 85.3k | func_name stringlengths 1 74 | language stringclasses 1
value | repo stringlengths 5 60 | path stringlengths 4 172 | url stringlengths 44 218 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
static getAllFlows() {
AgentFlows.createOrCheckFlowsDir();
const files = fs.readdirSync(AgentFlows.flowsDir);
const flows = {};
for (const file of files) {
if (!file.endsWith(".json")) continue;
try {
const filePath = path.join(AgentFlows.flowsDir, file);
const content = fs.... | Helper to get all flow files with their contents
@returns {Object} Map of flow UUID to flow config | getAllFlows | javascript | Mintplex-Labs/anything-llm | server/utils/agentFlows/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agentFlows/index.js | MIT |
static loadFlow(uuid) {
try {
const flowJsonPath = normalizePath(
path.join(AgentFlows.flowsDir, `${uuid}.json`)
);
if (!uuid || !fs.existsSync(flowJsonPath)) return null;
const flow = safeJsonParse(fs.readFileSync(flowJsonPath, "utf8"), null);
if (!flow) return null;
re... | Load a flow configuration by UUID
@param {string} uuid - The UUID of the flow to load
@returns {LoadedFlow|null} Flow configuration or null if not found | loadFlow | javascript | Mintplex-Labs/anything-llm | server/utils/agentFlows/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agentFlows/index.js | MIT |
static saveFlow(name, config, uuid = null) {
try {
AgentFlows.createOrCheckFlowsDir();
if (!uuid) uuid = uuidv4();
const normalizedUuid = normalizePath(`${uuid}.json`);
const filePath = path.join(AgentFlows.flowsDir, normalizedUuid);
// Prevent saving flows with unsupported blocks or... | Save a flow configuration
@param {string} name - The name of the flow
@param {Object} config - The flow configuration
@param {string|null} uuid - Optional UUID for the flow
@returns {Object} Result of the save operation | saveFlow | javascript | Mintplex-Labs/anything-llm | server/utils/agentFlows/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agentFlows/index.js | MIT |
static listFlows() {
try {
const flows = AgentFlows.getAllFlows();
return Object.entries(flows).map(([uuid, flow]) => ({
name: flow.name,
uuid,
description: flow.description,
active: flow.active !== false,
}));
} catch (error) {
console.error("Failed to li... | List all available flows
@returns {Array} Array of flow summaries | listFlows | javascript | Mintplex-Labs/anything-llm | server/utils/agentFlows/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agentFlows/index.js | MIT |
static deleteFlow(uuid) {
try {
const filePath = normalizePath(
path.join(AgentFlows.flowsDir, `${uuid}.json`)
);
if (!fs.existsSync(filePath)) throw new Error(`Flow ${uuid} not found`);
fs.rmSync(filePath);
return { success: true };
} catch (error) {
console.error("F... | Delete a flow by UUID
@param {string} uuid - The UUID of the flow to delete
@returns {Object} Result of the delete operation | deleteFlow | javascript | Mintplex-Labs/anything-llm | server/utils/agentFlows/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agentFlows/index.js | MIT |
static async executeFlow(uuid, variables = {}, aibitat = null) {
const flow = AgentFlows.loadFlow(uuid);
if (!flow) throw new Error(`Flow ${uuid} not found`);
const flowExecutor = new FlowExecutor();
return await flowExecutor.executeFlow(flow, variables, aibitat);
} | Execute a flow by UUID
@param {string} uuid - The UUID of the flow to execute
@param {Object} variables - Initial variables for the flow
@param {Object} aibitat - The aibitat instance from the agent handler
@returns {Promise<Object>} Result of flow execution | executeFlow | javascript | Mintplex-Labs/anything-llm | server/utils/agentFlows/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agentFlows/index.js | MIT |
static activeFlowPlugins() {
const flows = AgentFlows.getAllFlows();
return Object.entries(flows)
.filter(([_, flow]) => flow.active !== false)
.map(([uuid]) => `@@flow_${uuid}`);
} | Get all active flows as plugins that can be loaded into the agent
@returns {string[]} Array of flow names in @@flow_{uuid} format | activeFlowPlugins | javascript | Mintplex-Labs/anything-llm | server/utils/agentFlows/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agentFlows/index.js | MIT |
static loadFlowPlugin(uuid) {
const flow = AgentFlows.loadFlow(uuid);
if (!flow) return null;
const startBlock = flow.config.steps?.find((s) => s.type === "start");
const variables = startBlock?.config?.variables || [];
return {
name: `flow_${uuid}`,
description: `Execute agent flow: $... | Load a flow plugin by its UUID
@param {string} uuid - The UUID of the flow to load
@returns {Object|null} Plugin configuration or null if not found | loadFlowPlugin | javascript | Mintplex-Labs/anything-llm | server/utils/agentFlows/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agentFlows/index.js | MIT |
static stringifyResult(input) {
return typeof input === "object" ? JSON.stringify(input) : String(input);
} | Stringify the result of a flow execution or return the input as is
@param {Object|string} input - The result to stringify
@returns {string} The stringified result | stringifyResult | javascript | Mintplex-Labs/anything-llm | server/utils/agentFlows/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agentFlows/index.js | MIT |
async function executeApiCall(config, context) {
const { url, method, headers = [], body, bodyType, formData } = config;
const { introspect, logger } = context;
logger(`\x1b[43m[AgentFlowToolExecutor]\x1b[0m - executing API Call block`);
introspect(`Making ${method} request to external API...`);
const reques... | Execute an API call flow step
@param {Object} config Flow step configuration
@param {Object} context Execution context with introspect function
@returns {Promise<string>} Response data | executeApiCall | javascript | Mintplex-Labs/anything-llm | server/utils/agentFlows/executors/api-call.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agentFlows/executors/api-call.js | MIT |
async function executeLLMInstruction(config, context) {
const { instruction, resultVariable } = config;
const { introspect, logger, aibitat } = context;
logger(
`\x1b[43m[AgentFlowToolExecutor]\x1b[0m - executing LLM Instruction block`
);
introspect(`Processing data with LLM instruction...`);
try {
... | Execute an LLM instruction flow step
@param {Object} config Flow step configuration
@param {{introspect: Function, logger: Function}} context Execution context with introspect function
@returns {Promise<string>} Processed result | executeLLMInstruction | javascript | Mintplex-Labs/anything-llm | server/utils/agentFlows/executors/llm-instruction.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agentFlows/executors/llm-instruction.js | MIT |
async function executeWebScraping(config, context) {
const { CollectorApi } = require("../../collectorApi");
const { TokenManager } = require("../../helpers/tiktoken");
const Provider = require("../../agents/aibitat/providers/ai-provider");
const { summarizeContent } = require("../../agents/aibitat/utils/summar... | Execute a web scraping flow step
@param {Object} config Flow step configuration
@param {Object} context Execution context with introspect function
@returns {Promise<string>} Scraped content | executeWebScraping | javascript | Mintplex-Labs/anything-llm | server/utils/agentFlows/executors/web-scraping.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agentFlows/executors/web-scraping.js | MIT |
function parseHTMLwithSelector(html, selector = null, context) {
if (!selector || selector.length === 0) {
context.introspect("No selector provided. Returning the entire HTML.");
return { success: true, content: html };
}
const Cheerio = require("cheerio");
const $ = Cheerio.load(html);
const selecte... | Parse HTML with a CSS selector
@param {string} html - The HTML to parse
@param {string|null} selector - The CSS selector to use (as text string)
@param {{introspect: Function}} context - The context object
@returns {Object} The parsed content | parseHTMLwithSelector | javascript | Mintplex-Labs/anything-llm | server/utils/agentFlows/executors/web-scraping.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agentFlows/executors/web-scraping.js | MIT |
async function agentSkillsFromSystemSettings() {
const systemFunctions = [];
// Load non-imported built-in skills that are configurable, but are default enabled.
const _disabledDefaultSkills = safeJsonParse(
await SystemSettings.getValueOrFallback(
{ label: "disabled_agent_skills" },
"[]"
),
... | Fetches and preloads the names/identifiers for plugins that will be dynamically
loaded later
@returns {Promise<string[]>} | agentSkillsFromSystemSettings | javascript | Mintplex-Labs/anything-llm | server/utils/agents/defaults.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/defaults.js | MIT |
constructor({
uuid,
workspace,
prompt,
userId = null,
threadId = null,
sessionId = null,
}) {
super({ uuid });
this.#invocationUUID = uuid;
this.#workspace = workspace;
this.#prompt = prompt;
this.#userId = userId;
this.#threadId = threadId;
this.#sessionId = sessi... | @param {{
uuid: string,
workspace: import("@prisma/client").workspaces,
prompt: string,
userId: import("@prisma/client").users["id"]|null,
threadId: import("@prisma/client").workspace_threads["id"]|null,
sessionId: string|null
}} parameters | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/ephemeral.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/ephemeral.js | MIT |
async init() {
this.#providerSetupAndCheck();
return this;
} | Finds or assumes the model preference value to use for API calls.
If multi-model loading is supported, we use their agent model selection of the workspace
If not supported, we attempt to fallback to the system provider value for the LLM preference
and if that fails - we assume a reasonable base model to exist.
@returns... | init | javascript | Mintplex-Labs/anything-llm | server/utils/agents/ephemeral.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/ephemeral.js | MIT |
static isAgentInvocation({ message }) {
const agentHandles = WorkspaceAgentInvocation.parseAgents(message);
if (agentHandles.length > 0) return true;
return false;
} | Determine if the message provided is an agent invocation.
@param {{message:string}} parameters
@returns {boolean} | isAgentInvocation | javascript | Mintplex-Labs/anything-llm | server/utils/agents/ephemeral.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/ephemeral.js | MIT |
packMessages() {
const thoughts = [];
let textResponse = null;
for (let msg of this.messages) {
if (msg.type !== "statusResponse") {
textResponse = msg.content;
} else {
thoughts.push(msg.content);
}
}
return { thoughts, textResponse };
} | Compacts all messages in class and returns them in a condensed format.
@returns {{thoughts: string[], textResponse: string}} | packMessages | javascript | Mintplex-Labs/anything-llm | server/utils/agents/ephemeral.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/ephemeral.js | MIT |
static loadPluginByHubId(hubId) {
const configLocation = path.resolve(
pluginsPath,
normalizePath(hubId),
"plugin.json"
);
if (!this.isValidLocation(configLocation)) return;
const config = safeJsonParse(fs.readFileSync(configLocation, "utf8"));
return new ImportedPlugin(config);
... | Gets the imported plugin handler.
@param {string} hubId - The hub ID of the plugin.
@returns {ImportedPlugin} - The plugin handler. | loadPluginByHubId | javascript | Mintplex-Labs/anything-llm | server/utils/agents/imported.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/imported.js | MIT |
static checkPluginFolderExists() {
const dir = path.resolve(pluginsPath);
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
return;
} | Checks if the plugin folder exists and if it does not, creates the folder. | checkPluginFolderExists | javascript | Mintplex-Labs/anything-llm | server/utils/agents/imported.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/imported.js | MIT |
static activeImportedPlugins() {
const plugins = [];
this.checkPluginFolderExists();
const folders = fs.readdirSync(path.resolve(pluginsPath));
for (const folder of folders) {
const configLocation = path.resolve(
pluginsPath,
normalizePath(folder),
"plugin.json"
);
... | Loads plugins from `plugins` folder in storage that are custom loaded and defined.
only loads plugins that are active: true.
@returns {string[]} - array of plugin names to be loaded later. | activeImportedPlugins | javascript | Mintplex-Labs/anything-llm | server/utils/agents/imported.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/imported.js | MIT |
static listImportedPlugins() {
const plugins = [];
this.checkPluginFolderExists();
if (!fs.existsSync(pluginsPath)) return plugins;
const folders = fs.readdirSync(path.resolve(pluginsPath));
for (const folder of folders) {
const configLocation = path.resolve(
pluginsPath,
norm... | Lists all imported plugins.
@returns {Array} - array of plugin configurations (JSON). | listImportedPlugins | javascript | Mintplex-Labs/anything-llm | server/utils/agents/imported.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/imported.js | MIT |
static updateImportedPlugin(hubId, config) {
const configLocation = path.resolve(
pluginsPath,
normalizePath(hubId),
"plugin.json"
);
if (!this.isValidLocation(configLocation)) return;
const currentConfig = safeJsonParse(
fs.readFileSync(configLocation, "utf8"),
null
)... | Updates a plugin configuration.
@param {string} hubId - The hub ID of the plugin.
@param {object} config - The configuration to update.
@returns {object} - The updated configuration. | updateImportedPlugin | javascript | Mintplex-Labs/anything-llm | server/utils/agents/imported.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/imported.js | MIT |
static deletePlugin(hubId) {
if (!hubId) throw new Error("No plugin hubID passed.");
const pluginFolder = path.resolve(pluginsPath, normalizePath(hubId));
if (!this.isValidLocation(pluginFolder)) return;
fs.rmSync(pluginFolder, { recursive: true });
return true;
} | Deletes a plugin. Removes the entire folder of the object.
@param {string} hubId - The hub ID of the plugin.
@returns {boolean} - True if the plugin was deleted, false otherwise. | deletePlugin | javascript | Mintplex-Labs/anything-llm | server/utils/agents/imported.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/imported.js | MIT |
static validateImportedPluginHandler(hubId) {
const handlerLocation = path.resolve(
pluginsPath,
normalizePath(hubId),
"handler.js"
);
return this.isValidLocation(handlerLocation);
} | /**
Validates if the handler.js file exists for the given plugin.
@param {string} hubId - The hub ID of the plugin.
@returns {boolean} - True if the handler.js file exists, false otherwise. | validateImportedPluginHandler | javascript | Mintplex-Labs/anything-llm | server/utils/agents/imported.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/imported.js | MIT |
static async importCommunityItemFromUrl(url, item) {
this.checkPluginFolderExists();
const hubId = item.id;
if (!hubId) return { success: false, error: "No hubId passed to import." };
const zipFilePath = path.resolve(pluginsPath, `${item.id}.zip`);
const pluginFile = item.manifest.files.find(
... | Imports a community item from a URL.
The community item is a zip file that contains a plugin.json file and handler.js file.
This function will unzip the file and import the plugin into the agent-skills folder
based on the hubId found in the plugin.json file.
The zip file will be downloaded to the pluginsPath folder and... | importCommunityItemFromUrl | javascript | Mintplex-Labs/anything-llm | server/utils/agents/imported.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/imported.js | MIT |
providerDefault(provider = this.provider) {
switch (provider) {
case "openai":
return process.env.OPEN_MODEL_PREF ?? "gpt-4o";
case "anthropic":
return process.env.ANTHROPIC_MODEL_PREF ?? "claude-3-sonnet-20240229";
case "lmstudio":
return process.env.LMSTUDIO_MODEL_PREF ??... | Finds the default model for a given provider. If no default model is set for it's associated ENV then
it will return a reasonable base model for the provider if one exists.
@param {string} provider - The provider to find the default model for.
@returns {string|null} The default model for the provider. | providerDefault | javascript | Mintplex-Labs/anything-llm | server/utils/agents/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/index.js | MIT |
constructor(props = {}) {
const {
chats = [],
interrupt = "NEVER",
maxRounds = 100,
provider = "openai",
handlerProps = {}, // Inherited props we can spread so aibitat can access.
...rest
} = props;
this._chats = chats;
this.defaultInterrupt = interrupt;
this.maxR... | Temporary flag to skip the handleExecution function
This is used to return the result of a flow execution directly to the chat
without going through the handleExecution function (resulting in more LLM processing)
Setting Skip execution to true will prevent any further tool calls from being executed.
This is useful for... | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
get chats() {
return this._chats;
} | Get the chat history between agents and channels. | chats | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
agent(name = "", config = {}) {
this.agents.set(name, config);
return this;
} | Add a new agent to the AIbitat.
@param name
@param config
@returns | agent | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
channel(name = "", members = [""], config = {}) {
this.channels.set(name, {
members,
...config,
});
return this;
} | Add a new channel to the AIbitat.
@param name
@param members
@param config
@returns | channel | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
getAgentConfig(agent = "") {
const config = this.agents.get(agent);
if (!config) {
throw new Error(`Agent configuration "${agent}" not found`);
}
return {
role: "You are a helpful AI assistant.",
// role: `You are a helpful AI assistant.
// Solve tasks using your coding and... | Get the specific agent configuration.
@param agent The name of the agent.
@throws When the agent configuration is not found.
@returns The agent configuration. | getAgentConfig | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
getChannelConfig(channel = "") {
const config = this.channels.get(channel);
if (!config) {
throw new Error(`Channel configuration "${channel}" not found`);
}
return {
maxRounds: 10,
role: "",
...config,
};
} | Get the specific channel configuration.
@param channel The name of the channel.
@throws When the channel configuration is not found.
@returns The channel configuration. | getChannelConfig | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
getGroupMembers(node = "") {
const group = this.getChannelConfig(node);
return group.members;
} | Get the members of a group.
@throws When the group is not defined as an array in the connections.
@param node The name of the group.
@returns The members of the group. | getGroupMembers | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
onAbort(listener = () => null) {
this.emitter.on("abort", listener);
return this;
} | Triggered when a plugin, socket, or command is aborted.
@param listener
@returns | onAbort | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
abort() {
this.emitter.emit("abort", null, this);
} | Abort the running of any plugins that may still be pending (Langchain summarize) | abort | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
onTerminate(listener = () => null) {
this.emitter.on("terminate", listener);
return this;
} | Triggered when a chat is terminated. After this, the chat can't be continued.
@param listener
@returns | onTerminate | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
terminate(node = "") {
this.emitter.emit("terminate", node, this);
} | Terminate the chat. After this, the chat can't be continued.
@param node Last node to chat with | terminate | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
onInterrupt(listener = () => null) {
this.emitter.on("interrupt", listener);
return this;
} | Triggered when a chat is interrupted by a node.
@param listener
@returns | onInterrupt | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
interrupt(route) {
this._chats.push({
...route,
state: "interrupt",
});
this.emitter.emit("interrupt", route, this);
} | Interruption the chat.
@param route The nodes that participated in the interruption.
@returns | interrupt | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
onMessage(listener = (chat) => null) {
this.emitter.on("message", listener);
return this;
} | Triggered when a message is added to the chat history.
This can either be the first message or a reply to a message.
@param listener
@returns | onMessage | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
newMessage(message) {
const chat = {
...message,
state: "success",
};
this._chats.push(chat);
this.emitter.emit("message", chat, this);
} | Register a new successful message in the chat history.
This will trigger the `onMessage` event.
@param message | newMessage | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
onError(
listener = (
/**
* The error that occurred.
*
* Native errors are:
* - `APIError`
* - `AuthorizationError`
* - `UnknownError`
* - `RateLimitError`
* - `ServerError`
*/
error = null,
/**
* The message when the error occu... | Triggered when an error occurs during the chat.
@param listener
@returns | onError | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
newError(route, error) {
const chat = {
...route,
content: error instanceof Error ? error.message : String(error),
state: "error",
};
this._chats.push(chat);
this.emitter.emit("replyError", error, chat);
} | Register an error in the chat history.
This will trigger the `onError` event.
@param route
@param error | newError | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
async start(message) {
// register the message in the chat history
this.newMessage(message);
this.emitter.emit("start", message, this);
// ask the node to reply
await this.chat({
to: message.from,
from: message.to,
});
return this;
} | Start a new chat.
@param message The message to start the chat. | start | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
async chat(route, keepAlive = true) {
// check if the message is for a group
// if it is, select the next node to chat with from the group
// and then ask them to reply.
if (this.channels.get(route.from)) {
// select a node from the group
let nextNode;
try {
nextNode = await th... | Recursively chat between two nodes.
@param route
@param keepAlive Whether to keep the chat alive. | chat | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
shouldAgentInterrupt(agent = "") {
const config = this.getAgentConfig(agent);
return this.defaultInterrupt === "ALWAYS" || config.interrupt === "ALWAYS";
} | Check if the agent should interrupt the chat based on its configuration.
@param agent
@returns {boolean} Whether the agent should interrupt the chat. | shouldAgentInterrupt | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
async selectNext(channel = "") {
// get all members of the group
const nodes = this.getGroupMembers(channel);
const channelConfig = this.getChannelConfig(channel);
// TODO: move this to when the group is created
// warn if the group is underpopulated
if (nodes.length < 3) {
console.warn(
... | Select the next node to chat with from a group. The node will be selected based on the history of chats.
It will select the node that has not reached the maximum number of rounds yet and has not chatted with the channel in the last round.
If it could not determine the next node, it will return a random node.
@param ch... | selectNext | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
hasReachedMaximumRounds(from = "", to = "") {
return this.getHistory({ from, to }).length >= this.maxRounds;
} | Check if the chat has reached the maximum number of rounds. | hasReachedMaximumRounds | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
async reply(route) {
// get the provider for the node that will reply
const fromConfig = this.getAgentConfig(route.from);
const chatHistory =
// if it is sending message to a group, send the group chat history to the provider
// otherwise, send the chat history between the two nodes
this.... | Ask the for the AI provider to generate a reply to the chat.
@param route.to The node that sent the chat.
@param route.from The node that will reply to the chat. | reply | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
async continue(feedback) {
const lastChat = this._chats.at(-1);
if (!lastChat || lastChat.state !== "interrupt") {
throw new Error("No chat to continue");
}
// remove the last chat's that was interrupted
this._chats.pop();
const { from, to } = lastChat;
if (this.hasReachedMaximumRou... | Continue the chat from the last interruption.
If the last chat was not an interruption, it will throw an error.
Provide a feedback where it was interrupted if you want to.
@param feedback The feedback to the interruption if any.
@returns | continue | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
async retry() {
const lastChat = this._chats.at(-1);
if (!lastChat || lastChat.state !== "error") {
throw new Error("No chat to retry");
}
// remove the last chat's that threw an error
const { from, to } = this?._chats?.pop();
await this.chat({ from, to });
return this;
} | Retry the last chat that threw an error.
If the last chat was not an error, it will throw an error. | retry | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
getHistory({ from, to }) {
return this._chats.filter((chat) => {
const isSuccess = chat.state === "success";
// return all chats to the node
if (!from) {
return isSuccess && chat.to === to;
}
// get all chats from the node
if (!to) {
return isSuccess && chat.fro... | Get the chat history between two nodes or all chats to/from a node. | getHistory | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
getProviderForConfig(config) {
if (typeof config.provider === "object") {
return config.provider;
}
switch (config.provider) {
case "openai":
return new Providers.OpenAIProvider({ model: config.model });
case "anthropic":
return new Providers.AnthropicProvider({ model: con... | Get provider based on configurations.
If the provider is a string, it will return the default provider for that string.
@param config The provider configuration. | getProviderForConfig | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
function(functionConfig) {
this.functions.set(functionConfig.name, functionConfig);
return this;
} | Register a new function to be called by the AIbitat agents.
You are also required to specify the which node can call the function.
@param functionConfig The function configuration. | function | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/index.js | MIT |
async start(controller) {
for (const chunk of chunks) {
const bytes = new TextEncoder().encode(chunk + " ");
controller.enqueue(bytes);
await new Promise((r) =>
setTimeout(
r,
// get a random number between 10ms an... | Print a message on the terminal
@param message
// message Type { from: string; to: string; content?: string } & {
state: 'loading' | 'error' | 'success' | 'interrupt'
}
@param simulateStream | start | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/plugins/cli.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/cli.js | MIT |
setup(aibitat) {
const folderPath = path.dirname(filename);
// get path from filename
if (folderPath) {
fs.mkdirSync(folderPath, { recursive: true });
}
aibitat.onMessage(() => {
const content = JSON.stringify(aibitat.chats, null, 2);
fs.writeFile(f... | Plugin to save chat history to a json file | setup | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/plugins/file-history.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/file-history.js | MIT |
setup(aibitat) {
aibitat.onError(async (error) => {
let errorMessage =
error?.message || "An error occurred while running the agent.";
console.error(chalk.red(` error: ${errorMessage}`), error);
aibitat.introspect(
`Error encountered while running: ${error... | HTTP Interface plugin for Aibitat to emulate a websocket interface in the agent
framework so we dont have to modify the interface for passing messages and responses
in REST or WSS. | setup | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/plugins/http-socket.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/http-socket.js | MIT |
middleTruncate(str, length = 5) {
if (str.length <= length) return str;
return `${str.slice(0, length)}...${str.slice(-length)}`;
} | Utility function to truncate a string to a given length for debugging
calls to the API while keeping the actual values mostly intact
@param {string} str - The string to truncate
@param {number} length - The length to truncate the string to
@returns {string} The truncated string | middleTruncate | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/plugins/web-browsing.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/web-browsing.js | MIT |
function getDBClient(identifier = "", connectionConfig = {}) {
switch (identifier) {
case "mysql":
const { MySQLConnector } = require("./MySQL");
return new MySQLConnector(connectionConfig);
case "postgresql":
const { PostgresSQLConnector } = require("./Postgresql");
return new Postgre... | @param {SQLEngine} identifier
@param {object} connectionConfig
@returns Database Connection Engine Class for SQLAgent or throws error | getDBClient | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/index.js | MIT |
async function listSQLConnections() {
return safeJsonParse(
(await SystemSettings.get({ label: "agent_sql_connections" }))?.value,
[]
);
} | Lists all of the known database connection that can be used by the agent.
@returns {Promise<[SQLConnection]>} | listSQLConnections | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/index.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/index.js | MIT |
async runQuery(queryString = "") {
const result = { rows: [], count: 0, error: null };
try {
if (!this.#connected) await this.connect();
const query = await this._client.query(queryString);
result.rows = query.recordset;
result.count = query.rowsAffected.reduce((sum, a) => sum + a, 0);
... | @param {string} queryString the SQL query to be run
@returns {import(".").QueryResult} | runQuery | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/MSSQL.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/MSSQL.js | MIT |
format(connectionStringObject) {
if (!connectionStringObject) {
return this.scheme + "://localhost";
}
if (
this.scheme &&
connectionStringObject.scheme &&
this.scheme !== connectionStringObject.scheme
) {
throw new Error(`Scheme not supported: ${connectionStringObject.sche... | Takes a connection string object and returns a URI string of the form:
scheme://[username[:password]@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[endpoint]][?options]
@param {Object} connectionStringObject The object that describes connection string parameters | format | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/utils.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/utils.js | MIT |
parse(uri) {
const connectionStringParser = new RegExp(
"^\\s*" + // Optional whitespace padding at the beginning of the line
"([^:]+)://" + // Scheme (Group 1)
"(?:([^:@,/?=&]+)(?::([^:@,/?=&]+))?@)?" + // User (Group 2) and Password (Group 3)
"([^@/?=&]+)" + // Host address(es) (Grou... | Where scheme and hosts will always be present. Other fields will only be present in the result if they were
present in the input.
@param {string} uri The connection string URI
@returns {ConnectionStringObject} The connection string object | parse | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/utils.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/utils.js | MIT |
_formatAddress(connectionStringObject) {
return connectionStringObject.hosts
.map(
(address) =>
encodeURIComponent(address.host) +
(address.port
? ":" + encodeURIComponent(address.port.toString(10))
: "")
)
.join(",");
} | Formats the address portion of a connection string
@param {Object} connectionStringObject The object that describes connection string parameters | _formatAddress | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/utils.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/utils.js | MIT |
_parseAddress(addresses) {
return addresses.split(",").map((address) => {
const i = address.indexOf(":");
return i >= 0
? {
host: decodeURIComponent(address.substring(0, i)),
port: +address.substring(i + 1),
}
: { host: decodeURIComponent(address) };
... | Parses an address
@param {string} addresses The address(es) to process | _parseAddress | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/utils.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/utils.js | MIT |
_parseOptions(options) {
const result = {};
options.split("&").forEach((option) => {
const i = option.indexOf("=");
if (i >= 0) {
result[decodeURIComponent(option.substring(0, i))] = decodeURIComponent(
option.substring(i + 1)
);
}
});
return result;
} | Parses options
@param {string} options The options to process | _parseOptions | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/utils.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/utils.js | MIT |
constructor(client) {
if (this.constructor == Provider) {
return;
}
this._client = client;
} | @typedef {Object} LangChainModelConfig
@property {(string|null)} baseURL - Override the default base URL process.env for this provider
@property {(string|null)} apiKey - Override the default process.env for this provider
@property {(number|null)} temperature - Override the default temperature
@property {(string|null)} ... | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/ai-provider.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/ai-provider.js | MIT |
static LangChainChatModel(provider = "openai", config = {}) {
switch (provider) {
// Cloud models
case "openai":
return new ChatOpenAI({
apiKey: process.env.OPEN_AI_KEY,
...config,
});
case "anthropic":
return new ChatAnthropic({
apiKey: proces... | @param {string} provider - the string key of the provider LLM being loaded.
@param {LangChainModelConfig} config - Config to be used to override default connection object.
@returns | LangChainChatModel | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/ai-provider.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/ai-provider.js | MIT |
constructor(config = {}) {
const {
options = {
apiKey: process.env.ANTHROPIC_API_KEY,
maxRetries: 3,
},
model = "claude-2",
} = config;
const client = new Anthropic(options);
super(client);
this.model = model;
} | The agent provider for the Anthropic API.
By default, the model is set to 'claude-2'. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/anthropic.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/anthropic.js | MIT |
async complete(messages, functions = []) {
try {
const [systemPrompt, chats] = this.#parseSystemPrompt(messages);
const response = await this.client.messages.create(
{
model: this.model,
max_tokens: 4096,
system: systemPrompt,
messages: this.#sanitize(chat... | Create a completion based on the received messages.
@param messages A list of messages to send to the Anthropic API.
@param functions
@returns The completion. | complete | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/anthropic.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/anthropic.js | MIT |
constructor(config = {}) {
const { model = "openrouter/llama-3.1-8b-instruct" } = config;
super();
const client = new OpenAI({
baseURL: "https://apipie.ai/v1",
apiKey: process.env.APIPIE_LLM_API_KEY,
maxRetries: 3,
});
this._client = client;
this.model = model;
this.verbos... | The agent provider for the OpenRouter provider. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/apipie.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/apipie.js | MIT |
async complete(messages, functions = []) {
try {
let completion;
if (functions.length > 0) {
const { toolCall, text } = await this.functionCall(
messages,
functions,
this.#handleFunctionCallChat.bind(this)
);
if (toolCall !== null) {
this.... | Create a completion based on the received messages.
@param messages A list of messages to send to the API.
@param functions
@returns The completion. | complete | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/apipie.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/apipie.js | MIT |
getCost(_usage) {
return 0;
} | Get the cost of the completion.
@param _usage The completion to get the cost for.
@returns The cost of the completion. | getCost | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/apipie.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/apipie.js | MIT |
constructor(config = { model: null }) {
const client = new AzureOpenAI({
apiKey: process.env.AZURE_OPENAI_KEY,
endpoint: process.env.AZURE_OPENAI_ENDPOINT,
apiVersion: "2024-12-01-preview",
});
super(client);
this.model = config.model ?? process.env.OPEN_MODEL_PREF;
this.verbose = ... | The agent provider for the Azure OpenAI API. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/azure.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/azure.js | MIT |
async complete(messages, functions = []) {
try {
const response = await this.client.chat.completions.create({
model: this.model,
// stream: true,
messages,
...(Array.isArray(functions) && functions?.length > 0
? { functions }
: {}),
});
// Right... | Create a completion based on the received messages.
@param messages A list of messages to send to the OpenAI API.
@param functions
@returns The completion. | complete | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/azure.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/azure.js | MIT |
constructor(_config = {}) {
super();
const model = process.env.AWS_BEDROCK_LLM_MODEL_PREFERENCE ?? null;
const client = new ChatBedrockConverse({
region: process.env.AWS_BEDROCK_LLM_REGION,
credentials: this.credentials,
model,
});
this._client = client;
this.model = model;
... | The agent provider for the AWS Bedrock provider. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/bedrock.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/bedrock.js | MIT |
get credentials() {
switch (this.authMethod) {
case "iam": // explicit credentials
return {
accessKeyId: process.env.AWS_BEDROCK_LLM_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_BEDROCK_LLM_ACCESS_KEY,
};
case "sessionToken": // Session token is used for temporary ... | Gets the credentials for the AWS Bedrock LLM based on the authentication method provided.
@returns {object} The credentials object. | credentials | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/bedrock.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/bedrock.js | MIT |
get authMethod() {
const method = process.env.AWS_BEDROCK_LLM_CONNECTION_METHOD || "iam";
return SUPPORTED_CONNECTION_METHODS.includes(method) ? method : "iam";
} | Gets the configured AWS authentication method ('iam' or 'sessionToken').
Defaults to 'iam' if the environment variable is invalid.
@returns {"iam" | "iam_role" | "sessionToken"} The authentication method. | authMethod | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/bedrock.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/bedrock.js | MIT |
constructor(config = {}) {
const { model = "accounts/fireworks/models/llama-v3p1-8b-instruct" } =
config;
super();
const client = new OpenAI({
baseURL: "https://api.fireworks.ai/inference/v1",
apiKey: process.env.FIREWORKS_AI_LLM_API_KEY,
maxRetries: 0,
});
this._client = cl... | The agent provider for the FireworksAI provider.
We wrap FireworksAI in UnTooled because its tool-calling may not be supported for specific models and this normalizes that. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/fireworksai.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/fireworksai.js | MIT |
constructor(config = {}) {
const { model = "gemini-2.0-flash-lite" } = config;
super();
const client = new OpenAI({
baseURL: "https://generativelanguage.googleapis.com/v1beta/openai/",
apiKey: process.env.GEMINI_API_KEY,
maxRetries: 0,
});
this._client = client;
this.model = m... | The agent provider for the Gemini provider.
We wrap Gemini in UnTooled because its tool-calling is not supported via the dedicated OpenAI API. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/gemini.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/gemini.js | MIT |
formatMessages(messages) {
if (!NO_SYSTEM_PROMPT_MODELS.includes(this.model)) return messages;
// Replace the system message with a user/assistant message pair
const formattedMessages = [];
for (const message of messages) {
if (message.role === "system") {
formattedMessages.push({
... | Format the messages to the format required by the Gemini API since some models do not support system prompts.
@see {NO_SYSTEM_PROMPT_MODELS}
@param {import("openai").OpenAI.ChatCompletionMessage[]} messages
@returns {import("openai").OpenAI.ChatCompletionMessage[]} | formatMessages | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/gemini.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/gemini.js | MIT |
constructor(config = {}) {
super();
const { model = "gpt-3.5-turbo" } = config;
const client = new OpenAI({
baseURL: process.env.GENERIC_OPEN_AI_BASE_PATH,
apiKey: process.env.GENERIC_OPEN_AI_API_KEY ?? null,
maxRetries: 3,
});
this._client = client;
this.model = model;
th... | The agent provider for the Generic OpenAI provider.
Since we cannot promise the generic provider even supports tool calling
which is nearly 100% likely it does not, we can just wrap it in untooled
which often is far better anyway. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/genericOpenAi.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/genericOpenAi.js | MIT |
constructor(config = {}) {
const { model = "llama3-8b-8192" } = config;
super();
const client = new OpenAI({
baseURL: "https://api.groq.com/openai/v1",
apiKey: process.env.GROQ_API_KEY,
maxRetries: 3,
});
this._client = client;
this.model = model;
this.verbose = true;
} | The agent provider for the GroqAI provider.
We wrap Groq in UnTooled because its tool-calling built in is quite bad and wasteful. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/groq.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/groq.js | MIT |
constructor(_config = {}) {
super();
const model = process.env.KOBOLD_CPP_MODEL_PREF ?? null;
const client = new OpenAI({
baseURL: process.env.KOBOLD_CPP_BASE_PATH?.replace(/\/+$/, ""),
apiKey: null,
maxRetries: 3,
});
this._client = client;
this.model = model;
this.verbos... | The agent provider for the KoboldCPP provider. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/koboldcpp.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/koboldcpp.js | MIT |
constructor(config = {}) {
const { model = null } = config;
super();
const client = new OpenAI({
baseURL: process.env.LOCAL_AI_BASE_PATH,
apiKey: process.env.LOCAL_AI_API_KEY ?? null,
maxRetries: 3,
});
this._client = client;
this.model = model;
this.verbose = true;
} | The agent provider for the LocalAI provider. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/localai.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/localai.js | MIT |
constructor(config = {}) {
const { model = "deepseek/deepseek-r1" } = config;
super();
const client = new OpenAI({
baseURL: "https://api.novita.ai/v3/openai",
apiKey: process.env.NOVITA_LLM_API_KEY,
maxRetries: 3,
defaultHeaders: {
"HTTP-Referer": "https://anythingllm.com",
... | The agent provider for the Novita AI provider. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/novita.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/novita.js | MIT |
getCost() {
return 0;
} | Get the cost of the completion.
@param _usage The completion to get the cost for.
@returns The cost of the completion.
Stubbed since Novita AI has no cost basis. | getCost | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/novita.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/novita.js | MIT |
constructor(config = {}) {
const { model } = config;
super();
const client = new OpenAI({
baseURL: process.env.NVIDIA_NIM_LLM_BASE_PATH,
apiKey: null,
maxRetries: 0,
});
this._client = client;
this.model = model;
this.verbose = true;
} | The agent provider for the Nvidia NIM provider.
We wrap Nvidia NIM in UnTooled because its tool-calling may not be supported for specific models and this normalizes that. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/nvidiaNim.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/nvidiaNim.js | MIT |
constructor(config = {}) {
const {
// options = {},
model = null,
} = config;
super();
const headers = process.env.OLLAMA_AUTH_TOKEN
? { Authorization: `Bearer ${process.env.OLLAMA_AUTH_TOKEN}` }
: {};
this._client = new Ollama({
host: process.env.OLLAMA_BASE_PATH,
... | The agent provider for the Ollama provider. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/ollama.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/ollama.js | MIT |
constructor(config = {}) {
const {
options = {
apiKey: process.env.OPEN_AI_KEY,
maxRetries: 3,
},
model = "gpt-4o",
} = config;
const client = new OpenAI(options);
super(client);
this.model = model;
} | The agent provider for the OpenAI API.
By default, the model is set to 'gpt-3.5-turbo'. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/openai.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/openai.js | MIT |
getCost(usage) {
if (!usage) {
return Number.NaN;
}
// regex to remove the version number from the model
const modelBase = this.model.replace(/-(\d{4})$/, "");
if (!(modelBase in OpenAIProvider.COST_PER_TOKEN)) {
return Number.NaN;
}
const costPerToken = OpenAIProvider.COST_PE... | Get the cost of the completion.
@param usage The completion to get the cost for.
@returns The cost of the completion. | getCost | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/openai.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/openai.js | MIT |
constructor(config = {}) {
super();
const { model = "sonar-small-online" } = config;
const client = new OpenAI({
baseURL: "https://api.perplexity.ai",
apiKey: process.env.PERPLEXITY_API_KEY ?? null,
maxRetries: 3,
});
this._client = client;
this.model = model;
this.verbose... | The agent provider for the Perplexity provider. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/perplexity.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/perplexity.js | MIT |
constructor(config = {}) {
const { model = "qwen/qwen2.5-32b-instruct" } = config;
super();
const client = new OpenAI({
baseURL: "https://api.ppinfra.com/v3/openai",
apiKey: process.env.PPIO_API_KEY,
maxRetries: 3,
defaultHeaders: {
"HTTP-Referer": "https://anythingllm.com",
... | The agent provider for the PPIO AI provider. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/ppio.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/ppio.js | MIT |
constructor(_config = {}) {
super();
const client = new OpenAI({
baseURL: process.env.TEXT_GEN_WEB_UI_BASE_PATH,
apiKey: process.env.TEXT_GEN_WEB_UI_API_KEY ?? null,
maxRetries: 3,
});
this._client = client;
this.model = null; // text-web-gen-ui does not have a model pref.
thi... | The agent provider for the Oobabooga provider. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/textgenwebui.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/textgenwebui.js | MIT |
constructor(config = {}) {
const { model = "mistralai/Mistral-7B-Instruct-v0.1" } = config;
super();
const client = new OpenAI({
baseURL: "https://api.together.xyz/v1",
apiKey: process.env.TOGETHER_AI_API_KEY,
maxRetries: 3,
});
this._client = client;
this.model = model;
t... | The agent provider for the TogetherAI provider. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/togetherai.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/togetherai.js | MIT |
constructor(config = {}) {
const { model = "grok-beta" } = config;
super();
const client = new OpenAI({
baseURL: "https://api.x.ai/v1",
apiKey: process.env.XAI_LLM_API_KEY,
maxRetries: 3,
});
this._client = client;
this.model = model;
this.verbose = true;
} | The agent provider for the xAI provider. | constructor | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/xai.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/xai.js | MIT |
compareArrays(arr1, arr2, opts) {
function vKey(i, v) {
return (opts?.enforceOrder ? `${i}-` : "") + `${typeof v}-${v}`;
}
if (arr1.length !== arr2.length) return false;
const d1 = {};
const d2 = {};
for (let i = arr1.length - 1; i >= 0; i--) {
d1[vKey(i, arr1[i])] = true;
d2... | Check if two arrays of strings or numbers have the same values
@param {string[]|number[]} arr1
@param {string[]|number[]} arr2
@param {Object} [opts]
@param {boolean} [opts.enforceOrder] - By default (false), the order of the values in the arrays doesn't matter.
@return {boolean} | compareArrays | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/providers/helpers/untooled.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/helpers/untooled.js | MIT |
reset(type = "runs") {
switch (type) {
case "runs":
this.#hashes = {};
break;
case "cooldowns":
this.#cooldowns = {};
break;
case "uniques":
this.#uniques = {};
break;
}
return;
} | Resets the object property for this instance of the Deduplicator class
@param {('runs'|'cooldowns'|'uniques')} type - The type of prop to reset | reset | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/utils/dedupe.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/utils/dedupe.js | MIT |
async function summarizeContent({
provider = "openai",
model = null,
controllerSignal,
content,
}) {
const llm = Provider.LangChainChatModel(provider, {
temperature: 0,
model: model,
});
const textSplitter = new RecursiveCharacterTextSplitter({
separators: ["\n\n", "\n"],
chunkSize: 10000... | Summarize content using LLM LC-Chain call
@param {LCSummarizationConfig} The LLM to use for summarization (inherited)
@returns {Promise<string>} The summarized content. | summarizeContent | javascript | Mintplex-Labs/anything-llm | server/utils/agents/aibitat/utils/summarize.js | https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/utils/summarize.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.