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
constructPrompt({ systemPrompt = "", contextTexts = [], chatHistory = [], userPrompt = "", attachments = [], // This is the specific attachment for only this prompt }) { const prompt = { role: "system", content: `${systemPrompt}${this.#appendContext(contextTexts)}`, }; retu...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
constructPrompt
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/mistral/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/mistral/index.js
MIT
async getChatCompletion(messages = null, { temperature = 0.7 }) { if (!(await this.isValidChatCompletionModel(this.model))) throw new Error( `Mistral chat: ${this.model} is not valid for chat completion!` ); const result = await LLMPerformanceMonitor.measureAsyncFunction( this.openai....
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
getChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/mistral/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/mistral/index.js
MIT
async streamGetChatCompletion(messages = null, { temperature = 0.7 }) { if (!(await this.isValidChatCompletionModel(this.model))) throw new Error( `Mistral chat: ${this.model} is not valid for chat completion!` ); const measuredStreamRequest = await LLMPerformanceMonitor.measureStream( ...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
streamGetChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/mistral/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/mistral/index.js
MIT
handleStream(response, stream, responseProps) { return handleDefaultStreamResponseV2(response, stream, responseProps); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
handleStream
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/mistral/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/mistral/index.js
MIT
async embedTextInput(textInput) { return await this.embedder.embedTextInput(textInput); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
embedTextInput
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/mistral/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/mistral/index.js
MIT
async embedChunks(textChunks = []) { return await this.embedder.embedChunks(textChunks); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
embedChunks
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/mistral/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/mistral/index.js
MIT
async compressMessages(promptArgs = {}, rawHistory = []) { const { messageArrayCompressor } = require("../../helpers/chat"); const messageArray = this.constructPrompt(promptArgs); return await messageArrayCompressor(this, messageArray, rawHistory); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
compressMessages
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/mistral/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/mistral/index.js
MIT
constructor() { if (ContextWindowFinder.instance) return ContextWindowFinder.instance; ContextWindowFinder.instance = this; if (!fs.existsSync(this.cacheLocation)) fs.mkdirSync(this.cacheLocation, { recursive: true }); // If the cache is stale or not found at all, pull the model map from remote ...
Mapping for AnythingLLM provider <> LiteLLM provider @type {Record<string, string>}
constructor
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/modelMap/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/modelMap/index.js
MIT
log(text, ...args) { console.log(`\x1b[33m[ContextWindowFinder]\x1b[0m ${text}`, ...args); }
Mapping for AnythingLLM provider <> LiteLLM provider @type {Record<string, string>}
log
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/modelMap/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/modelMap/index.js
MIT
get isCacheStale() { if (!fs.existsSync(this.cacheFileExpiryPath)) return true; const cachedAt = fs.readFileSync(this.cacheFileExpiryPath, "utf8"); return Date.now() - cachedAt > ContextWindowFinder.expiryMs; }
Checks if the cache is stale by checking if the cache file exists and if the cache file is older than the expiry time. @returns {boolean}
isCacheStale
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/modelMap/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/modelMap/index.js
MIT
get cachedModelMap() { if (!fs.existsSync(this.cacheFilePath)) { this.log(`\x1b[33m -------------------------------- [WARNING] Model map cache is not found! Invalid context windows will be returned leading to inaccurate model responses or smaller context windows than expected. You can fix this by restarting A...
Gets the cached model map. Always returns the available model map - even if it is expired since re-pulling the model map only occurs on container start/system start. @returns {Record<string, Record<string, number>> | null} - The cached model map
cachedModelMap
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/modelMap/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/modelMap/index.js
MIT
get(provider = null, model = null) { if (!provider || !this.cachedModelMap || !this.cachedModelMap[provider]) return null; if (!model) return this.cachedModelMap[provider]; const modelContextWindow = this.cachedModelMap[provider][model]; if (!modelContextWindow) { this.log("Invalid access t...
Gets the context window for a given provider and model. If the provider is not found, null is returned. If the model is not found, the provider's entire model map is returned. if both provider and model are provided, the context window for the given model is returned. @param {string|null} provider - The provider to g...
get
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/modelMap/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/modelMap/index.js
MIT
models() { if (!fs.existsSync(this.cacheModelPath)) return {}; return safeJsonParse( fs.readFileSync(this.cacheModelPath, { encoding: "utf-8" }), {} ); }
Novita has various models that never return `finish_reasons` and thus leave the stream open which causes issues in subsequent messages. This timeout value forces us to close the stream after x milliseconds. This is a configurable value via the NOVITA_LLM_TIMEOUT_MS value @returns {number} The timeout value in milliseco...
models
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
streamingEnabled() { return "streamGetChatCompletion" in this; }
Novita has various models that never return `finish_reasons` and thus leave the stream open which causes issues in subsequent messages. This timeout value forces us to close the stream after x milliseconds. This is a configurable value via the NOVITA_LLM_TIMEOUT_MS value @returns {number} The timeout value in milliseco...
streamingEnabled
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
static promptWindowLimit(modelName) { const cacheModelPath = path.resolve(cacheFolder, "models.json"); const availableModels = fs.existsSync(cacheModelPath) ? safeJsonParse( fs.readFileSync(cacheModelPath, { encoding: "utf-8" }), {} ) : {}; return availableModels[mode...
Novita has various models that never return `finish_reasons` and thus leave the stream open which causes issues in subsequent messages. This timeout value forces us to close the stream after x milliseconds. This is a configurable value via the NOVITA_LLM_TIMEOUT_MS value @returns {number} The timeout value in milliseco...
promptWindowLimit
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
promptWindowLimit() { const availableModels = this.models(); return availableModels[this.model]?.maxLength || 4096; }
Novita has various models that never return `finish_reasons` and thus leave the stream open which causes issues in subsequent messages. This timeout value forces us to close the stream after x milliseconds. This is a configurable value via the NOVITA_LLM_TIMEOUT_MS value @returns {number} The timeout value in milliseco...
promptWindowLimit
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
async isValidChatCompletionModel(model = "") { await this.#syncModels(); const availableModels = this.models(); return availableModels.hasOwnProperty(model); }
Novita has various models that never return `finish_reasons` and thus leave the stream open which causes issues in subsequent messages. This timeout value forces us to close the stream after x milliseconds. This is a configurable value via the NOVITA_LLM_TIMEOUT_MS value @returns {number} The timeout value in milliseco...
isValidChatCompletionModel
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
constructPrompt({ systemPrompt = "", contextTexts = [], chatHistory = [], userPrompt = "", attachments = [], }) { const prompt = { role: "system", content: `${systemPrompt}${this.#appendContext(contextTexts)}`, }; return [ prompt, ...formatChatHistory(chatHistor...
Generates appropriate content array for a message + attachments. @param {{userPrompt:string, attachments: import("../../helpers").Attachment[]}} @returns {string|object[]}
constructPrompt
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
async getChatCompletion(messages = null, { temperature = 0.7 }) { if (!(await this.isValidChatCompletionModel(this.model))) throw new Error( `Novita chat: ${this.model} is not valid for chat completion!` ); const result = await LLMPerformanceMonitor.measureAsyncFunction( this.openai.c...
Generates appropriate content array for a message + attachments. @param {{userPrompt:string, attachments: import("../../helpers").Attachment[]}} @returns {string|object[]}
getChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
async streamGetChatCompletion(messages = null, { temperature = 0.7 }) { if (!(await this.isValidChatCompletionModel(this.model))) throw new Error( `Novita chat: ${this.model} is not valid for chat completion!` ); const measuredStreamRequest = await LLMPerformanceMonitor.measureStream( ...
Generates appropriate content array for a message + attachments. @param {{userPrompt:string, attachments: import("../../helpers").Attachment[]}} @returns {string|object[]}
streamGetChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
handleStream(response, stream, responseProps) { const timeoutThresholdMs = this.timeout; const { uuid = uuidv4(), sources = [] } = responseProps; return new Promise(async (resolve) => { let fullText = ""; let lastChunkTime = null; // null when first token is still not received. // Establ...
Handles the default stream response for a chat. @param {import("express").Response} response @param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream @param {Object} responseProps @returns {Promise<string>}
handleStream
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
handleAbort = () => { stream?.endMeasurement({ completion_tokens: LLMPerformanceMonitor.countTokens(fullText), }); clientAbortedHandler(resolve, fullText); }
Handles the default stream response for a chat. @param {import("express").Response} response @param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream @param {Object} responseProps @returns {Promise<string>}
handleAbort
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
handleAbort = () => { stream?.endMeasurement({ completion_tokens: LLMPerformanceMonitor.countTokens(fullText), }); clientAbortedHandler(resolve, fullText); }
Handles the default stream response for a chat. @param {import("express").Response} response @param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream @param {Object} responseProps @returns {Promise<string>}
handleAbort
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
async embedTextInput(textInput) { return await this.embedder.embedTextInput(textInput); }
Handles the default stream response for a chat. @param {import("express").Response} response @param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream @param {Object} responseProps @returns {Promise<string>}
embedTextInput
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
async embedChunks(textChunks = []) { return await this.embedder.embedChunks(textChunks); }
Handles the default stream response for a chat. @param {import("express").Response} response @param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream @param {Object} responseProps @returns {Promise<string>}
embedChunks
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
async compressMessages(promptArgs = {}, rawHistory = []) { const { messageArrayCompressor } = require("../../helpers/chat"); const messageArray = this.constructPrompt(promptArgs); return await messageArrayCompressor(this, messageArray, rawHistory); }
Handles the default stream response for a chat. @param {import("express").Response} response @param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream @param {Object} responseProps @returns {Promise<string>}
compressMessages
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
async function fetchNovitaModels() { return await fetch(`https://api.novita.ai/v3/openai/models`, { method: "GET", headers: { "Content-Type": "application/json", }, }) .then((res) => res.json()) .then(({ data = [] }) => { const models = {}; data.forEach((model) => { mod...
Handles the default stream response for a chat. @param {import("express").Response} response @param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream @param {Object} responseProps @returns {Promise<string>}
fetchNovitaModels
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/novita/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/novita/index.js
MIT
constructPrompt({ systemPrompt = "", contextTexts = [], chatHistory = [], userPrompt = "", attachments = [], }) { const prompt = { role: "system", content: `${systemPrompt}${this.#appendContext(contextTexts)}`, }; return [ prompt, ...formatChatHistory(chatHistor...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
constructPrompt
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/nvidiaNim/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/nvidiaNim/index.js
MIT
async getChatCompletion(messages = null, { temperature = 0.7 }) { if (!this.model) throw new Error( `NVIDIA NIM chat: ${this.model} is not valid or defined model for chat completion!` ); const result = await LLMPerformanceMonitor.measureAsyncFunction( this.nvidiaNim.chat.completions ...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
getChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/nvidiaNim/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/nvidiaNim/index.js
MIT
async streamGetChatCompletion(messages = null, { temperature = 0.7 }) { if (!this.model) throw new Error( `NVIDIA NIM chat: ${this.model} is not valid or defined model for chat completion!` ); const measuredStreamRequest = await LLMPerformanceMonitor.measureStream( this.nvidiaNim.chat...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
streamGetChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/nvidiaNim/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/nvidiaNim/index.js
MIT
handleStream(response, stream, responseProps) { return handleDefaultStreamResponseV2(response, stream, responseProps); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
handleStream
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/nvidiaNim/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/nvidiaNim/index.js
MIT
async embedTextInput(textInput) { return await this.embedder.embedTextInput(textInput); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
embedTextInput
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/nvidiaNim/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/nvidiaNim/index.js
MIT
async embedChunks(textChunks = []) { return await this.embedder.embedChunks(textChunks); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
embedChunks
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/nvidiaNim/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/nvidiaNim/index.js
MIT
async compressMessages(promptArgs = {}, rawHistory = []) { const { messageArrayCompressor } = require("../../helpers/chat"); const messageArray = this.constructPrompt(promptArgs); return await messageArrayCompressor(this, messageArray, rawHistory); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
compressMessages
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/nvidiaNim/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/nvidiaNim/index.js
MIT
function parseNvidiaNimBasePath(providedBasePath = "") { try { const baseURL = new URL(providedBasePath); const basePath = `${baseURL.origin}/v1`; return basePath; } catch (e) { return providedBasePath; } }
Parse the base path for the Nvidia NIM container API. Since the base path must end in /v1 and cannot have a trailing slash, and the user can possibly set it to anything and likely incorrectly due to pasting behaviors, we need to ensure it is in the correct format. @param {string} basePath @returns {string}
parseNvidiaNimBasePath
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/nvidiaNim/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/nvidiaNim/index.js
MIT
constructPrompt({ systemPrompt = "", contextTexts = [], chatHistory = [], userPrompt = "", attachments = [], }) { const prompt = { role: "system", content: `${systemPrompt}${this.#appendContext(contextTexts)}`, }; return [ prompt, ...formatChatHistory(chatHistor...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
constructPrompt
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ollama/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ollama/index.js
MIT
async getChatCompletion(messages = null, { temperature = 0.7 }) { const result = await LLMPerformanceMonitor.measureAsyncFunction( this.client .chat({ model: this.model, stream: false, messages, keep_alive: this.keepAlive, options: { temper...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
getChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ollama/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ollama/index.js
MIT
async streamGetChatCompletion(messages = null, { temperature = 0.7 }) { const measuredStreamRequest = await LLMPerformanceMonitor.measureStream( this.client.chat({ model: this.model, stream: true, messages, keep_alive: this.keepAlive, options: { temperature, ...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
streamGetChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ollama/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ollama/index.js
MIT
handleStream(response, stream, responseProps) { const { uuid = uuidv4(), sources = [] } = responseProps; return new Promise(async (resolve) => { let fullText = ""; let usage = { prompt_tokens: 0, completion_tokens: 0, }; // Establish listener to early-abort a streaming ...
Handles streaming responses from Ollama. @param {import("express").Response} response @param {import("../../helpers/chat/LLMPerformanceMonitor").MonitoredStream} stream @param {import("express").Request} request @returns {Promise<string>}
handleStream
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ollama/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ollama/index.js
MIT
handleAbort = () => { stream?.endMeasurement(usage); clientAbortedHandler(resolve, fullText); }
Handles streaming responses from Ollama. @param {import("express").Response} response @param {import("../../helpers/chat/LLMPerformanceMonitor").MonitoredStream} stream @param {import("express").Request} request @returns {Promise<string>}
handleAbort
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ollama/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ollama/index.js
MIT
handleAbort = () => { stream?.endMeasurement(usage); clientAbortedHandler(resolve, fullText); }
Handles streaming responses from Ollama. @param {import("express").Response} response @param {import("../../helpers/chat/LLMPerformanceMonitor").MonitoredStream} stream @param {import("express").Request} request @returns {Promise<string>}
handleAbort
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ollama/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ollama/index.js
MIT
async embedTextInput(textInput) { return await this.embedder.embedTextInput(textInput); }
Handles streaming responses from Ollama. @param {import("express").Response} response @param {import("../../helpers/chat/LLMPerformanceMonitor").MonitoredStream} stream @param {import("express").Request} request @returns {Promise<string>}
embedTextInput
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ollama/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ollama/index.js
MIT
async embedChunks(textChunks = []) { return await this.embedder.embedChunks(textChunks); }
Handles streaming responses from Ollama. @param {import("express").Response} response @param {import("../../helpers/chat/LLMPerformanceMonitor").MonitoredStream} stream @param {import("express").Request} request @returns {Promise<string>}
embedChunks
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ollama/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ollama/index.js
MIT
async compressMessages(promptArgs = {}, rawHistory = []) { const { messageArrayCompressor } = require("../../helpers/chat"); const messageArray = this.constructPrompt(promptArgs); return await messageArrayCompressor(this, messageArray, rawHistory); }
Handles streaming responses from Ollama. @param {import("express").Response} response @param {import("../../helpers/chat/LLMPerformanceMonitor").MonitoredStream} stream @param {import("express").Request} request @returns {Promise<string>}
compressMessages
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ollama/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ollama/index.js
MIT
get isOTypeModel() { return this.model.startsWith("o"); }
Check if the model is an o1 model. @returns {boolean}
isOTypeModel
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openAi/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openAi/index.js
MIT
streamingEnabled() { // o3-mini is the only o-type model that supports streaming if (this.isOTypeModel && this.model !== "o3-mini") return false; return "streamGetChatCompletion" in this; }
Check if the model is an o1 model. @returns {boolean}
streamingEnabled
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openAi/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openAi/index.js
MIT
static promptWindowLimit(modelName) { return MODEL_MAP.get("openai", modelName) ?? 4_096; }
Check if the model is an o1 model. @returns {boolean}
promptWindowLimit
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openAi/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openAi/index.js
MIT
promptWindowLimit() { return MODEL_MAP.get("openai", this.model) ?? 4_096; }
Check if the model is an o1 model. @returns {boolean}
promptWindowLimit
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openAi/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openAi/index.js
MIT
async isValidChatCompletionModel(modelName = "") { const isPreset = modelName.toLowerCase().includes("gpt") || modelName.toLowerCase().startsWith("o"); if (isPreset) return true; const model = await this.openai.models .retrieve(modelName) .then((modelObj) => modelObj) .catch((...
Check if the model is an o1 model. @returns {boolean}
isValidChatCompletionModel
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openAi/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openAi/index.js
MIT
constructPrompt({ systemPrompt = "", contextTexts = [], chatHistory = [], userPrompt = "", attachments = [], // This is the specific attachment for only this prompt }) { // o1 Models do not support the "system" role // in order to combat this, we can use the "user" role as a replacement fo...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
constructPrompt
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openAi/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openAi/index.js
MIT
async getChatCompletion(messages = null, { temperature = 0.7 }) { if (!(await this.isValidChatCompletionModel(this.model))) throw new Error( `OpenAI chat: ${this.model} is not valid for chat completion!` ); const result = await LLMPerformanceMonitor.measureAsyncFunction( this.openai.c...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
getChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openAi/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openAi/index.js
MIT
async streamGetChatCompletion(messages = null, { temperature = 0.7 }) { if (!(await this.isValidChatCompletionModel(this.model))) throw new Error( `OpenAI chat: ${this.model} is not valid for chat completion!` ); const measuredStreamRequest = await LLMPerformanceMonitor.measureStream( ...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
streamGetChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openAi/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openAi/index.js
MIT
handleStream(response, stream, responseProps) { return handleDefaultStreamResponseV2(response, stream, responseProps); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
handleStream
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openAi/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openAi/index.js
MIT
async embedTextInput(textInput) { return await this.embedder.embedTextInput(textInput); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
embedTextInput
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openAi/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openAi/index.js
MIT
async embedChunks(textChunks = []) { return await this.embedder.embedChunks(textChunks); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
embedChunks
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openAi/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openAi/index.js
MIT
async compressMessages(promptArgs = {}, rawHistory = []) { const { messageArrayCompressor } = require("../../helpers/chat"); const messageArray = this.constructPrompt(promptArgs); return await messageArrayCompressor(this, messageArray, rawHistory); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
compressMessages
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openAi/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openAi/index.js
MIT
get isPerplexityModel() { return this.model.startsWith("perplexity/"); }
Returns true if the model is a Perplexity model. OpenRouter has support for a lot of models and we have some special handling for Perplexity models that support in-line citations. @returns {boolean}
isPerplexityModel
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
enrichToken({ token, citations = [] }) { if (!Array.isArray(citations) || citations.length === 0) return token; return token.replace(/\[(\d+)\]/g, (match, index) => { const citationIndex = parseInt(index) - 1; return citations[citationIndex] ? `[[${index}](${citations[citationIndex]})]` ...
Generic formatting of a token for the following use cases: - Perplexity models that return inline citations in the token text @param {{token: string, citations: string[]}} options - The token text and citations. @returns {string} - The formatted token text.
enrichToken
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
log(text, ...args) { console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args); }
Generic formatting of a token for the following use cases: - Perplexity models that return inline citations in the token text @param {{token: string, citations: string[]}} options - The token text and citations. @returns {string} - The formatted token text.
log
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
models() { if (!fs.existsSync(this.cacheModelPath)) return {}; return safeJsonParse( fs.readFileSync(this.cacheModelPath, { encoding: "utf-8" }), {} ); }
OpenRouter has various models that never return `finish_reasons` and thus leave the stream open which causes issues in subsequent messages. This timeout value forces us to close the stream after x milliseconds. This is a configurable value via the OPENROUTER_TIMEOUT_MS value @returns {number} The timeout value in milli...
models
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
streamingEnabled() { return "streamGetChatCompletion" in this; }
OpenRouter has various models that never return `finish_reasons` and thus leave the stream open which causes issues in subsequent messages. This timeout value forces us to close the stream after x milliseconds. This is a configurable value via the OPENROUTER_TIMEOUT_MS value @returns {number} The timeout value in milli...
streamingEnabled
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
static promptWindowLimit(modelName) { const cacheModelPath = path.resolve(cacheFolder, "models.json"); const availableModels = fs.existsSync(cacheModelPath) ? safeJsonParse( fs.readFileSync(cacheModelPath, { encoding: "utf-8" }), {} ) : {}; return availableModels[mode...
OpenRouter has various models that never return `finish_reasons` and thus leave the stream open which causes issues in subsequent messages. This timeout value forces us to close the stream after x milliseconds. This is a configurable value via the OPENROUTER_TIMEOUT_MS value @returns {number} The timeout value in milli...
promptWindowLimit
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
promptWindowLimit() { const availableModels = this.models(); return availableModels[this.model]?.maxLength || 4096; }
OpenRouter has various models that never return `finish_reasons` and thus leave the stream open which causes issues in subsequent messages. This timeout value forces us to close the stream after x milliseconds. This is a configurable value via the OPENROUTER_TIMEOUT_MS value @returns {number} The timeout value in milli...
promptWindowLimit
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
async isValidChatCompletionModel(model = "") { await this.#syncModels(); const availableModels = this.models(); return availableModels.hasOwnProperty(model); }
OpenRouter has various models that never return `finish_reasons` and thus leave the stream open which causes issues in subsequent messages. This timeout value forces us to close the stream after x milliseconds. This is a configurable value via the OPENROUTER_TIMEOUT_MS value @returns {number} The timeout value in milli...
isValidChatCompletionModel
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
constructPrompt({ systemPrompt = "", contextTexts = [], chatHistory = [], userPrompt = "", attachments = [], }) { const prompt = { role: "system", content: `${systemPrompt}${this.#appendContext(contextTexts)}`, }; return [ prompt, ...formatChatHistory(chatHistor...
Parses and prepends reasoning from the response and returns the full text response. @param {Object} response @returns {string}
constructPrompt
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
async getChatCompletion(messages = null, { temperature = 0.7 }) { if (!(await this.isValidChatCompletionModel(this.model))) throw new Error( `OpenRouter chat: ${this.model} is not valid for chat completion!` ); const result = await LLMPerformanceMonitor.measureAsyncFunction( this.open...
Parses and prepends reasoning from the response and returns the full text response. @param {Object} response @returns {string}
getChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
async streamGetChatCompletion(messages = null, { temperature = 0.7 }) { if (!(await this.isValidChatCompletionModel(this.model))) throw new Error( `OpenRouter chat: ${this.model} is not valid for chat completion!` ); const measuredStreamRequest = await LLMPerformanceMonitor.measureStream( ...
Parses and prepends reasoning from the response and returns the full text response. @param {Object} response @returns {string}
streamGetChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
handleStream(response, stream, responseProps) { const timeoutThresholdMs = this.timeout; const { uuid = uuidv4(), sources = [] } = responseProps; return new Promise(async (resolve) => { let fullText = ""; let reasoningText = ""; let lastChunkTime = null; // null when first token is still ...
Handles the default stream response for a chat. @param {import("express").Response} response @param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream @param {Object} responseProps @returns {Promise<string>}
handleStream
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
handleAbort = () => { stream?.endMeasurement({ completion_tokens: LLMPerformanceMonitor.countTokens(fullText), }); clientAbortedHandler(resolve, fullText); }
Handles the default stream response for a chat. @param {import("express").Response} response @param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream @param {Object} responseProps @returns {Promise<string>}
handleAbort
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
handleAbort = () => { stream?.endMeasurement({ completion_tokens: LLMPerformanceMonitor.countTokens(fullText), }); clientAbortedHandler(resolve, fullText); }
Handles the default stream response for a chat. @param {import("express").Response} response @param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream @param {Object} responseProps @returns {Promise<string>}
handleAbort
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
async embedTextInput(textInput) { return await this.embedder.embedTextInput(textInput); }
Handles the default stream response for a chat. @param {import("express").Response} response @param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream @param {Object} responseProps @returns {Promise<string>}
embedTextInput
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
async embedChunks(textChunks = []) { return await this.embedder.embedChunks(textChunks); }
Handles the default stream response for a chat. @param {import("express").Response} response @param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream @param {Object} responseProps @returns {Promise<string>}
embedChunks
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
async compressMessages(promptArgs = {}, rawHistory = []) { const { messageArrayCompressor } = require("../../helpers/chat"); const messageArray = this.constructPrompt(promptArgs); return await messageArrayCompressor(this, messageArray, rawHistory); }
Handles the default stream response for a chat. @param {import("express").Response} response @param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream @param {Object} responseProps @returns {Promise<string>}
compressMessages
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
async function fetchOpenRouterModels() { return await fetch(`https://openrouter.ai/api/v1/models`, { method: "GET", headers: { "Content-Type": "application/json", }, }) .then((res) => res.json()) .then(({ data = [] }) => { const models = {}; data.forEach((model) => { mo...
Handles the default stream response for a chat. @param {import("express").Response} response @param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream @param {Object} responseProps @returns {Promise<string>}
fetchOpenRouterModels
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/openRouter/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/openRouter/index.js
MIT
enrichToken(token, citations) { if (!Array.isArray(citations) || citations.length === 0) return token; return token.replace(/\[(\d+)\]/g, (match, index) => { const citationIndex = parseInt(index) - 1; return citations[citationIndex] ? `[[${index}](${citations[citationIndex]})]` : mat...
Enrich a token with citations if available for in-line citations. @param {string} token - The token to enrich. @param {Array} citations - The citations to enrich the token with. @returns {string} The enriched token.
enrichToken
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/perplexity/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/perplexity/index.js
MIT
handleStream(response, stream, responseProps) { const timeoutThresholdMs = 800; const { uuid = uuidv4(), sources = [] } = responseProps; let hasUsageMetrics = false; let pplxCitations = []; // Array of links let usage = { completion_tokens: 0, }; return new Promise(async (resolve) => ...
Enrich a token with citations if available for in-line citations. @param {string} token - The token to enrich. @param {Array} citations - The citations to enrich the token with. @returns {string} The enriched token.
handleStream
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/perplexity/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/perplexity/index.js
MIT
handleAbort = () => { stream?.endMeasurement(usage); clientAbortedHandler(resolve, fullText); }
Enrich a token with citations if available for in-line citations. @param {string} token - The token to enrich. @param {Array} citations - The citations to enrich the token with. @returns {string} The enriched token.
handleAbort
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/perplexity/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/perplexity/index.js
MIT
handleAbort = () => { stream?.endMeasurement(usage); clientAbortedHandler(resolve, fullText); }
Enrich a token with citations if available for in-line citations. @param {string} token - The token to enrich. @param {Array} citations - The citations to enrich the token with. @returns {string} The enriched token.
handleAbort
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/perplexity/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/perplexity/index.js
MIT
async embedTextInput(textInput) { return await this.embedder.embedTextInput(textInput); }
Enrich a token with citations if available for in-line citations. @param {string} token - The token to enrich. @param {Array} citations - The citations to enrich the token with. @returns {string} The enriched token.
embedTextInput
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/perplexity/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/perplexity/index.js
MIT
async embedChunks(textChunks = []) { return await this.embedder.embedChunks(textChunks); }
Enrich a token with citations if available for in-line citations. @param {string} token - The token to enrich. @param {Array} citations - The citations to enrich the token with. @returns {string} The enriched token.
embedChunks
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/perplexity/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/perplexity/index.js
MIT
async compressMessages(promptArgs = {}, rawHistory = []) { const { messageArrayCompressor } = require("../../helpers/chat"); const messageArray = this.constructPrompt(promptArgs); return await messageArrayCompressor(this, messageArray, rawHistory); }
Enrich a token with citations if available for in-line citations. @param {string} token - The token to enrich. @param {Array} citations - The citations to enrich the token with. @returns {string} The enriched token.
compressMessages
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/perplexity/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/perplexity/index.js
MIT
constructPrompt({ systemPrompt = "", contextTexts = [], chatHistory = [], userPrompt = "", // attachments = [], - not supported }) { const prompt = { role: "system", content: `${systemPrompt}${this.#appendContext(contextTexts)}`, }; return [prompt, ...chatHistory, { role: "...
Generates appropriate content array for a message + attachments. @param {{userPrompt:string, attachments: import("../../helpers").Attachment[]}} @returns {string|object[]}
constructPrompt
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ppio/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ppio/index.js
MIT
async getChatCompletion(messages = null, { temperature = 0.7 }) { if (!(await this.isValidChatCompletionModel(this.model))) throw new Error( `PPIO chat: ${this.model} is not valid for chat completion!` ); const result = await LLMPerformanceMonitor.measureAsyncFunction( this.openai.cha...
Generates appropriate content array for a message + attachments. @param {{userPrompt:string, attachments: import("../../helpers").Attachment[]}} @returns {string|object[]}
getChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ppio/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ppio/index.js
MIT
async streamGetChatCompletion(messages = null, { temperature = 0.7 }) { if (!(await this.isValidChatCompletionModel(this.model))) throw new Error( `PPIO chat: ${this.model} is not valid for chat completion!` ); const measuredStreamRequest = await LLMPerformanceMonitor.measureStream( t...
Generates appropriate content array for a message + attachments. @param {{userPrompt:string, attachments: import("../../helpers").Attachment[]}} @returns {string|object[]}
streamGetChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ppio/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ppio/index.js
MIT
handleStream(response, stream, responseProps) { return handleDefaultStreamResponseV2(response, stream, responseProps); }
Generates appropriate content array for a message + attachments. @param {{userPrompt:string, attachments: import("../../helpers").Attachment[]}} @returns {string|object[]}
handleStream
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ppio/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ppio/index.js
MIT
async embedTextInput(textInput) { return await this.embedder.embedTextInput(textInput); }
Generates appropriate content array for a message + attachments. @param {{userPrompt:string, attachments: import("../../helpers").Attachment[]}} @returns {string|object[]}
embedTextInput
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ppio/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ppio/index.js
MIT
async embedChunks(textChunks = []) { return await this.embedder.embedChunks(textChunks); }
Generates appropriate content array for a message + attachments. @param {{userPrompt:string, attachments: import("../../helpers").Attachment[]}} @returns {string|object[]}
embedChunks
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ppio/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ppio/index.js
MIT
async compressMessages(promptArgs = {}, rawHistory = []) { const { messageArrayCompressor } = require("../../helpers/chat"); const messageArray = this.constructPrompt(promptArgs); return await messageArrayCompressor(this, messageArray, rawHistory); }
Generates appropriate content array for a message + attachments. @param {{userPrompt:string, attachments: import("../../helpers").Attachment[]}} @returns {string|object[]}
compressMessages
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ppio/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ppio/index.js
MIT
async function fetchPPIOModels() { return await fetch(`https://api.ppinfra.com/v3/openai/models`, { method: "GET", headers: { "Content-Type": "application/json", Authorization: `Bearer ${process.env.PPIO_API_KEY}`, }, }) .then((res) => res.json()) .then(({ data = [] }) => { con...
Generates appropriate content array for a message + attachments. @param {{userPrompt:string, attachments: import("../../helpers").Attachment[]}} @returns {string|object[]}
fetchPPIOModels
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/ppio/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/ppio/index.js
MIT
constructPrompt({ systemPrompt = "", contextTexts = [], chatHistory = [], userPrompt = "", attachments = [], }) { const prompt = { role: "system", content: `${systemPrompt}${this.#appendContext(contextTexts)}`, }; return [ prompt, ...formatChatHistory(chatHistor...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
constructPrompt
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/textGenWebUI/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/textGenWebUI/index.js
MIT
async getChatCompletion(messages = null, { temperature = 0.7 }) { const result = await LLMPerformanceMonitor.measureAsyncFunction( this.openai.chat.completions .create({ model: this.model, messages, temperature, }) .catch((e) => { throw new Error...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
getChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/textGenWebUI/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/textGenWebUI/index.js
MIT
async streamGetChatCompletion(messages = null, { temperature = 0.7 }) { const measuredStreamRequest = await LLMPerformanceMonitor.measureStream( this.openai.chat.completions.create({ model: this.model, stream: true, messages, temperature, }), messages ); ret...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
streamGetChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/textGenWebUI/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/textGenWebUI/index.js
MIT
handleStream(response, stream, responseProps) { return handleDefaultStreamResponseV2(response, stream, responseProps); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
handleStream
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/textGenWebUI/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/textGenWebUI/index.js
MIT
async embedTextInput(textInput) { return await this.embedder.embedTextInput(textInput); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
embedTextInput
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/textGenWebUI/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/textGenWebUI/index.js
MIT
async embedChunks(textChunks = []) { return await this.embedder.embedChunks(textChunks); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
embedChunks
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/textGenWebUI/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/textGenWebUI/index.js
MIT
async compressMessages(promptArgs = {}, rawHistory = []) { const { messageArrayCompressor } = require("../../helpers/chat"); const messageArray = this.constructPrompt(promptArgs); return await messageArrayCompressor(this, messageArray, rawHistory); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
compressMessages
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/textGenWebUI/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/textGenWebUI/index.js
MIT
constructPrompt({ systemPrompt = "", contextTexts = [], chatHistory = [], userPrompt = "", attachments = [], // This is the specific attachment for only this prompt }) { const prompt = { role: "system", content: `${systemPrompt}${this.#appendContext(contextTexts)}`, }; retu...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
constructPrompt
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/xai/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/xai/index.js
MIT
async getChatCompletion(messages = null, { temperature = 0.7 }) { if (!this.isValidChatCompletionModel(this.model)) throw new Error( `xAI chat: ${this.model} is not valid for chat completion!` ); const result = await LLMPerformanceMonitor.measureAsyncFunction( this.openai.chat.complet...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
getChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/xai/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/xai/index.js
MIT
async streamGetChatCompletion(messages = null, { temperature = 0.7 }) { if (!this.isValidChatCompletionModel(this.model)) throw new Error( `xAI chat: ${this.model} is not valid for chat completion!` ); const measuredStreamRequest = await LLMPerformanceMonitor.measureStream( this.opena...
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
streamGetChatCompletion
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/xai/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/xai/index.js
MIT
handleStream(response, stream, responseProps) { return handleDefaultStreamResponseV2(response, stream, responseProps); }
Construct the user prompt for this model. @param {{attachments: import("../../helpers").Attachment[]}} param0 @returns
handleStream
javascript
Mintplex-Labs/anything-llm
server/utils/AiProviders/xai/index.js
https://github.com/Mintplex-Labs/anything-llm/blob/master/server/utils/AiProviders/xai/index.js
MIT