code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
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
parseCallOptions() { const callOpts = {}; if (!this.config.setup_args || typeof this.config.setup_args !== "object") { return callOpts; } for (const [param, definition] of Object.entries(this.config.setup_args)) { if (definition.required && !definition?.value) { console.log( ...
/** 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.
parseCallOptions
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
plugin(runtimeArgs = {}) { const customFunctions = this.handler.runtime; return { runtimeArgs, name: this.name, config: this.config, setup(aibitat) { aibitat.function({ super: aibitat, name: this.name, config: this.config, runtimeArgs: this...
/** 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.
plugin
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
setup(aibitat) { aibitat.function({ super: aibitat, name: this.name, config: this.config, runtimeArgs: this.runtimeArgs, description: this.config.description, logger: aibitat?.handlerProps?.log || console.log, // Allows plugin to log to the console. ...
/** 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.
setup
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
parseCallOptions(args, config = {}, pluginName) { const callOpts = {}; for (const [param, definition] of Object.entries(config)) { if ( definition.required && (!Object.prototype.hasOwnProperty.call(args, param) || args[param] === null) ) { this.log( `'${pa...
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...
parseCallOptions
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
async init() { await this.#validInvocation(); 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/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/index.js
MIT
async createAIbitat( args = { socket, } ) { this.aibitat = new AIbitat({ provider: this.provider ?? "openai", model: this.model ?? "gpt-4o", chats: await this.#chatHistory(20), handlerProps: { invocation: this.invocation, log: this.log, }, }); /...
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...
createAIbitat
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
startAgentCluster() { return this.aibitat.start({ from: USER_AGENT.name, to: this.channel ?? WORKSPACE_AGENT.name, content: this.invocation.prompt, }); }
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...
startAgentCluster
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
onStart(listener = (chat, aibitat) => null) { this.emitter.on("start", listener); return this; }
Triggered when a chat is interrupted by a node. @param listener @returns
onStart
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 handleExecution( provider, messages = [], functions = [], byAgent = null ) { // get the chat completion const completion = await provider.complete(messages, functions); if (completion.functionCall) { const { name, arguments: args } = completion.functionCall; const fn = t...
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.
handleExecution
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
getTablesSql() { return `SELECT name FROM sysobjects WHERE xtype='U';`; }
@param {string} queryString the SQL query to be run @returns {import(".").QueryResult}
getTablesSql
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
getTableSchemaSql(table_name) { return `SELECT COLUMN_NAME,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='${table_name}'`; }
@param {string} queryString the SQL query to be run @returns {import(".").QueryResult}
getTableSchemaSql
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
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; result.count = query?.length; } catch (err) { console.log(this.co...
@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/MySQL.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/MySQL.js
MIT
getTablesSql() { return `SELECT table_name FROM information_schema.tables WHERE table_schema = '${this.database_id}'`; }
@param {string} queryString the SQL query to be run @returns {import(".").QueryResult}
getTablesSql
javascript
Mintplex-Labs/anything-llm
server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/MySQL.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/MySQL.js
MIT
getTableSchemaSql(table_name) { return `SHOW COLUMNS FROM ${this.database_id}.${table_name};`; }
@param {string} queryString the SQL query to be run @returns {import(".").QueryResult}
getTableSchemaSql
javascript
Mintplex-Labs/anything-llm
server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/MySQL.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/MySQL.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.rows; result.count = query.rowCount; } catch (err) { console.log(thi...
@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/Postgresql.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/Postgresql.js
MIT
getTablesSql() { return `SELECT * FROM pg_catalog.pg_tables WHERE schemaname = 'public'`; }
@param {string} queryString the SQL query to be run @returns {import(".").QueryResult}
getTablesSql
javascript
Mintplex-Labs/anything-llm
server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/Postgresql.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/Postgresql.js
MIT
getTableSchemaSql(table_name) { return ` select column_name, data_type, character_maximum_length, column_default, is_nullable from INFORMATION_SCHEMA.COLUMNS where table_name = '${table_name}'`; }
@param {string} queryString the SQL query to be run @returns {import(".").QueryResult}
getTableSchemaSql
javascript
Mintplex-Labs/anything-llm
server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/Postgresql.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/Postgresql.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
providerLog(text, ...args) { console.log( `\x1b[36m[AgentLLM${this?.model ? ` - ${this.model}` : ""}]\x1b[0m ${text}`, ...args ); }
@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)} ...
providerLog
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
get client() { return this._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)} ...
client
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
get client() { return this._client; }
The agent provider for the OpenRouter provider.
client
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
getCost(_usage) { return 0; }
Get the cost of the completion. Stubbed since Azure OpenAI has no public cost basis. @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/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
get client() { return this._client; }
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.
client
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
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/bedrock.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/bedrock.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. Stubbed since KoboldCPP has no cost basis.
getCost
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
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/deepseek.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/deepseek.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/deepseek.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/deepseek.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/dellProAiStudio.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/dellProAiStudio.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. Stubbed since LMStudio has no cost basis.
getCost
javascript
Mintplex-Labs/anything-llm
server/utils/agents/aibitat/providers/dellProAiStudio.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/dellProAiStudio.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
get client() { return this._client; }
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.
client
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
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/fireworksai.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/fireworksai.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/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
get client() { return this._client; }
The agent provider for the Gemini provider. We wrap Gemini in UnTooled because its tool-calling is not supported via the dedicated OpenAI API.
client
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
async complete(messages, functions = []) { try { let completion; if (functions.length > 0) { const { toolCall, text } = await this.functionCall( this.cleanMsgs(this.formatMessages(messages)), functions, this.#handleFunctionCallChat.bind(this) ); if...
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/gemini.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/gemini.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/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
get client() { return this._client; }
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.
client
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
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/genericOpenAi.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/genericOpenAi.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/genericOpenAi.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/agents/aibitat/providers/genericOpenAi.js
MIT