Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🤖 feat: Model Specs & Save Tools per Convo/Preset (#2578)

Danny Avila0e50c07e3ff2
diff --git a/api/app/clients/AnthropicClient.js b/api/app/clients/AnthropicClient.js
index 6d478defab..48e1f22b64 100644
--- a/api/app/clients/AnthropicClient.js
+++ b/api/app/clients/AnthropicClient.js
@@ -655,6 +655,9 @@ class AnthropicClient extends BaseClient {
promptPrefix: this.options.promptPrefix,
modelLabel: this.options.modelLabel,
resendFiles: this.options.resendFiles,
+ iconURL: this.options.iconURL,
+ greeting: this.options.greeting,
+ spec: this.options.spec,
...this.modelOptions,
};
}
diff --git a/api/app/clients/BaseClient.js b/api/app/clients/BaseClient.js
index f7ed3b9cf1..d1690672e3 100644
--- a/api/app/clients/BaseClient.js
+++ b/api/app/clients/BaseClient.js
@@ -456,6 +456,8 @@ class BaseClient {
sender: this.sender,
text: addSpaceIfNeeded(generation) + completion,
promptTokens,
+ iconURL: this.options.iconURL,
+ endpoint: this.options.endpoint,
...(this.metadata ?? {}),
};
@@ -525,8 +527,19 @@ class BaseClient {
return _messages;
}
+ /**
+ * Save a message to the database.
+ * @param {TMessage} message
+ * @param {Partial<TConversation>} endpointOptions
+ * @param {string | null} user
+ */
async saveMessageToDatabase(message, endpointOptions, user = null) {
- await saveMessage({ ...message, endpoint: this.options.endpoint, user, unfinished: false });
+ await saveMessage({
+ ...message,
+ endpoint: this.options.endpoint,
+ unfinished: false,
+ user,
+ });
await saveConvo(user, {
conversationId: message.conversationId,
endpoint: this.options.endpoint,
diff --git a/api/app/clients/GoogleClient.js b/api/app/clients/GoogleClient.js
index a0f08694f2..af2ee5794c 100644
--- a/api/app/clients/GoogleClient.js
+++ b/api/app/clients/GoogleClient.js
@@ -708,6 +708,9 @@ class GoogleClient extends BaseClient {
return {
promptPrefix: this.options.promptPrefix,
modelLabel: this.options.modelLabel,
+ iconURL: this.options.iconURL,
+ greeting: this.options.greeting,
+ spec: this.options.spec,
...this.modelOptions,
};
}
diff --git a/api/app/clients/OpenAIClient.js b/api/app/clients/OpenAIClient.js
index 11e9124953..b87b5f287b 100644
--- a/api/app/clients/OpenAIClient.js
+++ b/api/app/clients/OpenAIClient.js
@@ -381,6 +381,9 @@ class OpenAIClient extends BaseClient {
promptPrefix: this.options.promptPrefix,
resendFiles: this.options.resendFiles,
imageDetail: this.options.imageDetail,
+ iconURL: this.options.iconURL,
+ greeting: this.options.greeting,
+ spec: this.options.spec,
...this.modelOptions,
};
}
diff --git a/api/app/clients/PluginsClient.js b/api/app/clients/PluginsClient.js
index 7ba530b885..9c57ee2e9c 100644
--- a/api/app/clients/PluginsClient.js
+++ b/api/app/clients/PluginsClient.js
@@ -42,8 +42,12 @@ class PluginsClient extends OpenAIClient {
return {
chatGptLabel: this.options.chatGptLabel,
promptPrefix: this.options.promptPrefix,
+ tools: this.options.tools,
...this.modelOptions,
agentOptions: this.agentOptions,
+ iconURL: this.options.iconURL,
+ greeting: this.options.greeting,
+ spec: this.options.spec,
};
}
@@ -144,9 +148,11 @@ class PluginsClient extends OpenAIClient {
signal,
pastMessages,
tools: this.tools,
- currentDateString: this.currentDateString,
verbose: this.options.debug,
returnIntermediateSteps: true,
+ customName: this.options.chatGptLabel,
+ currentDateString: this.currentDateString,
+ customInstructions: this.options.promptPrefix,
callbackManager: CallbackManager.fromHandlers({
async handleAgentAction(action, runId) {
handleAction(action, runId, onAgentAction);
@@ -304,6 +310,8 @@ class PluginsClient extends OpenAIClient {
}
const responseMessage = {
+ endpoint: EModelEndpoint.gptPlugins,
+ iconURL: this.options.iconURL,
messageId: responseMessageId,
conversationId,
parentMessageId: userMessage.messageId,
diff --git a/api/app/clients/agents/CustomAgent/initializeCustomAgent.js b/api/app/clients/agents/CustomAgent/initializeCustomAgent.js
index 2a7813eea6..3d45e5be83 100644
--- a/api/app/clients/agents/CustomAgent/initializeCustomAgent.js
+++ b/api/app/clients/agents/CustomAgent/initializeCustomAgent.js
@@ -13,10 +13,18 @@ const initializeCustomAgent = async ({
tools,
model,
pastMessages,
+ customName,
+ customInstructions,
currentDateString,
...rest
}) => {
let prompt = CustomAgent.createPrompt(tools, { currentDateString, model: model.modelName });
+ if (customName) {
+ prompt = `You are "${customName}".\n${prompt}`;
+ }
+ if (customInstructions) {
+ prompt = `${prompt}\n${customInstructions}`;
+ }
const chatPrompt = ChatPromptTemplate.fromMessages([
new SystemMessagePromptTemplate(prompt),
diff --git a/api/app/clients/agents/Functions/initializeFunctionsAgent.js b/api/app/clients/agents/Functions/initializeFunctionsAgent.js
index 3d1a1704ea..3e813bdbcc 100644
--- a/api/app/clients/agents/Functions/initializeFunctionsAgent.js
+++ b/api/app/clients/agents/Functions/initializeFunctionsAgent.js
@@ -10,6 +10,8 @@ const initializeFunctionsAgent = async ({
tools,
model,
pastMessages,
+ customName,
+ customInstructions,
currentDateString,
...rest
}) => {
@@ -24,7 +26,13 @@ const initializeFunctionsAgent = async ({
returnMessages: true,
});
- const prefix = addToolDescriptions(`Current Date: ${currentDateString}\n${PREFIX}`, tools);
+ let prefix = addToolDescriptions(`Current Date: ${currentDateString}\n${PREFIX}`, tools);
+ if (customName) {
+ prefix = `You are "${customName}".\n${prefix}`;
+ }
+ if (customInstructions) {
+ prefix = `${prefix}\n${customInstructions}`;
+ }
return await initializeAgentExecutorWithOptions(tools, model, {
agentType: 'openai-functions',
diff --git a/api/models/Message.js b/api/models/Message.js
index a8e1acdf14..554e9f7117 100644
--- a/api/models/Message.js
+++ b/api/models/Message.js
@@ -10,6 +10,7 @@ module.exports = {
async saveMessage({
user,
endpoint,
+ iconURL,
messageId,
newMessageId,
conversationId,
@@ -35,6 +36,7 @@ module.exports = {
const update = {
user,
+ iconURL,
endpoint,
messageId: newMessageId || messageId,
conversationId,
diff --git a/api/models/Preset.js b/api/models/Preset.js
index e9f0a1e77e..c0134eca6a 100644
--- a/api/models/Preset.js
+++ b/api/models/Preset.js
@@ -39,6 +39,12 @@ module.exports = {
try {
const setter = { $set: {} };
const update = { presetId, ...preset };
+ if (preset.tools && Array.isArray(preset.tools)) {
+ update.tools =
+ preset.tools
+ .map((tool) => tool?.pluginKey ?? tool)
+ .filter((toolName) => typeof toolName === 'string') ?? [];
+ }
if (newPresetId) {
update.presetId = newPresetId;
}
diff --git a/api/models/schema/defaults.js b/api/models/schema/defaults.js
index 710e0f3a36..775251d082 100644
--- a/api/models/schema/defaults.js
+++ b/api/models/schema/defaults.js
@@ -89,6 +89,17 @@ const conversationPreset = {
type: String,
},
stop: { type: [{ type: String }], default: undefined },
+ /* UI Components */
+ iconURL: {
+ type: String,
+ },
+ greeting: {
+ type: String,
+ },
+ spec: {
+ type: String,
+ },
+ tools: { type: [{ type: String }], default: undefined },
};
const agentOptions = {
diff --git a/api/models/schema/messageSchema.js b/api/models/schema/messageSchema.js
index fc745499fe..d9a6dfb939 100644
--- a/api/models/schema/messageSchema.js
+++ b/api/models/schema/messageSchema.js
@@ -110,6 +110,10 @@ const messageSchema = mongoose.Schema(
thread_id: {
type: String,
},
+ /* frontend components */
+ iconURL: {
+ type: String,
+ },
},
{ timestamps: true },
);
diff --git a/api/server/controllers/PluginController.js b/api/server/controllers/PluginController.js
index 803d89923b..cac0b88bcf 100644
--- a/api/server/controllers/PluginController.js
+++ b/api/server/controllers/PluginController.js
@@ -55,6 +55,9 @@ const getAvailablePluginsController = async (req, res) => {
return;
}
+ /** @type {{ filteredTools: string[] }} */
+ const { filteredTools = [] } = req.app.locals;
+
const pluginManifest = await fs.readFile(req.app.locals.paths.pluginManifest, 'utf8');
const jsonData = JSON.parse(pluginManifest);
@@ -67,7 +70,10 @@ const getAvailablePluginsController = async (req, res) => {
return plugin;
}
});
- const plugins = await addOpenAPISpecs(authenticatedPlugins);
+
+ let plugins = await addOpenAPISpecs(authenticatedPlugins);
+ plugins = plugins.filter((plugin) => !filteredTools.includes(plugin.pluginKey));
+
await cache.set(CacheKeys.PLUGINS, plugins);
res.status(200).json(plugins);
} catch (error) {
diff --git a/api/server/middleware/abortMiddleware.js b/api/server/middleware/abortMiddleware.js
index d77fccd755..a868b107b3 100644
--- a/api/server/middleware/abortMiddleware.js
+++ b/api/server/middleware/abortMiddleware.js
@@ -73,6 +73,8 @@ const createAbortController = (req, res, getAbortData) => {
...responseData,
conversationId,
finish_reason: 'incomplete',
+ endpoint: endpointOption.endpoint,
+ iconURL: endpointOption.iconURL,
model: endpointOption.modelOptions.model,
unfinished: false,
error: false,
diff --git a/api/server/middleware/buildEndpointOption.js b/api/server/middleware/buildEndpointOption.js
index e0ae6c8534..7205b76473 100644
--- a/api/server/middleware/buildEndpointOption.js
+++ b/api/server/middleware/buildEndpointOption.js
@@ -7,6 +7,8 @@ const anthropic = require('~/server/services/Endpoints/anthropic');
const openAI = require('~/server/services/Endpoints/openAI');
const custom = require('~/server/services/Endpoints/custom');
const google = require('~/server/services/Endpoints/google');
+const enforceModelSpec = require('./enforceModelSpec');
+const { handleError } = require('~/server/utils');
const buildFunction = {
[EModelEndpoint.openAI]: openAI.buildOptions,
@@ -21,6 +23,31 @@ const buildFunction = {
async function buildEndpointOption(req, res, next) {
const { endpoint, endpointType } = req.body;
const parsedBody = parseConvo({ endpoint, endpointType, conversation: req.body });
+
+ if (req.app.locals.modelSpecs?.list && req.app.locals.modelSpecs?.enforce) {
+ /** @type {{ list: TModelSpec[] }}*/
+ const { list } = req.app.locals.modelSpecs;
+ const { spec } = parsedBody;
+
+ if (!spec) {
+ return handleError(res, { text: 'No model spec selected' });
+ }
+
+ const currentModelSpec = list.find((s) => s.name === spec);
+ if (!currentModelSpec) {
+ return handleError(res, { text: 'Invalid model spec' });
+ }
+
+ if (endpoint !== currentModelSpec.preset.endpoint) {
+ return handleError(res, { text: 'Model spec mismatch' });
+ }
+
+ const isValidModelSpec = enforceModelSpec(currentModelSpec, parsedBody);
+ if (!isValidModelSpec) {
+ return handleError(res, { text: 'Model spec mismatch' });
+ }
+ }
+
req.body.endpointOption = buildFunction[endpointType ?? endpoint](
endpoint,
parsedBody,
diff --git a/api/server/middleware/enforceModelSpec.js b/api/server/middleware/enforceModelSpec.js
new file mode 100644
index 0000000000..c2c10b3860
--- /dev/null
+++ b/api/server/middleware/enforceModelSpec.js
@@ -0,0 +1,47 @@
+const interchangeableKeys = new Map([
+ ['chatGptLabel', ['modelLabel']],
+ ['modelLabel', ['chatGptLabel']],
+]);
+
+/**
+ * Middleware to enforce the model spec for a conversation
+ * @param {TModelSpec} modelSpec - The model spec to enforce
+ * @param {TConversation} parsedBody - The parsed body of the conversation
+ * @returns {boolean} - Whether the model spec is enforced
+ */
+const enforceModelSpec = (modelSpec, parsedBody) => {
+ for (const [key, value] of Object.entries(modelSpec.preset)) {
+ if (key === 'endpoint') {
+ continue;
+ }
+
+ if (!checkMatch(key, value, parsedBody)) {
+ return false;
+ }
+ }
+ return true;
+};
+
+/**
+ * Checks if there is a match for the given key and value in the parsed body
+ * or any of its interchangeable keys.
+ * @param {string} key
+ * @param {any} value
+ * @param {TConversation} parsedBody
+ * @returns {boolean}
+ */
+const checkMatch = (key, value, parsedBody) => {
+ if (parsedBody[key] === value) {
+ return true;
+ }
+
+ if (interchangeableKeys.has(key)) {
+ return interchangeableKeys
+ .get(key)
+ .some((interchangeableKey) => parsedBody[interchangeableKey] === value);
+ }
+
+ return false;
+};
+
+module.exports = enforceModelSpec;
diff --git a/api/server/routes/config.js b/api/server/routes/config.js
index a9f6772dee..32e03bc8e8 100644
--- a/api/server/routes/config.js
+++ b/api/server/routes/config.js
@@ -14,6 +14,7 @@ router.get('/', async function (req, res) {
};
try {
+ /** @type {TStartupConfig} */
const payload = {
appTitle: process.env.APP_TITLE || 'LibreChat',
socialLogins: req.app.locals.socialLogins ?? defaultSocialLogins,
@@ -44,7 +45,8 @@ router.get('/', async function (req, res) {
isEnabled(process.env.SHOW_BIRTHDAY_ICON) ||
process.env.SHOW_BIRTHDAY_ICON === '',
helpAndFaqURL: process.env.HELP_AND_FAQ_URL || 'https://librechat.ai',
- interface: req.app.locals.interface,
+ interface: req.app.locals.interfaceConfig,
+ modelSpecs: req.app.locals.modelSpecs,
};
if (typeof process.env.CUSTOM_FOOTER === 'string') {
diff --git a/api/server/services/AppService.js b/api/server/services/AppService.js
index 87c4a2394f..bcdd089481 100644
--- a/api/server/services/AppService.js
+++ b/api/server/services/AppService.js
@@ -1,14 +1,10 @@
-const {
- FileSources,
- EModelEndpoint,
- EImageOutputType,
- defaultSocialLogins,
-} = require('librechat-data-provider');
+const { FileSources, EModelEndpoint, getConfigDefaults } = require('librechat-data-provider');
const { checkVariables, checkHealth, checkConfig, checkAzureVariables } = require('./start/checks');
const { azureAssistantsDefaults, assistantsConfigSetup } = require('./start/assistants');
const { initializeFirebase } = require('./Files/Firebase/initialize');
const loadCustomConfig = require('./Config/loadCustomConfig');
const handleRateLimits = require('./Config/handleRateLimits');
+const { loadDefaultInterface } = require('./start/interface');
const { azureConfigSetup } = require('./start/azureOpenAI');
const { loadAndFormatTools } = require('./ToolService');
const paths = require('~/config/paths');
@@ -22,9 +18,12 @@ const paths = require('~/config/paths');
const AppService = async (app) => {
/** @type {TCustomConfig}*/
const config = (await loadCustomConfig()) ?? {};
+ const configDefaults = getConfigDefaults();
+
+ const filteredTools = config.filteredTools;
+ const fileStrategy = config.fileStrategy ?? configDefaults.fileStrategy;
+ const imageOutputType = config?.imageOutputType ?? configDefaults.imageOutputType;
- const fileStrategy = config.fileStrategy ?? FileSources.local;
- const imageOutputType = config?.imageOutputType ?? EImageOutputType.PNG;
process.env.CDN_PROVIDER = fileStrategy;
checkVariables();
@@ -37,24 +36,22 @@ const AppService = async (app) => {
/** @type {Record<string, FunctionTool} */
const availableTools = loadAndFormatTools({
directory: paths.structuredTools,
- filter: new Set([
- 'ChatTool.js',
- 'CodeSherpa.js',
- 'CodeSherpaTools.js',
- 'E2BTools.js',
- 'extractionChain.js',
- ]),
+ adminFilter: filteredTools,
});
- const socialLogins = config?.registration?.socialLogins ?? defaultSocialLogins;
+ const socialLogins =
+ config?.registration?.socialLogins ?? configDefaults?.registration?.socialLogins;
+ const interfaceConfig = loadDefaultInterface(config, configDefaults);
if (!Object.keys(config).length) {
app.locals = {
paths,
fileStrategy,
socialLogins,
+ filteredTools,
availableTools,
imageOutputType,
+ interfaceConfig,
};
return;
@@ -85,9 +82,11 @@ const AppService = async (app) => {
paths,
socialLogins,
fileStrategy,
+ filteredTools,
availableTools,
imageOutputType,
- interface: config?.interface,
+ interfaceConfig,
+ modelSpecs: config.modelSpecs,
fileConfig: config?.fileConfig,
secureImageLinks: config?.secureImageLinks,
...endpointLocals,
diff --git a/api/server/services/AppService.spec.js b/api/server/services/AppService.spec.js
index bf71ece6ed..cfd451308e 100644
--- a/api/server/services/AppService.spec.js
+++ b/api/server/services/AppService.spec.js
@@ -93,6 +93,16 @@ describe('AppService', () => {
expect(app.locals).toEqual({
socialLogins: ['testLogin'],
fileStrategy: 'testStrategy',
+ interfaceConfig: expect.objectContaining({
+ privacyPolicy: undefined,
+ termsOfService: undefined,
+ endpointsMenu: true,
+ modelSelect: true,
+ parameters: true,
+ sidePanel: true,
+ presets: true,
+ }),
+ modelSpecs: undefined,
availableTools: {
ExampleTool: {
type: 'function',
@@ -109,7 +119,6 @@ describe('AppService', () => {
},
paths: expect.anything(),
imageOutputType: expect.any(String),
- interface: undefined,
fileConfig: undefined,
secureImageLinks: undefined,
});
@@ -181,7 +190,6 @@ describe('AppService', () => {
expect(loadAndFormatTools).toHaveBeenCalledWith({
directory: expect.anything(),
- filter: expect.anything(),
});
expect(app.locals.availableTools.ExampleTool).toBeDefined();
diff --git a/api/server/services/Config/loadCustomConfig.js b/api/server/services/Config/loadCustomConfig.js
index 6becbb99a5..dc3105c392 100644
--- a/api/server/services/Config/loadCustomConfig.js
+++ b/api/server/services/Config/loadCustomConfig.js
@@ -42,6 +42,12 @@ async function loadCustomConfig() {
i === 0 && i++;
return null;
}
+
+ if (customConfig.reason || customConfig.stack) {
+ i === 0 && logger.error('Config file YAML format is invalid:', customConfig);
+ i === 0 && i++;
+ return null;
+ }
}
if (typeof customConfig === 'string') {
@@ -84,6 +90,10 @@ Please specify a correct \`imageOutputType\` value (case-sensitive).
await cache.set(CacheKeys.CUSTOM_CONFIG, customConfig);
}
+ if (result.data.modelSpecs) {
+ customConfig.modelSpecs = result.data.modelSpecs;
+ }
+
return customConfig;
}
diff --git a/api/server/services/Endpoints/anthropic/buildOptions.js b/api/server/services/Endpoints/anthropic/buildOptions.js
index 4cd9ba8b92..77588c293d 100644
--- a/api/server/services/Endpoints/anthropic/buildOptions.js
+++ b/api/server/services/Endpoints/anthropic/buildOptions.js
@@ -1,10 +1,13 @@
const buildOptions = (endpoint, parsedBody) => {
- const { modelLabel, promptPrefix, resendFiles, ...rest } = parsedBody;
+ const { modelLabel, promptPrefix, resendFiles, iconURL, greeting, spec, ...rest } = parsedBody;
const endpointOption = {
endpoint,
modelLabel,
promptPrefix,
resendFiles,
+ iconURL,
+ greeting,
+ spec,
modelOptions: {
...rest,
},
diff --git a/api/server/services/Endpoints/assistants/buildOptions.js b/api/server/services/Endpoints/assistants/buildOptions.js
index c670953539..047663c4e5 100644
--- a/api/server/services/Endpoints/assistants/buildOptions.js
+++ b/api/server/services/Endpoints/assistants/buildOptions.js
@@ -1,10 +1,13 @@
const buildOptions = (endpoint, parsedBody) => {
// eslint-disable-next-line no-unused-vars
- const { promptPrefix, assistant_id, ...rest } = parsedBody;
+ const { promptPrefix, assistant_id, iconURL, greeting, spec, ...rest } = parsedBody;
const endpointOption = {
endpoint,
promptPrefix,
assistant_id,
+ iconURL,
+ greeting,
+ spec,
modelOptions: {
...rest,
},
diff --git a/api/server/services/Endpoints/custom/buildOptions.js b/api/server/services/Endpoints/custom/buildOptions.js
index 3d93795732..8722e82362 100644
--- a/api/server/services/Endpoints/custom/buildOptions.js
+++ b/api/server/services/Endpoints/custom/buildOptions.js
@@ -1,5 +1,6 @@
const buildOptions = (endpoint, parsedBody, endpointType) => {
- const { chatGptLabel, promptPrefix, resendFiles, imageDetail, ...rest } = parsedBody;
+ const { chatGptLabel, promptPrefix, resendFiles, imageDetail, iconURL, greeting, spec, ...rest } =
+ parsedBody;
const endpointOption = {
endpoint,
endpointType,
@@ -7,6 +8,9 @@ const buildOptions = (endpoint, parsedBody, endpointType) => {
promptPrefix,
resendFiles,
imageDetail,
+ iconURL,
+ greeting,
+ spec,
modelOptions: {
...rest,
},
diff --git a/api/server/services/Endpoints/google/buildOptions.js b/api/server/services/Endpoints/google/buildOptions.js
index 0f00bf82d0..0d26e23c33 100644
--- a/api/server/services/Endpoints/google/buildOptions.js
+++ b/api/server/services/Endpoints/google/buildOptions.js
@@ -1,10 +1,13 @@
const buildOptions = (endpoint, parsedBody) => {
- const { examples, modelLabel, promptPrefix, ...rest } = parsedBody;
+ const { examples, modelLabel, promptPrefix, iconURL, greeting, spec, ...rest } = parsedBody;
const endpointOption = {
examples,
endpoint,
modelLabel,
promptPrefix,
+ iconURL,
+ greeting,
+ spec,
modelOptions: {
...rest,
},
diff --git a/api/server/services/Endpoints/gptPlugins/buildOptions.js b/api/server/services/Endpoints/gptPlugins/buildOptions.js
index ebf4116ec3..f5875ec38f 100644
--- a/api/server/services/Endpoints/gptPlugins/buildOptions.js
+++ b/api/server/services/Endpoints/gptPlugins/buildOptions.js
@@ -4,25 +4,24 @@ const buildOptions = (endpoint, parsedBody) => {
promptPrefix,
agentOptions,
tools,
- model,
- temperature,
- top_p,
- presence_penalty,
- frequency_penalty,
+ iconURL,
+ greeting,
+ spec,
+ ...modelOptions
} = parsedBody;
const endpointOption = {
endpoint,
- tools: tools.map((tool) => tool.pluginKey) ?? [],
+ tools:
+ tools
+ .map((tool) => tool?.pluginKey ?? tool)
+ .filter((toolName) => typeof toolName === 'string') ?? [],
chatGptLabel,
promptPrefix,
agentOptions,
- modelOptions: {
- model,
- temperature,
- top_p,
- presence_penalty,
- frequency_penalty,
- },
+ iconURL,
+ greeting,
+ spec,
+ modelOptions,
};
return endpointOption;
diff --git a/api/server/services/Endpoints/openAI/buildOptions.js b/api/server/services/Endpoints/openAI/buildOptions.js
index 0b1fb3eabd..f90886ed71 100644
--- a/api/server/services/Endpoints/openAI/buildOptions.js
+++ b/api/server/services/Endpoints/openAI/buildOptions.js
@@ -1,11 +1,15 @@
const buildOptions = (endpoint, parsedBody) => {
- const { chatGptLabel, promptPrefix, resendFiles, imageDetail, ...rest } = parsedBody;
+ const { chatGptLabel, promptPrefix, resendFiles, imageDetail, iconURL, greeting, spec, ...rest } =
+ parsedBody;
const endpointOption = {
endpoint,
chatGptLabel,
promptPrefix,
resendFiles,
imageDetail,
+ iconURL,
+ greeting,
+ spec,
modelOptions: {
...rest,
},
diff --git a/api/server/services/ToolService.js b/api/server/services/ToolService.js
index 5b131acfd7..0a10a9d394 100644
--- a/api/server/services/ToolService.js
+++ b/api/server/services/ToolService.js
@@ -20,6 +20,14 @@ const { redactMessage } = require('~/config/parsers');
const { sleep } = require('~/server/utils');
const { logger } = require('~/config');
+const filteredTools = new Set([
+ 'ChatTool.js',
+ 'CodeSherpa.js',
+ 'CodeSherpaTools.js',
+ 'E2BTools.js',
+ 'extractionChain.js',
+]);
+
/**
* Loads and formats tools from the specified tool directory.
*
@@ -30,10 +38,11 @@ const { logger } = require('~/config');
*
* @param {object} params - The parameters for the function.
* @param {string} params.directory - The directory path where the tools are located.
- * @param {Set<string>} [params.filter=new Set()] - A set of filenames to exclude from loading.
+ * @param {Array<string>} [params.adminFilter=[]] - Array of admin-defined tool keys to exclude from loading.
* @returns {Record<string, FunctionTool>} An object mapping each tool's plugin key to its instance.
*/
-function loadAndFormatTools({ directory, filter = new Set() }) {
+function loadAndFormatTools({ directory, adminFilter = [] }) {
+ const filter = new Set([...adminFilter, ...filteredTools]);
const tools = [];
/* Structured Tools Directory */
const files = fs.readdirSync(directory);
diff --git a/api/server/services/start/interface.js b/api/server/services/start/interface.js
new file mode 100644
index 0000000000..7cda706104
--- /dev/null
+++ b/api/server/services/start/interface.js
@@ -0,0 +1,74 @@
+const { logger } = require('~/config');
+
+/**
+ * Loads the default interface object.
+ * @param {TCustomConfig | undefined} config - The loaded custom configuration.
+ * @param {TConfigDefaults} configDefaults - The custom configuration default values.
+ * @returns {TCustomConfig['interface']} The default interface object.
+ */
+function loadDefaultInterface(config, configDefaults) {
+ const { interface: interfaceConfig } = config ?? {};
+ const { interface: defaults } = configDefaults;
+ const hasModelSpecs = config?.modelSpecs?.list?.length > 0;
+
+ const loadedInterface = {
+ endpointsMenu:
+ interfaceConfig?.endpointsMenu ?? (hasModelSpecs ? false : defaults.endpointsMenu),
+ modelSelect: interfaceConfig?.modelSelect ?? (hasModelSpecs ? false : defaults.modelSelect),
+ parameters: interfaceConfig?.parameters ?? (hasModelSpecs ? false : defaults.parameters),
+ presets: interfaceConfig?.presets ?? (hasModelSpecs ? false : defaults.presets),
+ sidePanel: interfaceConfig?.sidePanel ?? defaults.sidePanel,
+ privacyPolicy: interfaceConfig?.privacyPolicy ?? defaults.privacyPolicy,
+ termsOfService: interfaceConfig?.termsOfService ?? defaults.termsOfService,
+ };
+
+ let i = 0;
+ const logSettings = () => {
+ // log interface object and model specs object (without list) for reference
+ logger.warn(`\`interface\` settings:\n${JSON.stringify(loadedInterface, null, 2)}`);
+ logger.warn(
+ `\`modelSpecs\` settings:\n${JSON.stringify(
+ { ...(config?.modelSpecs ?? {}), list: undefined },
+ null,
+ 2,
+ )}`,
+ );
+ };
+
+ // warn about config.modelSpecs.prioritize if true and presets are enabled, that default presets will conflict with prioritizing model specs.
+ if (config?.modelSpecs?.prioritize && loadedInterface.presets) {
+ logger.warn(
+ 'Note: Prioritizing model specs can conflict with default presets if a default preset is set. It\'s recommended to disable presets from the interface or disable use of a default preset.',
+ );
+ i === 0 && i++;
+ }
+
+ // warn about config.modelSpecs.enforce if true and if any of these, endpointsMenu, modelSelect, presets, or parameters are enabled, that enforcing model specs can conflict with these options.
+ if (
+ config?.modelSpecs?.enforce &&
+ (loadedInterface.endpointsMenu ||
+ loadedInterface.modelSelect ||
+ loadedInterface.presets ||
+ loadedInterface.parameters)
+ ) {
+ logger.warn(
+ 'Note: Enforcing model specs can conflict with the interface options: endpointsMenu, modelSelect, presets, and parameters. It\'s recommended to disable these options from the interface or disable enforcing model specs.',
+ );
+ i === 0 && i++;
+ }
+ // warn if enforce is true and prioritize is not, that enforcing model specs without prioritizing them can lead to unexpected behavior.
+ if (config?.modelSpecs?.enforce && !config?.modelSpecs?.prioritize) {
+ logger.warn(
+ 'Note: Enforcing model specs without prioritizing them can lead to unexpected behavior. It\'s recommended to enable prioritizing model specs if enforcing them.',
+ );
+ i === 0 && i++;
+ }
+
+ if (i > 0) {
+ logSettings();
+ }
+
+ return loadedInterface;
+}
+
+module.exports = { loadDefaultInterface };
diff --git a/api/typedefs.js b/api/typedefs.js
index f1c20468e4..edee411a77 100644
--- a/api/typedefs.js
+++ b/api/typedefs.js
@@ -300,6 +300,18 @@
* @memberof typedefs
*/
+/**
+ * @exports TStartupConfig
+ * @typedef {import('librechat-data-provider').TStartupConfig} TStartupConfig
+ * @memberof typedefs
+ */
+
+/**
+ * @exports TConfigDefaults
+ * @typedef {import('librechat-data-provider').TConfigDefaults} TConfigDefaults
+ * @memberof typedefs
+ */
+
/**
* @exports TPlugin
* @typedef {import('librechat-data-provider').TPlugin} TPlugin
@@ -342,6 +354,18 @@
* @memberof typedefs
*/
+/**
+ * @exports TConversation
+ * @typedef {import('librechat-data-provider').TConversation} TConversation
+ * @memberof typedefs
+ */
+
+/**
+ * @exports TModelSpec
+ * @typedef {import('librechat-data-provider').TModelSpec} TModelSpec
+ * @memberof typedefs
+ */
+
/**
* @exports TPlugin
* @typedef {import('librechat-data-provider').TPlugin} TPlugin
diff --git a/api/utils/loadYaml.js b/api/utils/loadYaml.js
index b7068e209f..50e5d23ec3 100644
--- a/api/utils/loadYaml.js
+++ b/api/utils/loadYaml.js
@@ -6,7 +6,7 @@ function loadYaml(filepath) {
let fileContents = fs.readFileSync(filepath, 'utf8');
return yaml.load(fileContents);
} catch (e) {
- // console.error(e);
+ return e;
}
}
diff --git a/client/src/common/types.ts b/client/src/common/types.ts
index ebb9a89355..e76b79bdb2 100644
--- a/client/src/common/types.ts
+++ b/client/src/common/types.ts
@@ -2,21 +2,24 @@ import { FileSources } from 'librechat-data-provider';
import type { ColumnDef } from '@tanstack/react-table';
import type { SetterOrUpdater } from 'recoil';
import type {
- TSetOption as SetOption,
- TConversation,
- TMessage,
- TPreset,
- TLoginUser,
TUser,
- EModelEndpoint,
Action,
+ TPreset,
+ TPlugin,
+ TMessage,
+ TLoginUser,
AuthTypeEnum,
+ TConversation,
+ EModelEndpoint,
AuthorizationTypeEnum,
+ TSetOption as SetOption,
TokenExchangeMethodEnum,
} from 'librechat-data-provider';
import type { UseMutationResult } from '@tanstack/react-query';
import type { LucideIcon } from 'lucide-react';
+export type TPluginMap = Record<string, TPlugin>;
+
export type GenericSetter<T> = (value: T | ((currentValue: T) => T)) => void;
export type LastSelectedModels = Record<EModelEndpoint, string>;
@@ -32,6 +35,16 @@ export enum IconContext {
message = 'message',
}
+export type IconMapProps = {
+ className?: string;
+ iconURL?: string;
+ context?: 'landing' | 'menu-item' | 'nav' | 'message';
+ endpoint?: string | null;
+ assistantName?: string;
+ avatar?: string;
+ size?: number;
+};
+
export type NavLink = {
title: string;
label?: string;
diff --git a/client/src/components/Chat/Header.tsx b/client/src/components/Chat/Header.tsx
index 868f9292ad..cc76bbbc69 100644
--- a/client/src/components/Chat/Header.tsx
+++ b/client/src/components/Chat/Header.tsx
@@ -1,17 +1,30 @@
+import { useMemo } from 'react';
import { useOutletContext } from 'react-router-dom';
+import { getConfigDefaults } from 'librechat-data-provider';
+import { useGetStartupConfig } from 'librechat-data-provider/react-query';
import type { ContextType } from '~/common';
-import { EndpointsMenu, PresetsMenu, HeaderNewChat } from './Menus';
+import { EndpointsMenu, ModelSpecsMenu, PresetsMenu, HeaderNewChat } from './Menus';
import HeaderOptions from './Input/HeaderOptions';
+const defaultInterface = getConfigDefaults().interface;
+
export default function Header() {
+ const { data: startupConfig } = useGetStartupConfig();
const { navVisible } = useOutletContext<ContextType>();
+ const modelSpecs = useMemo(() => startupConfig?.modelSpecs?.list ?? [], [startupConfig]);
+ const interfaceConfig = useMemo(
+ () => startupConfig?.interface ?? defaultInterface,
+ [startupConfig],
+ );
+
return (
<div className="sticky top-0 z-10 flex h-14 w-full items-center justify-between bg-white p-2 font-semibold dark:bg-gray-800 dark:text-white">
<div className="hide-scrollbar flex items-center gap-2 overflow-x-auto">
{!navVisible && <HeaderNewChat />}
- <EndpointsMenu />
- <HeaderOptions />
- <PresetsMenu />
+ {interfaceConfig.endpointsMenu && <EndpointsMenu />}
+ {modelSpecs?.length > 0 && <ModelSpecsMenu modelSpecs={modelSpecs} />}
+ {<HeaderOptions interfaceConfig={interfaceConfig} />}
+ {interfaceConfig.presets && <PresetsMenu />}
</div>
{/* Empty div for spacing */}
<div />
diff --git a/client/src/components/Chat/Input/HeaderOptions.tsx b/client/src/components/Chat/Input/HeaderOptions.tsx
index b0823b7cc0..ca3420b3cc 100644
--- a/client/src/components/Chat/Input/HeaderOptions.tsx
+++ b/client/src/components/Chat/Input/HeaderOptions.tsx
@@ -3,7 +3,7 @@ import { Settings2 } from 'lucide-react';
import { Root, Anchor } from '@radix-ui/react-popover';
import { useState, useEffect, useMemo } from 'react';
import { tPresetUpdateSchema, EModelEndpoint } from 'librechat-data-provider';
-import type { TPreset } from 'librechat-data-provider';
+import type { TPreset, TInterfaceConfig } from 'librechat-data-provider';
import { EndpointSettings, SaveAsPresetDialog, AlternativeSettings } from '~/components/Endpoints';
import { ModelSelect } from '~/components/Input/ModelSelect';
import { PluginStoreDialog } from '~/components';
@@ -15,7 +15,11 @@ import { Button } from '~/components/ui';
import { cn, cardStyle } from '~/utils/';
import store from '~/store';
-export default function HeaderOptions() {
+export default function HeaderOptions({
+ interfaceConfig,
+}: {
+ interfaceConfig?: Partial<TInterfaceConfig>;
+}) {
const [saveAsDialogShow, setSaveAsDialogShow] = useState<boolean>(false);
const [showPluginStoreDialog, setShowPluginStoreDialog] = useRecoilState(
store.showPluginStoreDialog,
@@ -70,13 +74,15 @@ export default function HeaderOptions() {
<div className="my-auto lg:max-w-2xl xl:max-w-3xl">
<span className="flex w-full flex-col items-center justify-center gap-0 md:order-none md:m-auto md:gap-2">
<div className="z-[61] flex w-full items-center justify-center gap-2">
- <ModelSelect
- conversation={conversation}
- setOption={setOption}
- isMultiChat={true}
- showAbove={false}
- />
- {!noSettings[endpoint] && (
+ {interfaceConfig?.modelSelect && (
+ <ModelSelect
+ conversation={conversation}
+ setOption={setOption}
+ showAbove={false}
+ popover={true}
+ />
+ )}
+ {!noSettings[endpoint] && interfaceConfig?.parameters && (
<Button
type="button"
className={cn(
@@ -90,35 +96,41 @@ export default function HeaderOptions() {
</Button>
)}
</div>
- <OptionsPopover
- visible={showPopover}
- saveAsPreset={saveAsPreset}
- closePopover={() => setShowPopover(false)}
- PopoverButtons={<PopoverButtons />}
- >
- <div className="px-4 py-4">
- <EndpointSettings
- className="[&::-webkit-scrollbar]:w-2"
- conversation={conversation}
- setOption={setOption}
- isMultiChat={true}
- />
- <AlternativeSettings conversation={conversation} setOption={setOption} />
- </div>
- </OptionsPopover>
- <SaveAsPresetDialog
- open={saveAsDialogShow}
- onOpenChange={setSaveAsDialogShow}
- preset={
- tPresetUpdateSchema.parse({
- ...conversation,
- }) as TPreset
- }
- />
- <PluginStoreDialog
- isOpen={showPluginStoreDialog}
- setIsOpen={setShowPluginStoreDialog}
- />
+ {interfaceConfig?.parameters && (
+ <OptionsPopover
+ visible={showPopover}
+ saveAsPreset={saveAsPreset}
+ presetsDisabled={!interfaceConfig?.presets}
+ PopoverButtons={<PopoverButtons />}
+ closePopover={() => setShowPopover(false)}
+ >
+ <div className="px-4 py-4">
+ <EndpointSettings
+ className="[&::-webkit-scrollbar]:w-2"
+ conversation={conversation}
+ setOption={setOption}
+ />
+ <AlternativeSettings conversation={conversation} setOption={setOption} />
+ </div>
+ </OptionsPopover>
+ )}
+ {interfaceConfig?.presets && (
+ <SaveAsPresetDialog
+ open={saveAsDialogShow}
+ onOpenChange={setSaveAsDialogShow}
+ preset={
+ tPresetUpdateSchema.parse({
+ ...conversation,
+ }) as TPreset
+ }
+ />
+ )}
+ {interfaceConfig?.parameters && (
+ <PluginStoreDialog
+ isOpen={showPluginStoreDialog}
+ setIsOpen={setShowPluginStoreDialog}
+ />
+ )}
</span>
</div>
</Anchor>
diff --git a/client/src/components/Chat/Input/OptionsPopover.tsx b/client/src/components/Chat/Input/OptionsPopover.tsx
index f59d94d26d..b123105e53 100644
--- a/client/src/components/Chat/Input/OptionsPopover.tsx
+++ b/client/src/components/Chat/Input/OptionsPopover.tsx
@@ -13,6 +13,7 @@ type TOptionsPopoverProps = {
saveAsPreset: () => void;
closePopover: () => void;
PopoverButtons: ReactNode;
+ presetsDisabled: boolean;
};
export default function OptionsPopover({
@@ -22,6 +23,7 @@ export default function OptionsPopover({
saveAsPreset,
closePopover,
PopoverButtons,
+ presetsDisabled,
}: TOptionsPopoverProps) {
const popoverRef = useRef(null);
useOnClickOutside(
@@ -61,14 +63,16 @@ export default function OptionsPopover({
)}
>
<div className="flex w-full items-center bg-gray-50 px-2 py-2 dark:bg-gray-700">
- <Button
- type="button"
- className="h-auto w-[150px] justify-start rounded-md border-2 border-gray-300/50 bg-transparent px-2 py-1 text-xs font-medium font-normal text-black hover:bg-gray-100 hover:text-black focus:ring-1 focus:ring-green-500/90 dark:border-gray-500/50 dark:bg-transparent dark:text-white dark:hover:bg-gray-600 dark:focus:ring-green-500"
- onClick={saveAsPreset}
- >
- <Save className="mr-1 w-[14px]" />
- {localize('com_endpoint_save_as_preset')}
- </Button>
+ {presetsDisabled ? null : (
+ <Button
+ type="button"
+ className="h-auto w-[150px] justify-start rounded-md border-2 border-gray-300/50 bg-transparent px-2 py-1 text-xs font-medium font-normal text-black hover:bg-gray-100 hover:text-black focus:ring-1 focus:ring-green-500/90 dark:border-gray-500/50 dark:bg-transparent dark:text-white dark:hover:bg-gray-600 dark:focus:ring-green-500"
+ onClick={saveAsPreset}
+ >
+ <Save className="mr-1 w-[14px]" />
+ {localize('com_endpoint_save_as_preset')}
+ </Button>
+ )}
{PopoverButtons}
<Button
type="button"
diff --git a/client/src/components/Chat/Landing.tsx b/client/src/components/Chat/Landing.tsx
index 56093ccac6..b3a53cbce5 100644
--- a/client/src/components/Chat/Landing.tsx
+++ b/client/src/components/Chat/Landing.tsx
@@ -2,21 +2,22 @@ import { EModelEndpoint } from 'librechat-data-provider';
import { useGetEndpointsQuery, useGetStartupConfig } from 'librechat-data-provider/react-query';
import type { ReactNode } from 'react';
import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from '~/components/ui';
+import { getEndpointField, getIconEndpoint, getIconKey } from '~/utils';
import { useChatContext, useAssistantsMapContext } from '~/Providers';
+import ConvoIconURL from '~/components/Endpoints/ConvoIconURL';
import { icons } from './Menus/Endpoints/Icons';
import { BirthdayIcon } from '~/components/svg';
-import { getEndpointField } from '~/utils';
import { useLocalize } from '~/hooks';
export default function Landing({ Header }: { Header?: ReactNode }) {
const { conversation } = useChatContext();
- const { data: endpointsConfig } = useGetEndpointsQuery();
- const { data: startupConfig } = useGetStartupConfig();
const assistantMap = useAssistantsMapContext();
+ const { data: startupConfig } = useGetStartupConfig();
+ const { data: endpointsConfig } = useGetEndpointsQuery();
const localize = useLocalize();
- let { endpoint } = conversation ?? {};
+ let { endpoint = '' } = conversation ?? {};
const { assistant_id = null } = conversation ?? {};
if (
@@ -27,9 +28,11 @@ export default function Landing({ Header }: { Header?: ReactNode }) {
endpoint = EModelEndpoint.openAI;
}
- const endpointType = getEndpointField(endpointsConfig, endpoint, 'type');
- const iconURL = getEndpointField(endpointsConfig, endpoint, 'iconURL');
- const iconKey = endpointType ? 'unknown' : endpoint ?? 'unknown';
+ const iconURL = conversation?.iconURL;
+ endpoint = getIconEndpoint({ endpointsConfig, iconURL, endpoint });
+
+ const endpointIconURL = getEndpointField(endpointsConfig, endpoint, 'iconURL');
+ const iconKey = getIconKey({ endpoint, endpointsConfig, endpointIconURL });
const Icon = icons[iconKey];
const assistant = endpoint === EModelEndpoint.assistants && assistantMap?.[assistant_id ?? ''];
@@ -51,19 +54,29 @@ export default function Landing({ Header }: { Header?: ReactNode }) {
<div className="absolute left-0 right-0">{Header && Header}</div>
<div className="flex h-full flex-col items-center justify-center">
<div className="relative mb-3 h-[72px] w-[72px]">
- <div className={className}>
- {endpoint &&
- Icon &&
- Icon({
- size: 41,
- context: 'landing',
- className: 'h-2/3 w-2/3',
- endpoint: endpoint,
- iconURL: iconURL,
- assistantName,
- avatar,
- })}
- </div>
+ {iconURL && iconURL.includes('http') ? (
+ <ConvoIconURL
+ preset={conversation}
+ endpointIconURL={endpointIconURL}
+ assistantName={assistantName}
+ assistantAvatar={avatar}
+ context="landing"
+ />
+ ) : (
+ <div className={className}>
+ {endpoint &&
+ Icon &&
+ Icon({
+ size: 41,
+ context: 'landing',
+ className: 'h-2/3 w-2/3',
+ iconURL: endpointIconURL,
+ assistantName,
+ endpoint,
+ avatar,
+ })}
+ </div>
+ )}
<TooltipTrigger>
{(startupConfig?.showBirthdayIcon ?? false) && (
<BirthdayIcon className="absolute bottom-12 right-5" />
@@ -88,8 +101,8 @@ export default function Landing({ Header }: { Header?: ReactNode }) {
) : (
<div className="mb-5 text-2xl font-medium dark:text-white">
{endpoint === EModelEndpoint.assistants
- ? localize('com_nav_welcome_assistant')
- : localize('com_nav_welcome_message')}
+ ? conversation?.greeting ?? localize('com_nav_welcome_assistant')
+ : conversation?.greeting ?? localize('com_nav_welcome_message')}
</div>
)}
</div>
diff --git a/client/src/components/Chat/Menus/Endpoints/Icons.tsx b/client/src/components/Chat/Menus/Endpoints/Icons.tsx
index 89e521a664..c77edfdf57 100644
--- a/client/src/components/Chat/Menus/Endpoints/Icons.tsx
+++ b/client/src/components/Chat/Menus/Endpoints/Icons.tsx
@@ -1,4 +1,5 @@
import { EModelEndpoint } from 'librechat-data-provider';
+import type { IconMapProps } from '~/common';
import {
MinimalPlugin,
GPTIcon,
@@ -23,17 +24,7 @@ export const icons = {
[EModelEndpoint.google]: GoogleMinimalIcon,
[EModelEndpoint.bingAI]: BingAIMinimalIcon,
[EModelEndpoint.custom]: CustomMinimalIcon,
- [EModelEndpoint.assistants]: ({
- className = '',
- assistantName,
- avatar,
- size,
- }: {
- className?: string;
- assistantName?: string;
- avatar?: string;
- size?: number;
- }) => {
+ [EModelEndpoint.assistants]: ({ className = '', assistantName, avatar, size }: IconMapProps) => {
if (assistantName && avatar) {
return (
<img
diff --git a/client/src/components/Chat/Menus/Endpoints/MenuItem.tsx b/client/src/components/Chat/Menus/Endpoints/MenuItem.tsx
index fac02a6e78..89c230b799 100644
--- a/client/src/components/Chat/Menus/Endpoints/MenuItem.tsx
+++ b/client/src/components/Chat/Menus/Endpoints/MenuItem.tsx
@@ -1,13 +1,13 @@
import { useState } from 'react';
import { Settings } from 'lucide-react';
import { useRecoilValue } from 'recoil';
-import { EModelEndpoint, modularEndpoints } from 'librechat-data-provider';
+import { EModelEndpoint } from 'librechat-data-provider';
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
-import type { TPreset, TConversation } from 'librechat-data-provider';
+import type { TConversation } from 'librechat-data-provider';
import type { FC } from 'react';
+import { cn, getConvoSwitchLogic, getEndpointField, getIconKey } from '~/utils';
import { useLocalize, useUserKey, useDefaultConvo } from '~/hooks';
import { SetKeyDialog } from '~/components/Input/SetKeyDialog';
-import { cn, getEndpointField } from '~/utils';
import { useChatContext } from '~/Providers';
import { icons } from './Icons';
import store from '~/store';
@@ -43,58 +43,44 @@ const MenuItem: FC<MenuItemProps> = ({
const onSelectEndpoint = (newEndpoint: EModelEndpoint) => {
if (!newEndpoint) {
return;
- } else {
- if (!expiryTime) {
- setDialogOpen(true);
- }
-
- const currentEndpoint = conversation?.endpoint;
- const template: Partial<TPreset> = {
- ...conversation,
- endpoint: newEndpoint,
- conversationId: 'new',
- };
- const isAssistantSwitch =
- newEndpoint === EModelEndpoint.assistants &&
- currentEndpoint === EModelEndpoint.assistants &&
- currentEndpoint === newEndpoint;
-
- const { conversationId } = conversation ?? {};
- const isExistingConversation = conversationId && conversationId !== 'new';
- const currentEndpointType =
- getEndpointField(endpointsConfig, currentEndpoint, 'type') ?? currentEndpoint;
- const newEndpointType = getEndpointField(endpointsConfig, newEndpoint, 'type') ?? newEndpoint;
-
- const hasEndpoint = modularEndpoints.has(currentEndpoint ?? '');
- const hasCurrentEndpointType = modularEndpoints.has(currentEndpointType ?? '');
- const isCurrentModular = hasEndpoint || hasCurrentEndpointType || isAssistantSwitch;
+ }
- const hasNewEndpoint = modularEndpoints.has(newEndpoint ?? '');
- const hasNewEndpointType = modularEndpoints.has(newEndpointType ?? '');
- const isNewModular = hasNewEndpoint || hasNewEndpointType || isAssistantSwitch;
+ if (!expiryTime) {
+ setDialogOpen(true);
+ }
- const endpointsMatch = currentEndpoint === newEndpoint;
- const shouldSwitch = endpointsMatch || modularChat || isAssistantSwitch;
+ const {
+ shouldSwitch,
+ isNewModular,
+ isCurrentModular,
+ isExistingConversation,
+ newEndpointType,
+ template,
+ } = getConvoSwitchLogic({
+ newEndpoint,
+ modularChat,
+ conversation,
+ endpointsConfig,
+ });
- if (isExistingConversation && isCurrentModular && isNewModular && shouldSwitch) {
- template.endpointType = newEndpointType;
+ if (isExistingConversation && isCurrentModular && isNewModular && shouldSwitch) {
+ template.endpointType = newEndpointType;
- const currentConvo = getDefaultConversation({
- /* target endpointType is necessary to avoid endpoint mixing */
- conversation: { ...(conversation ?? {}), endpointType: template.endpointType },
- preset: template,
- });
+ const currentConvo = getDefaultConversation({
+ /* target endpointType is necessary to avoid endpoint mixing */
+ conversation: { ...(conversation ?? {}), endpointType: template.endpointType },
+ preset: template,
+ });
- /* We don't reset the latest message, only when changing settings mid-converstion */
- newConversation({ template: currentConvo, preset: currentConvo, keepLatestMessage: true });
- return;
- }
- newConversation({ template: { ...(template as Partial<TConversation>) } });
+ /* We don't reset the latest message, only when changing settings mid-converstion */
+ newConversation({ template: currentConvo, preset: currentConvo, keepLatestMessage: true });
+ return;
}
+ newConversation({ template: { ...(template as Partial<TConversation>) } });
};
const endpointType = getEndpointField(endpointsConfig, endpoint, 'type');
- const iconKey = endpointType ? 'unknown' : endpoint ?? 'unknown';
+ const iconKey = getIconKey({ endpoint, endpointsConfig, endpointType });
const Icon = icons[iconKey];
return (
diff --git a/client/src/components/Chat/Menus/Models/MenuButton.tsx b/client/src/components/Chat/Menus/Models/MenuButton.tsx
new file mode 100644
index 0000000000..404b858e7c
--- /dev/null
+++ b/client/src/components/Chat/Menus/Models/MenuButton.tsx
@@ -0,0 +1,49 @@
+import { Trigger } from '@radix-ui/react-popover';
+import type { TModelSpec, TEndpointsConfig } from 'librechat-data-provider';
+import { useLocalize } from '~/hooks';
+import SpecIcon from './SpecIcon';
+
+export default function MenuButton({
+ selected,
+ primaryText = '',
+ secondaryText = '',
+ endpointsConfig,
+}: {
+ selected?: TModelSpec;
+ primaryText?: string;
+ secondaryText?: string;
+ endpointsConfig: TEndpointsConfig;
+}) {
+ const localize = useLocalize();
+ return (
+ <Trigger asChild>
+ <div
+ className="group flex cursor-pointer items-center gap-1 rounded-xl px-3 py-2 text-lg font-medium hover:bg-gray-50 radix-state-open:bg-gray-50 dark:hover:bg-gray-700 dark:radix-state-open:bg-gray-700"
+ // type="button"
+ >
+ {selected && selected.showIconInHeader && (
+ <SpecIcon currentSpec={selected} endpointsConfig={endpointsConfig} />
+ )}
+ <div>
+ {!selected ? localize('com_ui_none_selected') : primaryText}{' '}
+ {!!secondaryText && <span className="text-token-text-secondary">{secondaryText}</span>}
+ </div>
+ <svg
+ width="16"
+ height="17"
+ viewBox="0 0 16 17"
+ fill="none"
+ className="text-token-text-tertiary"
+ >
+ <path
+ d="M11.3346 7.83203L8.00131 11.1654L4.66797 7.83203"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ />
+ </svg>
+ </div>
+ </Trigger>
+ );
+}
diff --git a/client/src/components/Chat/Menus/Models/ModelSpec.tsx b/client/src/components/Chat/Menus/Models/ModelSpec.tsx
new file mode 100644
index 0000000000..e1f578915d
--- /dev/null
+++ b/client/src/components/Chat/Menus/Models/ModelSpec.tsx
@@ -0,0 +1,130 @@
+import { useState, useMemo } from 'react';
+import { Settings } from 'lucide-react';
+import type { FC } from 'react';
+import type { TModelSpec, TEndpointsConfig } from 'librechat-data-provider';
+import { SetKeyDialog } from '~/components/Input/SetKeyDialog';
+import { useLocalize, useUserKey } from '~/hooks';
+import { cn, getEndpointField } from '~/utils';
+import SpecIcon from './SpecIcon';
+
+type MenuItemProps = {
+ title: string;
+ spec: TModelSpec;
+ selected: boolean;
+ description?: string;
+ userProvidesKey: boolean;
+ endpointsConfig: TEndpointsConfig;
+ onClick?: () => void;
+ // iconPath: string;
+ // hoverContent?: string;
+};
+
+const MenuItem: FC<MenuItemProps> = ({
+ title,
+ spec,
+ selected,
+ description,
+ userProvidesKey,
+ endpointsConfig,
+ onClick,
+ ...rest
+}) => {
+ const { endpoint } = spec.preset;
+ const [isDialogOpen, setDialogOpen] = useState(false);
+ const { getExpiry } = useUserKey(endpoint ?? '');
+ const localize = useLocalize();
+ const expiryTime = getExpiry();
+
+ const clickHandler = () => {
+ if (!expiryTime) {
+ setDialogOpen(true);
+ }
+ if (onClick) {
+ onClick();
+ }
+ };
+
+ const endpointType = useMemo(
+ () => spec.preset.endpointType ?? getEndpointField(endpointsConfig, endpoint, 'type'),
+ [spec, endpointsConfig, endpoint],
+ );
+
+ const { showIconInMenu = true } = spec;
+
+ return (
+ <>
+ <div
+ role="menuitem"
+ className="group m-1.5 flex cursor-pointer gap-2 rounded px-1 py-2.5 !pr-3 text-sm !opacity-100 hover:bg-black/5 focus:ring-0 radix-disabled:pointer-events-none radix-disabled:opacity-50 dark:hover:bg-white/5"
+ tabIndex={-1}
+ {...rest}
+ onClick={clickHandler}
+ >
+ <div className="flex grow items-center justify-between gap-2">
+ <div>
+ <div className="flex items-center gap-2">
+ {showIconInMenu && <SpecIcon currentSpec={spec} endpointsConfig={endpointsConfig} />}
+ <div>
+ {title}
+ <div className="text-token-text-tertiary">{description}</div>
+ </div>
+ </div>
+ </div>
+ <div className="flex items-center gap-2">
+ {userProvidesKey ? (
+ <div className="text-token-text-primary" key={`set-key-${endpoint}`}>
+ <button
+ className={cn(
+ 'invisible flex gap-x-1 group-hover:visible',
+ selected ? 'visible' : '',
+ expiryTime
+ ? 'w-full rounded-lg p-2 hover:bg-gray-200 dark:hover:bg-gray-900'
+ : '',
+ )}
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setDialogOpen(true);
+ }}
+ >
+ <div className={cn('invisible group-hover:visible', expiryTime ? 'text-xs' : '')}>
+ {localize('com_endpoint_config_key')}
+ </div>
+ <Settings className={cn(expiryTime ? 'icon-sm' : 'icon-md stroke-1')} />
+ </button>
+ </div>
+ ) : null}
+ {selected && (
+ <svg
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ className="icon-md block"
+ // className="icon-md block group-hover:hidden"
+ >
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12ZM16.0755 7.93219C16.5272 8.25003 16.6356 8.87383 16.3178 9.32549L11.5678 16.0755C11.3931 16.3237 11.1152 16.4792 10.8123 16.4981C10.5093 16.517 10.2142 16.3973 10.0101 16.1727L7.51006 13.4227C7.13855 13.014 7.16867 12.3816 7.57733 12.0101C7.98598 11.6386 8.61843 11.6687 8.98994 12.0773L10.6504 13.9039L14.6822 8.17451C15 7.72284 15.6238 7.61436 16.0755 7.93219Z"
+ fill="currentColor"
+ />
+ </svg>
+ )}
+ </div>
+ </div>
+ </div>
+ {userProvidesKey && (
+ <SetKeyDialog
+ open={isDialogOpen}
+ onOpenChange={setDialogOpen}
+ endpoint={endpoint ?? ''}
+ endpointType={endpointType}
+ />
+ )}
+ </>
+ );
+};
+
+export default MenuItem;
diff --git a/client/src/components/Chat/Menus/Models/ModelSpecs.tsx b/client/src/components/Chat/Menus/Models/ModelSpecs.tsx
new file mode 100644
index 0000000000..6d3a767462
--- /dev/null
+++ b/client/src/components/Chat/Menus/Models/ModelSpecs.tsx
@@ -0,0 +1,44 @@
+import type { FC } from 'react';
+import { Close } from '@radix-ui/react-popover';
+import { AuthType } from 'librechat-data-provider';
+import type { TModelSpec, TEndpointsConfig } from 'librechat-data-provider';
+import MenuSeparator from '~/components/Chat/Menus/UI/MenuSeparator';
+import ModelSpec from './ModelSpec';
+
+const ModelSpecs: FC<{
+ specs?: TModelSpec[];
+ selected?: TModelSpec;
+ setSelected?: (spec: TModelSpec) => void;
+ endpointsConfig: TEndpointsConfig;
+}> = ({ specs = [], selected, setSelected = () => ({}), endpointsConfig }) => {
+ return (
+ <>
+ {specs &&
+ specs.map((spec, i) => {
+ if (!spec) {
+ return null;
+ }
+ return (
+ <Close asChild key={`spec-${spec.name}`}>
+ <div key={`spec-${spec.name}`}>
+ <ModelSpec
+ spec={spec}
+ title={spec.label}
+ key={`spec-item-${spec.name}`}
+ description={spec.description}
+ onClick={() => setSelected(spec)}
+ data-testid={`spec-item-${spec.name}`}
+ selected={selected?.name === spec.name}
+ userProvidesKey={spec.authType === AuthType.USER_PROVIDED}
+ endpointsConfig={endpointsConfig}
+ />
+ {i !== specs.length - 1 && <MenuSeparator />}
+ </div>
+ </Close>
+ );
+ })}
+ </>
+ );
+};
+
+export default ModelSpecs;
diff --git a/client/src/components/Chat/Menus/Models/ModelSpecsMenu.tsx b/client/src/components/Chat/Menus/Models/ModelSpecsMenu.tsx
new file mode 100644
index 0000000000..dbd5a441de
--- /dev/null
+++ b/client/src/components/Chat/Menus/Models/ModelSpecsMenu.tsx
@@ -0,0 +1,106 @@
+import { useMemo } from 'react';
+import { useRecoilValue } from 'recoil';
+import { EModelEndpoint } from 'librechat-data-provider';
+import { Content, Portal, Root } from '@radix-ui/react-popover';
+import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
+import type { TModelSpec, TConversation, TEndpointsConfig } from 'librechat-data-provider';
+import { getConvoSwitchLogic, getModelSpecIconURL } from '~/utils';
+import { useDefaultConvo, useNewConvo } from '~/hooks';
+import { useChatContext } from '~/Providers';
+import MenuButton from './MenuButton';
+import ModelSpecs from './ModelSpecs';
+import store from '~/store';
+
+export default function ModelSpecsMenu({ modelSpecs }: { modelSpecs: TModelSpec[] }) {
+ const { conversation } = useChatContext();
+ const { newConversation } = useNewConvo();
+
+ const { data: endpointsConfig = {} as TEndpointsConfig } = useGetEndpointsQuery();
+ const modularChat = useRecoilValue(store.modularChat);
+ const getDefaultConversation = useDefaultConvo();
+
+ const onSelectSpec = (spec: TModelSpec) => {
+ const { preset } = spec;
+ preset.iconURL = getModelSpecIconURL(spec);
+ preset.spec = spec.name;
+ const { endpoint: newEndpoint } = preset;
+ if (!newEndpoint) {
+ return;
+ }
+
+ const {
+ shouldSwitch,
+ isNewModular,
+ isCurrentModular,
+ isExistingConversation,
+ newEndpointType,
+ template,
+ } = getConvoSwitchLogic({
+ newEndpoint,
+ modularChat,
+ conversation,
+ endpointsConfig,
+ });
+
+ if (isExistingConversation && isCurrentModular && isNewModular && shouldSwitch) {
+ template.endpointType = newEndpointType as EModelEndpoint | undefined;
+
+ const currentConvo = getDefaultConversation({
+ /* target endpointType is necessary to avoid endpoint mixing */
+ conversation: { ...(conversation ?? {}), endpointType: template.endpointType },
+ preset: template,
+ });
+
+ /* We don't reset the latest message, only when changing settings mid-converstion */
+ newConversation({ template: currentConvo, preset, keepLatestMessage: true });
+ return;
+ }
+
+ newConversation({ template: { ...(template as Partial<TConversation>) }, preset });
+ };
+
+ const selected = useMemo(() => {
+ const spec = modelSpecs?.find((spec) => spec.name === conversation?.spec);
+ if (!spec) {
+ return undefined;
+ }
+ return spec;
+ }, [modelSpecs, conversation?.spec]);
+
+ return (
+ <Root>
+ <MenuButton
+ primaryText={selected?.label ?? ''}
+ selected={selected}
+ endpointsConfig={endpointsConfig}
+ />
+ <Portal>
+ {modelSpecs && modelSpecs?.length && (
+ <div
+ style={{
+ position: 'fixed',
+ left: '0px',
+ top: '0px',
+ transform: 'translate3d(268px, 50px, 0px)',
+ minWidth: 'max-content',
+ zIndex: 'auto',
+ }}
+ >
+ <Content
+ side="bottom"
+ align="start"
+ className="models-scrollbar mt-2 max-h-[65vh] min-w-[340px] max-w-xs overflow-y-auto rounded-lg border border-gray-100 bg-white shadow-lg dark:border-gray-700 dark:bg-gray-700 dark:text-white lg:max-h-[75vh]"
+ >
+ <ModelSpecs
+ specs={modelSpecs}
+ selected={selected}
+ setSelected={onSelectSpec}
+ endpointsConfig={endpointsConfig}
+ />
+ </Content>
+ </div>
+ )}
+ </Portal>
+ </Root>
+ );
+}
diff --git a/client/src/components/Chat/Menus/Models/SpecIcon.tsx b/client/src/components/Chat/Menus/Models/SpecIcon.tsx
new file mode 100644
index 0000000000..5235dd4860
--- /dev/null
+++ b/client/src/components/Chat/Menus/Models/SpecIcon.tsx
@@ -0,0 +1,50 @@
+import React from 'react';
+import type { TModelSpec, TEndpointsConfig } from 'librechat-data-provider';
+import type { IconMapProps } from '~/common';
+import { getModelSpecIconURL, getIconKey, getEndpointField } from '~/utils';
+import { icons } from '~/components/Chat/Menus/Endpoints/Icons';
+
+interface SpecIconProps {
+ currentSpec: TModelSpec;
+ endpointsConfig: TEndpointsConfig;
+}
+
+const SpecIcon: React.FC<SpecIconProps> = ({ currentSpec, endpointsConfig }) => {
+ const iconURL = getModelSpecIconURL(currentSpec);
+ const { endpoint } = currentSpec.preset;
+ const endpointIconURL = getEndpointField(endpointsConfig, endpoint, 'iconURL');
+ const iconKey = getIconKey({ endpoint, endpointsConfig, endpointIconURL });
+ let Icon: (props: IconMapProps) => React.JSX.Element;
+
+ if (!iconURL?.includes('http')) {
+ Icon = icons[iconKey] ?? icons.unknown;
+ } else {
+ Icon = iconURL
+ ? () => (
+ <div
+ className="icon-xl mr-1 shrink-0 overflow-hidden rounded-full "
+ style={{ width: '20', height: '20' }}
+ >
+ <img
+ src={iconURL}
+ alt={currentSpec.name}
+ style={{ width: '100%', height: '100%' }}
+ className="object-cover"
+ />
+ </div>
+ )
+ : icons[endpoint ?? ''] ?? icons.unknown;
+ }
+
+ return (
+ <Icon
+ size={20}
+ endpoint={endpoint}
+ context="menu-item"
+ iconURL={endpointIconURL}
+ className="icon-lg mr-1 shrink-0 dark:text-white"
+ />
+ );
+};
+
+export default SpecIcon;
diff --git a/client/src/components/Chat/Menus/Models/fakeData.ts b/client/src/components/Chat/Menus/Models/fakeData.ts
new file mode 100644
index 0000000000..7c994adb7b
--- /dev/null
+++ b/client/src/components/Chat/Menus/Models/fakeData.ts
@@ -0,0 +1,46 @@
+import { EModelEndpoint, AuthType } from 'librechat-data-provider';
+import type { TModelSpec } from 'librechat-data-provider';
+
+export const data: TModelSpec[] = [
+ {
+ name: 'commander_01',
+ label: 'Commander in Chief',
+ description:
+ 'Salute your president, soldier! Salute your president, soldier! Salute your president, soldier!',
+ iconURL: 'https://i.kym-cdn.com/entries/icons/facebook/000/017/252/2f0.jpg',
+ // iconURL: EModelEndpoint.openAI,
+ preset: {
+ endpoint: 'Ollama',
+ greeting: 'My fellow Americans,',
+ // 'endpointType': EModelEndpoint.custom,
+ frequency_penalty: 0,
+ // 'imageDetail': 'auto',
+ model: 'command-r',
+ presence_penalty: 0,
+ promptPrefix: null,
+ resendFiles: false,
+ temperature: 0.8,
+ top_p: 0.5,
+ },
+ authType: AuthType.SYSTEM_DEFINED,
+ },
+ {
+ name: 'vision_pro',
+ label: 'Vision Pro',
+ description:
+ 'Salute your president, soldier! Salute your president, soldier! Salute your president, soldier!',
+ // iconURL: 'https://i.ytimg.com/vi/SaneSRqePVY/maxresdefault.jpg',
+ iconURL: EModelEndpoint.openAI, // Allow using project-included icons
+ preset: {
+ chatGptLabel: 'Vision Helper',
+ greeting: 'What\'s up!!',
+ endpoint: EModelEndpoint.openAI,
+ model: 'gpt-4-turbo',
+ promptPrefix:
+ 'Examine images closely to understand its style, colors, composition, and other elements. Then, craft a detailed prompt to that closely resemble the original. Your focus is on accuracy in replicating the style, colors, techniques, and details of the original image in written form. Your prompt must be excruciatingly detailed as it will be given to an image generating AI for image generation. \n',
+ temperature: 0.8,
+ top_p: 1,
+ },
+ authType: AuthType.SYSTEM_DEFINED,
+ },
+];
diff --git a/client/src/components/Chat/Menus/Presets/EditPresetDialog.tsx b/client/src/components/Chat/Menus/Presets/EditPresetDialog.tsx
index da9bd8c113..9022b7e202 100644
--- a/client/src/components/Chat/Menus/Presets/EditPresetDialog.tsx
+++ b/client/src/components/Chat/Menus/Presets/EditPresetDialog.tsx
@@ -105,7 +105,6 @@ const EditPresetDialog = ({
conversation={preset}
setOption={setOption}
isPreset={true}
- isMultiChat={true}
className="h-full md:mb-4 md:h-[440px]"
/>
</div>
diff --git a/client/src/components/Chat/Menus/Presets/PresetItems.tsx b/client/src/components/Chat/Menus/Presets/PresetItems.tsx
index df4742aeab..77d60d33fc 100644
--- a/client/src/components/Chat/Menus/Presets/PresetItems.tsx
+++ b/client/src/components/Chat/Menus/Presets/PresetItems.tsx
@@ -4,11 +4,11 @@ import { Flipper, Flipped } from 'react-flip-toolkit';
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
import type { FC } from 'react';
import type { TPreset } from 'librechat-data-provider';
+import { getPresetTitle, getEndpointField, getIconKey } from '~/utils';
import FileUpload from '~/components/Chat/Input/Files/FileUpload';
import { PinIcon, EditIcon, TrashIcon } from '~/components/svg';
+import { Dialog, DialogTrigger, Label } from '~/components/ui';
import DialogTemplate from '~/components/ui/DialogTemplate';
-import { getPresetTitle, getEndpointField } from '~/utils';
-import { Dialog, DialogTrigger, Label } from '~/components/ui/';
import { MenuSeparator, MenuItem } from '../UI';
import { icons } from '../Endpoints/Icons';
import { useLocalize } from '~/hooks';
@@ -115,9 +115,7 @@ const PresetItems: FC<{
return null;
}
- const iconKey = getEndpointField(endpointsConfig, preset.endpoint, 'type')
- ? 'unknown'
- : preset.endpointType ?? preset.endpoint ?? 'unknown';
+ const iconKey = getIconKey({ endpoint: preset.endpoint, endpointsConfig });
const Icon = icons[iconKey];
return (
diff --git a/client/src/components/Chat/Menus/index.ts b/client/src/components/Chat/Menus/index.ts
index d505f76510..f77208fe55 100644
--- a/client/src/components/Chat/Menus/index.ts
+++ b/client/src/components/Chat/Menus/index.ts
@@ -1,3 +1,4 @@
-export { default as EndpointsMenu } from './EndpointsMenu';
export { default as PresetsMenu } from './PresetsMenu';
+export { default as EndpointsMenu } from './EndpointsMenu';
export { default as HeaderNewChat } from './HeaderNewChat';
+export { default as ModelSpecsMenu } from './Models/ModelSpecsMenu';
diff --git a/client/src/components/Chat/Messages/Message.tsx b/client/src/components/Chat/Messages/Message.tsx
index 0332b8f0ec..b1d105a365 100644
--- a/client/src/components/Chat/Messages/Message.tsx
+++ b/client/src/components/Chat/Messages/Message.tsx
@@ -1,6 +1,7 @@
import { useRecoilValue } from 'recoil';
import { useAuthContext, useMessageHelpers, useLocalize } from '~/hooks';
import type { TMessageProps } from '~/common';
+import Icon from '~/components/Chat/Messages/MessageIcon';
import { Plugin } from '~/components/Messages/Content';
import MessageContent from './Content/MessageContent';
import SiblingSwitch from './SiblingSwitch';
@@ -18,7 +19,6 @@ export default function Message(props: TMessageProps) {
const {
ask,
- icon,
edit,
isLast,
enterEdit,
@@ -60,11 +60,7 @@ export default function Message(props: TMessageProps) {
<div>
<div className="pt-0.5">
<div className="flex h-6 w-6 items-center justify-center overflow-hidden rounded-full">
- {typeof icon === 'string' && /[^\\x00-\\x7F]+/.test(icon as string) ? (
- <span className=" direction-rtl w-40 overflow-x-scroll">{icon}</span>
- ) : (
- icon
- )}
+ <Icon message={message} conversation={conversation} />
</div>
</div>
</div>
diff --git a/client/src/components/Chat/Messages/MessageIcon.tsx b/client/src/components/Chat/Messages/MessageIcon.tsx
new file mode 100644
index 0000000000..6910feeb2f
--- /dev/null
+++ b/client/src/components/Chat/Messages/MessageIcon.tsx
@@ -0,0 +1,58 @@
+import { useMemo } from 'react';
+import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
+import type { TMessage, TPreset, Assistant } from 'librechat-data-provider';
+import type { TMessageProps } from '~/common';
+import ConvoIconURL from '~/components/Endpoints/ConvoIconURL';
+import { getEndpointField, getIconEndpoint } from '~/utils';
+import Icon from '~/components/Endpoints/Icon';
+
+export default function MessageIcon(
+ props: Pick<TMessageProps, 'message' | 'conversation'> & {
+ assistant?: false | Assistant;
+ },
+) {
+ const { data: endpointsConfig } = useGetEndpointsQuery();
+ const { message, conversation, assistant } = props;
+
+ const assistantName = assistant ? (assistant.name as string | undefined) : '';
+ const assistantAvatar = assistant ? (assistant.metadata?.avatar as string | undefined) : '';
+
+ const messageSettings = useMemo(
+ () => ({
+ ...(conversation ?? {}),
+ ...({
+ ...message,
+ iconURL: message?.iconURL ?? '',
+ } as TMessage),
+ }),
+ [conversation, message],
+ );
+
+ const iconURL = messageSettings?.iconURL;
+ let endpoint = messageSettings?.endpoint;
+ endpoint = getIconEndpoint({ endpointsConfig, iconURL, endpoint });
+ const endpointIconURL = getEndpointField(endpointsConfig, endpoint, 'iconURL');
+
+ if (!message?.isCreatedByUser && iconURL && iconURL.includes('http')) {
+ return (
+ <ConvoIconURL
+ preset={messageSettings as typeof messageSettings & TPreset}
+ context="message"
+ assistantAvatar={assistantAvatar}
+ endpointIconURL={endpointIconURL}
+ assistantName={assistantName}
+ />
+ );
+ }
+
+ return (
+ <Icon
+ {...messageSettings}
+ endpoint={endpoint}
+ iconURL={!assistant ? endpointIconURL : assistantAvatar}
+ model={message?.model ?? conversation?.model}
+ assistantName={assistantName}
+ size={28.8}
+ />
+ );
+}
diff --git a/client/src/components/Chat/Messages/MessageParts.tsx b/client/src/components/Chat/Messages/MessageParts.tsx
index 8d0f2f88f9..a055ef83ea 100644
--- a/client/src/components/Chat/Messages/MessageParts.tsx
+++ b/client/src/components/Chat/Messages/MessageParts.tsx
@@ -1,5 +1,6 @@
-import ContentParts from './Content/ContentParts';
import type { TMessageProps } from '~/common';
+import Icon from '~/components/Chat/Messages/MessageIcon';
+import ContentParts from './Content/ContentParts';
import SiblingSwitch from './SiblingSwitch';
import { useMessageHelpers } from '~/hooks';
// eslint-disable-next-line import/no-cycle
@@ -14,7 +15,6 @@ export default function Message(props: TMessageProps) {
const {
ask,
- icon,
edit,
isLast,
enterEdit,
@@ -47,11 +47,7 @@ export default function Message(props: TMessageProps) {
<div>
<div className="pt-0.5">
<div className="shadow-stroke flex h-6 w-6 items-center justify-center overflow-hidden rounded-full">
- {typeof icon === 'string' && /[^\\x00-\\x7F]+/.test(icon as string) ? (
- <span className=" direction-rtl w-40 overflow-x-scroll">{icon}</span>
- ) : (
- icon
- )}
+ <Icon message={message} conversation={conversation} assistant={assistant} />
</div>
</div>
</div>
diff --git a/client/src/components/Chat/Presentation.tsx b/client/src/components/Chat/Presentation.tsx
index 8701973ade..b3333f3067 100644
--- a/client/src/components/Chat/Presentation.tsx
+++ b/client/src/components/Chat/Presentation.tsx
@@ -1,6 +1,7 @@
-import { useEffect, useMemo } from 'react';
import { useRecoilValue } from 'recoil';
-import { FileSources } from 'librechat-data-provider';
+import { useEffect, useMemo } from 'react';
+import { useGetStartupConfig } from 'librechat-data-provider/react-query';
+import { FileSources, LocalStorageKeys, getConfigDefaults } from 'librechat-data-provider';
import type { ExtendedFile } from '~/common';
import { useDragHelpers, useSetFilesToDelete } from '~/hooks';
import DragDropOverlay from './Input/Files/DragDropOverlay';
@@ -8,6 +9,8 @@ import { useDeleteFilesMutation } from '~/data-provider';
import { SidePanel } from '~/components/SidePanel';
import store from '~/store';
+const defaultInterface = getConfigDefaults().interface;
+
export default function Presentation({
children,
useSidePanel = false,
@@ -17,9 +20,16 @@ export default function Presentation({
panel?: React.ReactNode;
useSidePanel?: boolean;
}) {
+ const { data: startupConfig } = useGetStartupConfig();
const hideSidePanel = useRecoilValue(store.hideSidePanel);
- const { isOver, canDrop, drop } = useDragHelpers();
+ const interfaceConfig = useMemo(
+ () => startupConfig?.interface ?? defaultInterface,
+ [startupConfig],
+ );
+
const setFilesToDelete = useSetFilesToDelete();
+ const { isOver, canDrop, drop } = useDragHelpers();
+
const { mutateAsync } = useDeleteFilesMutation({
onSuccess: () => {
console.log('Temporary Files deleted');
@@ -31,7 +41,7 @@ export default function Presentation({
});
useEffect(() => {
- const filesToDelete = localStorage.getItem('filesToDelete');
+ const filesToDelete = localStorage.getItem(LocalStorageKeys.FILES_TO_DELETE);
const map = JSON.parse(filesToDelete ?? '{}') as Record<string, ExtendedFile>;
const files = Object.values(map)
.filter((file) => file.filepath && file.source && !file.embedded && file.temp_file_id)
@@ -69,7 +79,7 @@ export default function Presentation({
</div>
);
- if (useSidePanel && !hideSidePanel) {
+ if (useSidePanel && !hideSidePanel && interfaceConfig.sidePanel) {
return (
<div
ref={drop}
diff --git a/client/src/components/Conversations/Convo.tsx b/client/src/components/Conversations/Convo.tsx
index b2bc5c262a..49e2f40f4f 100644
--- a/client/src/components/Conversations/Convo.tsx
+++ b/client/src/components/Conversations/Convo.tsx
@@ -1,16 +1,16 @@
import { useRecoilValue } from 'recoil';
import { useParams } from 'react-router-dom';
import { useState, useRef, useMemo } from 'react';
-import { EModelEndpoint } from 'librechat-data-provider';
+import { EModelEndpoint, LocalStorageKeys } from 'librechat-data-provider';
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
import type { MouseEvent, FocusEvent, KeyboardEvent } from 'react';
-import { useConversations, useNavigateToConvo } from '~/hooks';
+import { MinimalIcon, ConvoIconURL } from '~/components/Endpoints';
import { useUpdateConversationMutation } from '~/data-provider';
-import { MinimalIcon } from '~/components/Endpoints';
+import { useConversations, useNavigateToConvo } from '~/hooks';
+import { getEndpointField, getIconEndpoint } from '~/utils';
import { NotificationSeverity } from '~/common';
import { useToastContext } from '~/Providers';
import DeleteButton from './DeleteButton';
-import { getEndpointField } from '~/utils';
import RenameButton from './RenameButton';
import store from '~/store';
@@ -51,11 +51,15 @@ export default function Conversation({ conversation, retainView, toggleNav, isLa
if (conversation?.endpoint === EModelEndpoint.gptPlugins) {
let lastSelectedTools = [];
try {
- lastSelectedTools = JSON.parse(localStorage.getItem('lastSelectedTools') ?? '') ?? [];
+ lastSelectedTools =
+ JSON.parse(localStorage.getItem(LocalStorageKeys.LAST_TOOLS) ?? '') ?? [];
} catch (e) {
// console.error(e);
}
- navigateToConvo({ ...conversation, tools: lastSelectedTools });
+ navigateToConvo({
+ ...conversation,
+ tools: conversation?.tools?.length ? conversation?.tools : lastSelectedTools,
+ });
} else {
navigateToConvo(conversation);
}
@@ -95,19 +99,35 @@ export default function Conversation({ conversation, retainView, toggleNav, isLa
);
};
- const icon = MinimalIcon({
- size: 20,
- iconURL: getEndpointField(endpointsConfig, conversation.endpoint, 'iconURL'),
- endpoint: conversation.endpoint,
- endpointType: conversation.endpointType,
- model: conversation.model,
- error: false,
- className: 'mr-0',
- isCreatedByUser: false,
- chatGptLabel: undefined,
- modelLabel: undefined,
- jailbreak: undefined,
- });
+ const iconURL = conversation.iconURL ?? '';
+ let endpoint = conversation.endpoint;
+ endpoint = getIconEndpoint({ endpointsConfig, iconURL, endpoint });
+
+ const endpointType = getEndpointField(endpointsConfig, endpoint, 'type');
+ const endpointIconURL = getEndpointField(endpointsConfig, endpoint, 'iconURL');
+
+ let icon: React.ReactNode | null = null;
+ if (iconURL && iconURL.includes('http')) {
+ icon = ConvoIconURL({
+ preset: conversation,
+ context: 'menu-item',
+ endpointIconURL,
+ });
+ } else {
+ icon = MinimalIcon({
+ size: 20,
+ iconURL: endpointIconURL,
+ endpoint,
+ endpointType,
+ model: conversation.model,
+ error: false,
+ className: 'mr-0',
+ isCreatedByUser: false,
+ chatGptLabel: undefined,
+ modelLabel: undefined,
+ jailbreak: undefined,
+ });
+ }
const handleKeyDown = (e: KeyEvent) => {
if (e.key === 'Enter') {
diff --git a/client/src/components/Endpoints/AlternativeSettings.tsx b/client/src/components/Endpoints/AlternativeSettings.tsx
index 6420e369b7..2ee51da492 100644
--- a/client/src/components/Endpoints/AlternativeSettings.tsx
+++ b/client/src/components/Endpoints/AlternativeSettings.tsx
@@ -10,7 +10,7 @@ export default function AlternativeSettings({
setOption,
isPreset = false,
className = '',
-}: TSettingsProps & { isMultiChat?: boolean }) {
+}: TSettingsProps) {
const currentSettingsView = useRecoilValue(store.currentSettingsView);
if (!conversation?.endpoint || currentSettingsView === SettingsViews.default) {
return null;
diff --git a/client/src/components/Endpoints/ConvoIconURL.tsx b/client/src/components/Endpoints/ConvoIconURL.tsx
new file mode 100644
index 0000000000..31760c5784
--- /dev/null
+++ b/client/src/components/Endpoints/ConvoIconURL.tsx
@@ -0,0 +1,78 @@
+import React from 'react';
+import type { TPreset } from 'librechat-data-provider';
+import type { IconMapProps } from '~/common';
+import { icons } from '~/components/Chat/Menus/Endpoints/Icons';
+
+interface ConvoIconURLProps {
+ preset: TPreset | null;
+ endpointIconURL?: string;
+ assistantName?: string;
+ context?: 'landing' | 'menu-item' | 'nav' | 'message';
+ assistantAvatar?: string;
+}
+
+const classMap = {
+ 'menu-item': 'relative flex h-full items-center justify-center overflow-hidden rounded-full',
+ message: 'icon-md',
+ default: 'icon-xl relative flex h-full overflow-hidden rounded-full',
+};
+
+const styleMap = {
+ 'menu-item': { width: '20px', height: '20px' },
+ default: { width: '100%', height: '100%' },
+};
+
+const styleImageMap = {
+ default: { width: '100%', height: '100%' },
+};
+
+const ConvoIconURL: React.FC<ConvoIconURLProps> = ({
+ preset,
+ endpointIconURL,
+ assistantAvatar,
+ assistantName,
+ context,
+}) => {
+ const { iconURL = '' } = preset ?? {};
+ let Icon: (
+ props: IconMapProps & {
+ context?: string;
+ iconURL?: string;
+ },
+ ) => React.JSX.Element;
+
+ if (!iconURL?.includes('http')) {
+ Icon = icons[iconURL] ?? icons.unknown;
+ } else {
+ Icon = () => (
+ <div
+ className={classMap[context ?? 'default'] ?? classMap.default}
+ style={styleMap[context ?? 'default'] ?? styleMap.default}
+ >
+ <img
+ src={iconURL}
+ alt={preset?.chatGptLabel ?? preset?.modelLabel ?? ''}
+ style={styleImageMap[context ?? 'default'] ?? styleImageMap.default}
+ className="object-cover"
+ />
+ </div>
+ );
+
+ return <Icon />;
+ }
+
+ return (
+ <div className="shadow-stroke relative flex h-full items-center justify-center rounded-full bg-white text-black">
+ <Icon
+ size={41}
+ context={context}
+ className="h-2/3 w-2/3"
+ iconURL={endpointIconURL}
+ assistantName={assistantName}
+ avatar={assistantAvatar}
+ />
+ </div>
+ );
+};
+
+export default ConvoIconURL;
diff --git a/client/src/components/Endpoints/EndpointOptionsPopover.tsx b/client/src/components/Endpoints/EndpointOptionsPopover.tsx
deleted file mode 100644
index 24f9dbb507..0000000000
--- a/client/src/components/Endpoints/EndpointOptionsPopover.tsx
+++ /dev/null
@@ -1,71 +0,0 @@
-import { Save } from 'lucide-react';
-import type { ReactNode } from 'react';
-// import { EModelEndpoint } from 'librechat-data-provider';
-import { cn, removeFocusOutlines } from '~/utils';
-// import PopoverButtons from './PopoverButtons';
-import { CrossIcon } from '~/components/svg';
-import { Button } from '~/components/ui';
-import { useLocalize } from '~/hooks';
-
-type TEndpointOptionsPopoverProps = {
- children: ReactNode;
- visible: boolean;
- // endpoint: EModelEndpoint;
- saveAsPreset: () => void;
- closePopover: () => void;
- PopoverButtons: ReactNode;
-};
-
-export default function EndpointOptionsPopover({
- children,
- // endpoint,
- visible,
- saveAsPreset,
- closePopover,
- PopoverButtons,
-}: TEndpointOptionsPopoverProps) {
- const localize = useLocalize();
- const cardStyle =
- 'shadow-xl rounded-md min-w-[75px] font-normal bg-white border-black/10 border dark:bg-gray-700 text-black dark:text-white';
-
- return (
- <>
- <div
- className={cn(
- 'endpointOptionsPopover-container absolute bottom-[-10px] z-0 flex w-full flex-col items-center md:px-4',
- visible ? ' show' : '',
- )}
- >
- <div
- className={cn(
- cardStyle,
- 'border-d-0 flex w-full flex-col overflow-hidden rounded-none border-s-0 border-t bg-white px-0 pb-[10px] dark:border-white/10 md:rounded-md md:border lg:w-[736px]',
- )}
- >
- <div className="flex w-full items-center bg-gray-100 px-2 py-2 dark:bg-gray-800/60">
- <Button
- type="button"
- className="h-auto justify-start bg-transparent px-2 py-1 text-xs font-medium font-normal text-black hover:bg-gray-100 hover:text-black focus:ring-0 dark:bg-transparent dark:text-white dark:hover:bg-gray-700 dark:hover:text-white dark:focus:outline-none dark:focus:ring-offset-0"
- onClick={saveAsPreset}
- >
- <Save className="mr-1 w-[14px]" />
- {localize('com_endpoint_save_as_preset')}
- </Button>
- {PopoverButtons}
- <Button
- type="button"
- className={cn(
- 'ml-auto h-auto bg-transparent px-3 py-2 text-xs font-medium font-normal text-black hover:bg-gray-100 hover:text-black dark:bg-transparent dark:text-white dark:hover:bg-gray-700 dark:hover:text-white',
- removeFocusOutlines,
- )}
- onClick={closePopover}
- >
- <CrossIcon />
- </Button>
- </div>
- <div>{children}</div>
- </div>
- </div>
- </>
- );
-}
diff --git a/client/src/components/Endpoints/EndpointSettings.tsx b/client/src/components/Endpoints/EndpointSettings.tsx
index 52e0d9e3d6..49f5c74928 100644
--- a/client/src/components/Endpoints/EndpointSettings.tsx
+++ b/client/src/components/Endpoints/EndpointSettings.tsx
@@ -11,15 +11,14 @@ export default function Settings({
setOption,
isPreset = false,
className = '',
- isMultiChat = false,
-}: TSettingsProps & { isMultiChat?: boolean }) {
+}: TSettingsProps) {
const modelsQuery = useGetModelsQuery();
const currentSettingsView = useRecoilValue(store.currentSettingsView);
if (!conversation?.endpoint || currentSettingsView !== SettingsViews.default) {
return null;
}
- const { settings, multiViewSettings } = getSettings(isMultiChat);
+ const { settings, multiViewSettings } = getSettings();
const { endpoint: _endpoint, endpointType } = conversation;
const models = modelsQuery?.data?.[_endpoint] ?? [];
const endpoint = endpointType ?? _endpoint;
diff --git a/client/src/components/Endpoints/Icon.tsx b/client/src/components/Endpoints/Icon.tsx
index 9a0801966a..eac5d60cea 100644
--- a/client/src/components/Endpoints/Icon.tsx
+++ b/client/src/components/Endpoints/Icon.tsx
@@ -21,14 +21,15 @@ import { cn } from '~/utils';
const Icon: React.FC<IconProps> = (props) => {
const { user } = useAuthContext();
const {
- size = 30,
- isCreatedByUser,
+ error,
button,
- model = '',
+ iconURL,
endpoint,
- error,
jailbreak,
+ size = 30,
+ model = '',
assistantName,
+ isCreatedByUser,
} = props;
const avatarSrc = useAvatar(user);
@@ -167,9 +168,13 @@ const Icon: React.FC<IconProps> = (props) => {
},
};
- const { icon, bg, name } =
+ let { icon, bg, name } =
endpoint && endpointIcons[endpoint] ? endpointIcons[endpoint] : endpointIcons.default;
+ if (iconURL && endpointIcons[iconURL]) {
+ ({ icon, bg, name } = endpointIcons[iconURL]);
+ }
+
if (endpoint === EModelEndpoint.assistants) {
return icon;
}
diff --git a/client/src/components/Endpoints/MinimalIcon.tsx b/client/src/components/Endpoints/MinimalIcon.tsx
index 4e5c505d25..2082ad8ea9 100644
--- a/client/src/components/Endpoints/MinimalIcon.tsx
+++ b/client/src/components/Endpoints/MinimalIcon.tsx
@@ -55,7 +55,10 @@ const MinimalIcon: React.FC<IconProps> = (props) => {
},
};
- const { icon, name } = endpointIcons[endpoint] ?? endpointIcons.default;
+ let { icon, name } = endpointIcons[endpoint] ?? endpointIcons.default;
+ if (props.iconURL && endpointIcons[props.iconURL]) {
+ ({ icon, name } = endpointIcons[props.iconURL]);
+ }
return (
<div
diff --git a/client/src/components/Endpoints/Settings/MultiView/Google.tsx b/client/src/components/Endpoints/Settings/MultiView/Google.tsx
deleted file mode 100644
index 9cdb5cd214..0000000000
--- a/client/src/components/Endpoints/Settings/MultiView/Google.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-import Settings from '../Google';
-import Examples from '../Examples';
-import { useSetOptions } from '~/hooks';
-import { useRecoilValue } from 'recoil';
-import store from '~/store';
-
-export default function GoogleView({ conversation, models, isPreset = false }) {
- const optionSettings = useRecoilValue(store.optionSettings);
- const { setOption, setExample, addExample, removeExample } = useSetOptions(
- isPreset ? conversation : null,
- );
- if (!conversation) {
- return null;
- }
-
- const { examples } = conversation;
- const { showExamples, isCodeChat } = optionSettings;
- return showExamples && !isCodeChat ? (
- <Examples
- examples={examples ?? []}
- setExample={setExample}
- addExample={addExample}
- removeExample={removeExample}
- />
- ) : (
- <Settings conversation={conversation} setOption={setOption} models={models} />
- );
-}
diff --git a/client/src/components/Endpoints/Settings/MultiView/PluginSettings.tsx b/client/src/components/Endpoints/Settings/MultiView/PluginSettings.tsx
index 90b808bf1a..24f1ade440 100644
--- a/client/src/components/Endpoints/Settings/MultiView/PluginSettings.tsx
+++ b/client/src/components/Endpoints/Settings/MultiView/PluginSettings.tsx
@@ -5,7 +5,9 @@ import { useChatContext } from '~/Providers';
export default function PluginsView({ conversation, models, isPreset = false }) {
const { showAgentSettings } = useChatContext();
- const { setOption, setAgentOption } = useSetIndexOptions(isPreset ? conversation : null);
+ const { setOption, setTools, setAgentOption, checkPluginSelection } = useSetIndexOptions(
+ isPreset ? conversation : null,
+ );
if (!conversation) {
return null;
}
@@ -13,6 +15,12 @@ export default function PluginsView({ conversation, models, isPreset = false })
return showAgentSettings ? (
<AgentSettings conversation={conversation} setOption={setAgentOption} models={models} />
) : (
- <Settings conversation={conversation} setOption={setOption} models={models} />
+ <Settings
+ conversation={conversation}
+ setOption={setOption}
+ setTools={setTools}
+ checkPluginSelection={checkPluginSelection}
+ models={models}
+ />
);
}
diff --git a/client/src/components/Endpoints/Settings/MultiView/Plugins.tsx b/client/src/components/Endpoints/Settings/MultiView/Plugins.tsx
deleted file mode 100644
index 7d88ce7e57..0000000000
--- a/client/src/components/Endpoints/Settings/MultiView/Plugins.tsx
+++ /dev/null
@@ -1,19 +0,0 @@
-import Settings from '../Plugins';
-import AgentSettings from '../AgentSettings';
-import { useSetOptions } from '~/hooks';
-import { useRecoilValue } from 'recoil';
-import store from '~/store';
-
-export default function PluginsView({ conversation, models, isPreset = false }) {
- const showAgentSettings = useRecoilValue(store.showAgentSettings);
- const { setOption, setAgentOption } = useSetOptions(isPreset ? conversation : null);
- if (!conversation) {
- return null;
- }
-
- return showAgentSettings ? (
- <AgentSettings conversation={conversation} setOption={setAgentOption} models={models} />
- ) : (
- <Settings conversation={conversation} setOption={setOption} models={models} />
- );
-}
diff --git a/client/src/components/Endpoints/Settings/MultiView/index.ts b/client/src/components/Endpoints/Settings/MultiView/index.ts
index 3de12f02f3..f144aacc28 100644
--- a/client/src/components/Endpoints/Settings/MultiView/index.ts
+++ b/client/src/components/Endpoints/Settings/MultiView/index.ts
@@ -1,4 +1,2 @@
-export { default as Google } from './Google';
-export { default as Plugins } from './Plugins';
export { default as GoogleSettings } from './GoogleSettings';
export { default as PluginSettings } from './PluginSettings';
diff --git a/client/src/components/Endpoints/Settings/OpenAI.tsx b/client/src/components/Endpoints/Settings/OpenAI.tsx
index 5295470fd3..ce04a7f417 100644
--- a/client/src/components/Endpoints/Settings/OpenAI.tsx
+++ b/client/src/components/Endpoints/Settings/OpenAI.tsx
@@ -32,6 +32,7 @@ export default function Settings({ conversation, setOption, models, readonly }:
endpoint,
endpointType,
model,
+ modelLabel,
chatGptLabel,
promptPrefix,
temperature,
@@ -41,32 +42,33 @@ export default function Settings({ conversation, setOption, models, readonly }:
resendFiles,
imageDetail,
} = conversation ?? {};
- const [setChatGptLabel, chatGptLabelValue] = useDebouncedInput({
+
+ const [setChatGptLabel, chatGptLabelValue] = useDebouncedInput<string | null | undefined>({
setOption,
optionKey: 'chatGptLabel',
- initialValue: chatGptLabel,
+ initialValue: modelLabel ?? chatGptLabel,
});
- const [setPromptPrefix, promptPrefixValue] = useDebouncedInput({
+ const [setPromptPrefix, promptPrefixValue] = useDebouncedInput<string | null | undefined>({
setOption,
optionKey: 'promptPrefix',
initialValue: promptPrefix,
});
- const [setTemperature, temperatureValue] = useDebouncedInput({
+ const [setTemperature, temperatureValue] = useDebouncedInput<number | null | undefined>({
setOption,
optionKey: 'temperature',
initialValue: temperature,
});
- const [setTopP, topPValue] = useDebouncedInput({
+ const [setTopP, topPValue] = useDebouncedInput<number | null | undefined>({
setOption,
optionKey: 'top_p',
initialValue: topP,
});
- const [setFreqP, freqPValue] = useDebouncedInput({
+ const [setFreqP, freqPValue] = useDebouncedInput<number | null | undefined>({
setOption,
optionKey: 'frequency_penalty',
initialValue: freqP,
});
- const [setPresP, presPValue] = useDebouncedInput({
+ const [setPresP, presPValue] = useDebouncedInput<number | null | undefined>({
setOption,
optionKey: 'presence_penalty',
initialValue: presP,
diff --git a/client/src/components/Endpoints/Settings/Plugins.tsx b/client/src/components/Endpoints/Settings/Plugins.tsx
index 7f1b885371..64cd114650 100644
--- a/client/src/components/Endpoints/Settings/Plugins.tsx
+++ b/client/src/components/Endpoints/Settings/Plugins.tsx
@@ -1,44 +1,105 @@
+import { useMemo } from 'react';
+import { useRecoilValue } from 'recoil';
import TextareaAutosize from 'react-textarea-autosize';
+import { useAvailablePluginsQuery } from 'librechat-data-provider/react-query';
+import type { TPlugin } from 'librechat-data-provider';
+import type { TModelSelectProps } from '~/common';
import {
- SelectDropDown,
Input,
Label,
Slider,
- InputNumber,
HoverCard,
+ InputNumber,
+ SelectDropDown,
HoverCardTrigger,
-} from '~/components';
+ MultiSelectDropDown,
+} from '~/components/ui';
+import { cn, defaultTextProps, optionText, removeFocusOutlines } from '~/utils';
+import { useLocalize, useDebouncedInput } from '~/hooks';
+import { processPlugins, selectPlugins } from '~/utils';
import OptionHover from './OptionHover';
-import type { TModelSelectProps } from '~/common';
import { ESide } from '~/common';
-import { cn, defaultTextProps, optionText, removeFocusOutlines } from '~/utils/';
-import { useLocalize } from '~/hooks';
+import store from '~/store';
-export default function Settings({ conversation, setOption, models, readonly }: TModelSelectProps) {
+export default function Settings({
+ conversation,
+ setOption,
+ setTools,
+ checkPluginSelection,
+ models,
+ readonly,
+}: TModelSelectProps & {
+ setTools: (newValue: string, remove?: boolean | undefined) => void;
+ checkPluginSelection: (value: string) => boolean;
+}) {
const localize = useLocalize();
- if (!conversation) {
- return null;
- }
+ const availableTools = useRecoilValue(store.availableTools);
+ const { data: allPlugins } = useAvailablePluginsQuery({
+ select: selectPlugins,
+ });
+
+ const conversationTools: TPlugin[] = useMemo(() => {
+ if (!conversation?.tools) {
+ return [];
+ }
+ return processPlugins(conversation.tools, allPlugins?.map);
+ }, [conversation, allPlugins]);
+
+ const availablePlugins = useMemo(() => {
+ if (!availableTools) {
+ return [];
+ }
+
+ return Object.values(availableTools);
+ }, [availableTools]);
+
const {
model,
+ modelLabel,
chatGptLabel,
promptPrefix,
temperature,
top_p: topP,
frequency_penalty: freqP,
presence_penalty: presP,
- tools,
- } = conversation;
+ } = conversation ?? {};
+
+ const [setChatGptLabel, chatGptLabelValue] = useDebouncedInput<string | null | undefined>({
+ setOption,
+ optionKey: 'chatGptLabel',
+ initialValue: modelLabel ?? chatGptLabel,
+ });
+ const [setPromptPrefix, promptPrefixValue] = useDebouncedInput<string | null | undefined>({
+ setOption,
+ optionKey: 'promptPrefix',
+ initialValue: promptPrefix,
+ });
+ const [setTemperature, temperatureValue] = useDebouncedInput<number | null | undefined>({
+ setOption,
+ optionKey: 'temperature',
+ initialValue: temperature,
+ });
+ const [setTopP, topPValue] = useDebouncedInput<number | null | undefined>({
+ setOption,
+ optionKey: 'top_p',
+ initialValue: topP,
+ });
+ const [setFreqP, freqPValue] = useDebouncedInput<number | null | undefined>({
+ setOption,
+ optionKey: 'frequency_penalty',
+ initialValue: freqP,
+ });
+ const [setPresP, presPValue] = useDebouncedInput<number | null | undefined>({
+ setOption,
+ optionKey: 'presence_penalty',
+ initialValue: presP,
+ });
const setModel = setOption('model');
- const setChatGptLabel = setOption('chatGptLabel');
- const setPromptPrefix = setOption('promptPrefix');
- const setTemperature = setOption('temperature');
- const setTopP = setOption('top_p');
- const setFreqP = setOption('frequency_penalty');
- const setPresP = setOption('presence_penalty');
- const toolsSelected = tools && tools.length > 0;
+ if (!conversation) {
+ return null;
+ }
return (
<div className="grid grid-cols-5 gap-6">
@@ -58,21 +119,14 @@ export default function Settings({ conversation, setOption, models, readonly }:
<div className="grid w-full items-center gap-2">
<Label htmlFor="chatGptLabel" className="text-left text-sm font-medium">
{localize('com_endpoint_custom_name')}{' '}
- <small className="opacity-40">
- ({localize('com_endpoint_default_empty')} |{' '}
- {localize('com_endpoint_disabled_with_tools')})
- </small>
+ <small className="opacity-40">{localize('com_endpoint_default_empty')}</small>
</Label>
<Input
id="chatGptLabel"
- disabled={readonly || toolsSelected}
- value={chatGptLabel || ''}
+ disabled={readonly}
+ value={chatGptLabelValue || ''}
onChange={(e) => setChatGptLabel(e.target.value ?? null)}
- placeholder={
- toolsSelected
- ? localize('com_endpoint_disabled_with_tools_placeholder')
- : localize('com_endpoint_openai_custom_name_placeholder')
- }
+ placeholder={localize('com_endpoint_openai_custom_name_placeholder')}
className={cn(
defaultTextProps,
'flex h-10 max-h-10 w-full resize-none px-3 py-2',
@@ -83,21 +137,16 @@ export default function Settings({ conversation, setOption, models, readonly }:
<div className="grid w-full items-center gap-2">
<Label htmlFor="promptPrefix" className="text-left text-sm font-medium">
{localize('com_endpoint_prompt_prefix')}{' '}
- <small className="opacity-40">
- ({localize('com_endpoint_default_empty')} |{' '}
- {localize('com_endpoint_disabled_with_tools')})
- </small>
+ <small className="opacity-40">{localize('com_endpoint_default_empty')}</small>
</Label>
<TextareaAutosize
id="promptPrefix"
- disabled={readonly || toolsSelected}
- value={promptPrefix || ''}
+ disabled={readonly}
+ value={promptPrefixValue || ''}
onChange={(e) => setPromptPrefix(e.target.value ?? null)}
- placeholder={
- toolsSelected
- ? localize('com_endpoint_disabled_with_tools_placeholder')
- : localize('com_endpoint_plug_set_custom_instructions_for_gpt_placeholder')
- }
+ placeholder={localize(
+ 'com_endpoint_plug_set_custom_instructions_for_gpt_placeholder',
+ )}
className={cn(
defaultTextProps,
'flex max-h-[138px] min-h-[100px] w-full resize-none px-3 py-2 ',
@@ -107,6 +156,20 @@ export default function Settings({ conversation, setOption, models, readonly }:
</>
</div>
<div className="col-span-5 flex flex-col items-center justify-start gap-6 px-3 sm:col-span-2">
+ <MultiSelectDropDown
+ showAbove={false}
+ showLabel={false}
+ setSelected={setTools}
+ value={conversationTools}
+ optionValueKey="pluginKey"
+ availableValues={availablePlugins}
+ isSelected={checkPluginSelection}
+ searchPlaceholder={localize('com_ui_select_search_plugin')}
+ className={cn(defaultTextProps, 'flex w-full resize-none', removeFocusOutlines)}
+ optionsClassName="w-full max-h-[275px] dark:bg-gray-700 z-10 border dark:border-gray-600"
+ containerClassName="flex w-full resize-none border border-transparent"
+ labelClassName="dark:text-white"
+ />
<HoverCard openDelay={300}>
<HoverCardTrigger className="grid w-full items-center gap-2">
<div className="flex justify-between">
@@ -119,7 +182,7 @@ export default function Settings({ conversation, setOption, models, readonly }:
<InputNumber
id="temp-int"
disabled={readonly}
- value={temperature}
+ value={temperatureValue}
onChange={(value) => setTemperature(Number(value))}
max={2}
min={0}
@@ -136,7 +199,7 @@ export default function Settings({ conversation, setOption, models, readonly }:
</div>
<Slider
disabled={readonly}
- value={[temperature ?? 0.8]}
+ value={[temperatureValue ?? 0.8]}
onValueChange={(value) => setTemperature(value[0])}
doubleClickHandler={() => setTemperature(0.8)}
max={2}
@@ -159,7 +222,7 @@ export default function Settings({ conversation, setOption, models, readonly }:
<InputNumber
id="top-p-int"
disabled={readonly}
- value={topP}
+ value={topPValue}
onChange={(value) => setTopP(Number(value))}
max={1}
min={0}
@@ -176,7 +239,7 @@ export default function Settings({ conversation, setOption, models, readonly }:
</div>
<Slider
disabled={readonly}
- value={[topP ?? 1]}
+ value={[topPValue ?? 1]}
onValueChange={(value) => setTopP(value[0])}
doubleClickHandler={() => setTopP(1)}
max={1}
@@ -200,7 +263,7 @@ export default function Settings({ conversation, setOption, models, readonly }:
<InputNumber
id="freq-penalty-int"
disabled={readonly}
- value={freqP}
+ value={freqPValue}
onChange={(value) => setFreqP(Number(value))}
max={2}
min={-2}
@@ -217,7 +280,7 @@ export default function Settings({ conversation, setOption, models, readonly }:
</div>
<Slider
disabled={readonly}
- value={[freqP ?? 0]}
+ value={[freqPValue ?? 0]}
onValueChange={(value) => setFreqP(value[0])}
doubleClickHandler={() => setFreqP(0)}
max={2}
@@ -241,7 +304,7 @@ export default function Settings({ conversation, setOption, models, readonly }:
<InputNumber
id="pres-penalty-int"
disabled={readonly}
- value={presP}
+ value={presPValue}
onChange={(value) => setPresP(Number(value))}
max={2}
min={-2}
@@ -258,7 +321,7 @@ export default function Settings({ conversation, setOption, models, readonly }:
</div>
<Slider
disabled={readonly}
- value={[presP ?? 0]}
+ value={[presPValue ?? 0]}
onValueChange={(value) => setPresP(value[0])}
doubleClickHandler={() => setPresP(0)}
max={2}
diff --git a/client/src/components/Endpoints/Settings/settings.ts b/client/src/components/Endpoints/Settings/settings.ts
index 4538973043..1a6cf43fbc 100644
--- a/client/src/components/Endpoints/Settings/settings.ts
+++ b/client/src/components/Endpoints/Settings/settings.ts
@@ -1,7 +1,7 @@
import { EModelEndpoint } from 'librechat-data-provider';
import type { FC } from 'react';
-import type { TModelSelectProps, TBaseSettingsProps, TModels } from '~/common';
-import { Google, Plugins, GoogleSettings, PluginSettings } from './MultiView';
+import type { TModelSelectProps } from '~/common';
+import { GoogleSettings, PluginSettings } from './MultiView';
import AssistantsSettings from './Assistants';
import AnthropicSettings from './Anthropic';
import BingAISettings from './BingAI';
@@ -16,19 +16,7 @@ const settings: { [key: string]: FC<TModelSelectProps> } = {
[EModelEndpoint.anthropic]: AnthropicSettings,
};
-const multiViewSettings: { [key: string]: FC<TBaseSettingsProps & TModels> } = {
- [EModelEndpoint.google]: Google,
- [EModelEndpoint.gptPlugins]: Plugins,
-};
-
-export const getSettings = (isMultiChat = false) => {
- if (!isMultiChat) {
- return {
- settings,
- multiViewSettings,
- };
- }
-
+export const getSettings = () => {
return {
settings,
multiViewSettings: {
diff --git a/client/src/components/Endpoints/index.ts b/client/src/components/Endpoints/index.ts
index 02f21d167b..5236174bcc 100644
--- a/client/src/components/Endpoints/index.ts
+++ b/client/src/components/Endpoints/index.ts
@@ -1,6 +1,6 @@
export { default as Icon } from './Icon';
export { default as MinimalIcon } from './MinimalIcon';
+export { default as ConvoIconURL } from './ConvoIconURL';
export { default as EndpointSettings } from './EndpointSettings';
export { default as SaveAsPresetDialog } from './SaveAsPresetDialog';
export { default as AlternativeSettings } from './AlternativeSettings';
-export { default as EndpointOptionsPopover } from './EndpointOptionsPopover';
diff --git a/client/src/components/Input/Generations/GenerationButtons.tsx b/client/src/components/Input/Generations/GenerationButtons.tsx
deleted file mode 100644
index ad9ef15c4e..0000000000
--- a/client/src/components/Input/Generations/GenerationButtons.tsx
+++ /dev/null
@@ -1,83 +0,0 @@
-import { useEffect, useState } from 'react';
-import type { TMessage } from 'librechat-data-provider';
-import { useMessageHandler, useMediaQuery, useGenerations } from '~/hooks';
-import { cn } from '~/utils';
-import Regenerate from './Regenerate';
-import Continue from './Continue';
-import Stop from './Stop';
-
-type GenerationButtonsProps = {
- endpoint: string;
- showPopover: boolean;
- opacityClass: string;
-};
-
-export default function GenerationButtons({
- endpoint,
- showPopover,
- opacityClass,
-}: GenerationButtonsProps) {
- const {
- messages,
- isSubmitting,
- latestMessage,
- handleContinue,
- handleRegenerate,
- handleStopGenerating,
- } = useMessageHandler();
- const isSmallScreen = useMediaQuery('(max-width: 768px)');
- const { continueSupported, regenerateEnabled } = useGenerations({
- endpoint,
- message: latestMessage as TMessage,
- isSubmitting,
- });
-
- const [userStopped, setUserStopped] = useState(false);
-
- const handleStop = (e: React.MouseEvent<HTMLButtonElement>) => {
- setUserStopped(true);
- handleStopGenerating(e);
- };
-
- useEffect(() => {
- let timer: NodeJS.Timeout;
-
- if (userStopped) {
- timer = setTimeout(() => {
- setUserStopped(false);
- }, 200);
- }
-
- return () => {
- clearTimeout(timer);
- };
- }, [userStopped]);
-
- if (isSmallScreen) {
- return null;
- }
-
- let button: React.ReactNode = null;
-
- if (isSubmitting) {
- button = <Stop onClick={handleStop} />;
- } else if (userStopped || continueSupported) {
- button = <Continue onClick={handleContinue} />;
- } else if (messages && messages.length > 0 && regenerateEnabled) {
- button = <Regenerate onClick={handleRegenerate} />;
- }
-
- return (
- <div className="absolute bottom-4 right-0 z-[62]">
- <div className="grow" />
- <div className="flex items-center md:items-end">
- <div
- className={cn('option-buttons', showPopover ? '' : opacityClass)}
- data-projection-id="173"
- >
- {button}
- </div>
- </div>
- </div>
- );
-}
diff --git a/client/src/components/Input/Generations/index.ts b/client/src/components/Input/Generations/index.ts
deleted file mode 100644
index bbf5aeb41b..0000000000
--- a/client/src/components/Input/Generations/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as GenerationButtons } from './GenerationButtons';
diff --git a/client/src/components/Input/ModelSelect/ModelSelect.tsx b/client/src/components/Input/ModelSelect/ModelSelect.tsx
index 32397ab3bf..c4081db6ac 100644
--- a/client/src/components/Input/ModelSelect/ModelSelect.tsx
+++ b/client/src/components/Input/ModelSelect/ModelSelect.tsx
@@ -1,7 +1,7 @@
+import { useGetModelsQuery } from 'librechat-data-provider/react-query';
import type { TConversation } from 'librechat-data-provider';
import type { TSetOption } from '~/common';
-import { options, multiChatOptions } from './options';
-import { useGetModelsQuery } from 'librechat-data-provider/react-query';
+import { multiChatOptions } from './options';
type TGoogleProps = {
showExamples: boolean;
@@ -12,14 +12,14 @@ type TSelectProps = {
conversation: TConversation | null;
setOption: TSetOption;
extraProps?: TGoogleProps;
- isMultiChat?: boolean;
showAbove?: boolean;
+ popover?: boolean;
};
export default function ModelSelect({
conversation,
setOption,
- isMultiChat = false,
+ popover = false,
showAbove = true,
}: TSelectProps) {
const modelsQuery = useGetModelsQuery();
@@ -32,7 +32,7 @@ export default function ModelSelect({
const models = modelsQuery?.data?.[_endpoint] ?? [];
const endpoint = endpointType ?? _endpoint;
- const OptionComponent = isMultiChat ? multiChatOptions[endpoint] : options[endpoint];
+ const OptionComponent = multiChatOptions[endpoint];
if (!OptionComponent) {
return null;
@@ -44,7 +44,7 @@ export default function ModelSelect({
setOption={setOption}
models={models}
showAbove={showAbove}
- popover={isMultiChat}
+ popover={popover}
/>
);
}
diff --git a/client/src/components/Input/ModelSelect/Plugins.tsx b/client/src/components/Input/ModelSelect/Plugins.tsx
deleted file mode 100644
index d352da8424..0000000000
--- a/client/src/components/Input/ModelSelect/Plugins.tsx
+++ /dev/null
@@ -1,118 +0,0 @@
-import { useRecoilState } from 'recoil';
-import { useState, useEffect } from 'react';
-import { ChevronDownIcon } from 'lucide-react';
-import { useAvailablePluginsQuery } from 'librechat-data-provider/react-query';
-import type { TPlugin } from 'librechat-data-provider';
-import type { TModelSelectProps } from '~/common';
-import { SelectDropDown, MultiSelectDropDown, SelectDropDownPop, Button } from '~/components/ui';
-import { useSetOptions, useAuthContext, useMediaQuery, useLocalize } from '~/hooks';
-import { cn, cardStyle } from '~/utils/';
-import store from '~/store';
-
-const pluginStore: TPlugin = {
- name: 'Plugin store',
- pluginKey: 'pluginStore',
- isButton: true,
- description: '',
- icon: '',
- authConfig: [],
- authenticated: false,
-};
-
-export default function Plugins({
- conversation,
- setOption,
- models,
- showAbove,
- popover = false,
-}: TModelSelectProps) {
- const localize = useLocalize();
- const { data: allPlugins } = useAvailablePluginsQuery();
- const [visible, setVisibility] = useState<boolean>(true);
- const [availableTools, setAvailableTools] = useRecoilState(store.availableTools);
- const { checkPluginSelection, setTools } = useSetOptions();
- const { user } = useAuthContext();
- const isSmallScreen = useMediaQuery('(max-width: 640px)');
- const Menu = popover ? SelectDropDownPop : SelectDropDown;
-
- useEffect(() => {
- if (isSmallScreen) {
- setVisibility(false);
- }
- }, [isSmallScreen]);
-
- useEffect(() => {
- if (!user) {
- return;
- }
-
- if (!allPlugins) {
- return;
- }
-
- if (!user.plugins || user.plugins.length === 0) {
- setAvailableTools([pluginStore]);
- return;
- }
-
- const tools = [...user.plugins]
- .map((el) => allPlugins.find((plugin: TPlugin) => plugin.pluginKey === el))
- .filter((el): el is TPlugin => el !== undefined);
-
- /* Filter Last Selected Tools */
- const localStorageItem = localStorage.getItem('lastSelectedTools');
- if (!localStorageItem) {
- return setAvailableTools([...tools, pluginStore]);
- }
- const lastSelectedTools = JSON.parse(localStorageItem);
- const filteredTools = lastSelectedTools.filter((tool: TPlugin) =>
- tools.some((existingTool) => existingTool.pluginKey === tool.pluginKey),
- );
- localStorage.setItem('lastSelectedTools', JSON.stringify(filteredTools));
-
- setAvailableTools([...tools, pluginStore]);
- // setAvailableTools is a recoil state setter, so it's safe to use it in useEffect
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [allPlugins, user]);
-
- if (!conversation) {
- return null;
- }
-
- return (
- <>
- <Button
- type="button"
- className={cn(
- cardStyle,
- 'z-40 flex h-[40px] min-w-4 flex-none items-center justify-center px-3 hover:bg-white focus:ring-0 focus:ring-offset-0 dark:hover:bg-gray-700',
- )}
- onClick={() => setVisibility((prev) => !prev)}
- >
- <ChevronDownIcon
- className={cn(
- !visible ? 'rotate-180 transform' : '',
- 'w-4 text-gray-600 dark:text-white',
- )}
- />
- </Button>
- <Menu
- value={conversation.model ?? ''}
- setValue={setOption('model')}
- availableValues={models}
- showAbove={showAbove}
- className={cn(cardStyle, 'z-40 flex w-64 min-w-60 sm:w-48', visible ? '' : 'hidden')}
- />
- <MultiSelectDropDown
- value={conversation.tools || []}
- isSelected={checkPluginSelection}
- setSelected={setTools}
- availableValues={availableTools}
- optionValueKey="pluginKey"
- showAbove={showAbove}
- className={cn(cardStyle, 'z-50 w-64 min-w-60 sm:w-48', visible ? '' : 'hidden')}
- searchPlaceholder={localize('com_ui_select_search_plugin')}
- />
- </>
- );
-}
diff --git a/client/src/components/Input/ModelSelect/PluginsByIndex.tsx b/client/src/components/Input/ModelSelect/PluginsByIndex.tsx
index fe88847345..8546d82438 100644
--- a/client/src/components/Input/ModelSelect/PluginsByIndex.tsx
+++ b/client/src/components/Input/ModelSelect/PluginsByIndex.tsx
@@ -1,30 +1,20 @@
-import { useRecoilState } from 'recoil';
-import { useState, useEffect } from 'react';
+import { useRecoilValue } from 'recoil';
import { ChevronDownIcon } from 'lucide-react';
+import { useState, useEffect, useMemo } from 'react';
import { useAvailablePluginsQuery } from 'librechat-data-provider/react-query';
import type { TPlugin } from 'librechat-data-provider';
import type { TModelSelectProps } from '~/common';
import {
+ Button,
+ MultiSelectPop,
SelectDropDown,
SelectDropDownPop,
MultiSelectDropDown,
- MultiSelectPop,
- Button,
} from '~/components/ui';
import { useSetIndexOptions, useAuthContext, useMediaQuery, useLocalize } from '~/hooks';
-import { cn, cardStyle } from '~/utils/';
+import { cn, cardStyle, selectPlugins, processPlugins } from '~/utils';
import store from '~/store';
-const pluginStore: TPlugin = {
- name: 'Plugin store',
- pluginKey: 'pluginStore',
- isButton: true,
- description: '',
- icon: '',
- authConfig: [],
- authenticated: false,
-};
-
export default function PluginsByIndex({
conversation,
setOption,
@@ -33,12 +23,16 @@ export default function PluginsByIndex({
popover = false,
}: TModelSelectProps) {
const localize = useLocalize();
- const { data: allPlugins } = useAvailablePluginsQuery();
- const [visible, setVisibility] = useState<boolean>(true);
- const [availableTools, setAvailableTools] = useRecoilState(store.availableTools);
- const { checkPluginSelection, setTools } = useSetIndexOptions();
const { user } = useAuthContext();
+ const [visible, setVisibility] = useState<boolean>(true);
const isSmallScreen = useMediaQuery('(max-width: 640px)');
+ const availableTools = useRecoilValue(store.availableTools);
+ const { checkPluginSelection, setTools } = useSetIndexOptions();
+
+ const { data: allPlugins } = useAvailablePluginsQuery({
+ enabled: !!user?.plugins,
+ select: selectPlugins,
+ });
useEffect(() => {
if (isSmallScreen) {
@@ -46,39 +40,20 @@ export default function PluginsByIndex({
}
}, [isSmallScreen]);
- useEffect(() => {
- if (!user) {
- return;
- }
-
- if (!allPlugins) {
- return;
- }
-
- if (!user.plugins || user.plugins.length === 0) {
- setAvailableTools([pluginStore]);
- return;
+ const conversationTools: TPlugin[] = useMemo(() => {
+ if (!conversation?.tools) {
+ return [];
}
+ return processPlugins(conversation.tools, allPlugins?.map);
+ }, [conversation, allPlugins]);
- const tools = [...user.plugins]
- .map((el) => allPlugins.find((plugin: TPlugin) => plugin.pluginKey === el))
- .filter((el): el is TPlugin => el !== undefined);
-
- /* Filter Last Selected Tools */
- const localStorageItem = localStorage.getItem('lastSelectedTools');
- if (!localStorageItem) {
- return setAvailableTools([...tools, pluginStore]);
+ const availablePlugins = useMemo(() => {
+ if (!availableTools) {
+ return [];
}
- const lastSelectedTools = JSON.parse(localStorageItem);
- const filteredTools = lastSelectedTools.filter((tool: TPlugin) =>
- tools.some((existingTool) => existingTool.pluginKey === tool.pluginKey),
- );
- localStorage.setItem('lastSelectedTools', JSON.stringify(filteredTools));
- setAvailableTools([...tools, pluginStore]);
- // setAvailableTools is a recoil state setter, so it's safe to use it in useEffect
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [allPlugins, user]);
+ return Object.values(availableTools);
+ }, [availableTools]);
if (!conversation) {
return null;
@@ -112,15 +87,19 @@ export default function PluginsByIndex({
availableValues={models}
showAbove={showAbove}
showLabel={false}
+ className={cn(
+ cardStyle,
+ 'z-50 flex h-[40px] w-48 min-w-48 flex-none items-center justify-center px-4 hover:cursor-pointer',
+ )}
/>
<PluginsMenu
- value={conversation.tools || []}
- isSelected={checkPluginSelection}
- setSelected={setTools}
- availableValues={availableTools}
- optionValueKey="pluginKey"
showAbove={false}
showLabel={false}
+ setSelected={setTools}
+ value={conversationTools}
+ optionValueKey="pluginKey"
+ availableValues={availablePlugins}
+ isSelected={checkPluginSelection}
searchPlaceholder={localize('com_ui_select_search_plugin')}
/>
</>
diff --git a/client/src/components/Input/ModelSelect/options.ts b/client/src/components/Input/ModelSelect/options.ts
index ce231e8637..0159f0782f 100644
--- a/client/src/components/Input/ModelSelect/options.ts
+++ b/client/src/components/Input/ModelSelect/options.ts
@@ -5,7 +5,6 @@ import type { FC } from 'react';
import OpenAI from './OpenAI';
import BingAI from './BingAI';
import Google from './Google';
-import Plugins from './Plugins';
import ChatGPT from './ChatGPT';
import Anthropic from './Anthropic';
import PluginsByIndex from './PluginsByIndex';
@@ -16,7 +15,6 @@ export const options: { [key: string]: FC<TModelSelectProps> } = {
[EModelEndpoint.azureOpenAI]: OpenAI,
[EModelEndpoint.bingAI]: BingAI,
[EModelEndpoint.google]: Google,
- [EModelEndpoint.gptPlugins]: Plugins,
[EModelEndpoint.anthropic]: Anthropic,
[EModelEndpoint.chatGPTBrowser]: ChatGPT,
};
diff --git a/client/src/components/Messages/Message.tsx b/client/src/components/Messages/Message.tsx
deleted file mode 100644
index 04bd84826b..0000000000
--- a/client/src/components/Messages/Message.tsx
+++ /dev/null
@@ -1,227 +0,0 @@
-/* eslint-disable react-hooks/exhaustive-deps */
-import { useGetConversationByIdQuery } from 'librechat-data-provider/react-query';
-import { useEffect } from 'react';
-import { useSetRecoilState, useRecoilState, useRecoilValue } from 'recoil';
-import copy from 'copy-to-clipboard';
-import { SubRow, Plugin, MessageContent } from './Content';
-// eslint-disable-next-line import/no-cycle
-import MultiMessage from './MultiMessage';
-import HoverButtons from './HoverButtons';
-import SiblingSwitch from './SiblingSwitch';
-import { Icon } from '~/components/Endpoints';
-import { useMessageHandler, useConversation } from '~/hooks';
-import type { TMessageProps } from '~/common';
-import { cn } from '~/utils';
-import store from '~/store';
-import { useParams } from 'react-router-dom';
-
-export default function Message(props: TMessageProps) {
- const {
- conversation,
- message,
- scrollToBottom,
- currentEditId,
- setCurrentEditId,
- siblingIdx,
- siblingCount,
- setSiblingIdx,
- } = props;
-
- const setLatestMessage = useSetRecoilState(store.latestMessage);
- const [abortScroll, setAbortScroll] = useRecoilState(store.abortScroll);
- const { isSubmitting, ask, regenerate, handleContinue } = useMessageHandler();
- const { switchToConversation } = useConversation();
- const { conversationId } = useParams();
- const isSearching = useRecoilValue(store.isSearching);
-
- const {
- text,
- children,
- messageId = null,
- searchResult,
- isCreatedByUser,
- error,
- unfinished,
- } = message ?? {};
-
- const isLast = !children?.length;
- const edit = messageId === currentEditId;
- const getConversationQuery = useGetConversationByIdQuery(message?.conversationId ?? '', {
- enabled: false,
- });
-
- const autoScroll = useRecoilValue(store.autoScroll);
-
- useEffect(() => {
- if (isSubmitting && scrollToBottom && !abortScroll) {
- scrollToBottom();
- }
- }, [isSubmitting, text, scrollToBottom, abortScroll]);
-
- useEffect(() => {
- if (scrollToBottom && autoScroll && !isSearching && conversationId !== 'new') {
- scrollToBottom();
- }
- }, [autoScroll, conversationId, scrollToBottom, isSearching]);
-
- useEffect(() => {
- if (!message) {
- return;
- } else if (isLast) {
- setLatestMessage({ ...message });
- }
- }, [isLast, message, setLatestMessage]);
-
- if (!message) {
- return null;
- }
-
- const enterEdit = (cancel?: boolean) =>
- setCurrentEditId && setCurrentEditId(cancel ? -1 : messageId);
-
- const handleScroll = () => {
- if (isSubmitting) {
- setAbortScroll(true);
- } else {
- setAbortScroll(false);
- }
- };
-
- const commonClasses =
- 'w-full border-b text-gray-800 group border-black/10 dark:border-gray-800/50 dark:text-gray-200';
- const uniqueClasses = isCreatedByUser
- ? 'bg-white dark:bg-gray-800 dark:text-gray-20'
- : 'bg-gray-50 dark:bg-gray-700 dark:text-gray-100';
-
- const messageProps = {
- className: cn(commonClasses, uniqueClasses),
- titleclass: '',
- };
-
- const icon = Icon({
- ...conversation,
- ...message,
- model: message?.model ?? conversation?.model,
- size: 36,
- });
-
- if (message?.bg && searchResult) {
- messageProps.className = message?.bg?.split('hover')[0];
- messageProps.titleclass = message?.bg?.split(messageProps.className)[1] + ' cursor-pointer';
- }
-
- const regenerateMessage = () => {
- if (!isSubmitting && !isCreatedByUser) {
- regenerate(message);
- }
- };
-
- const copyToClipboard = (setIsCopied: React.Dispatch<React.SetStateAction<boolean>>) => {
- setIsCopied(true);
- copy(text ?? '');
-
- setTimeout(() => {
- setIsCopied(false);
- }, 3000);
- };
-
- const clickSearchResult = async () => {
- if (!searchResult) {
- return;
- }
- if (!message) {
- return;
- }
- const response = await getConversationQuery.refetch({
- queryKey: [message?.conversationId],
- });
-
- console.log('getConversationQuery response.data:', response.data);
-
- if (response.data) {
- switchToConversation(response.data);
- }
- };
-
- return (
- <>
- <div {...messageProps} onWheel={handleScroll} onTouchMove={handleScroll}>
- <div className="relative m-auto flex gap-4 p-4 text-base md:max-w-2xl md:gap-4 md:py-6 lg:max-w-2xl lg:px-0 xl:max-w-3xl">
- <div className="relative flex h-[40px] w-[40px] flex-col items-end text-right text-xs md:text-sm">
- {typeof icon === 'string' && /[^\\x00-\\x7F]+/.test(icon as string) ? (
- <span className=" direction-rtl w-40 overflow-x-scroll">{icon}</span>
- ) : (
- icon
- )}
- <div className="sibling-switch invisible absolute left-0 top-2 -ml-4 flex -translate-x-full items-center justify-center gap-1 text-xs group-hover:visible">
- <SiblingSwitch
- siblingIdx={siblingIdx}
- siblingCount={siblingCount}
- setSiblingIdx={setSiblingIdx}
- />
- </div>
- </div>
- <div className="relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]">
- {searchResult && (
- <SubRow
- classes={messageProps.titleclass + ' rounded'}
- subclasses="switch-result pl-2 pb-2"
- onClick={clickSearchResult}
- >
- <strong>{`${message?.title} | ${message?.sender}`}</strong>
- </SubRow>
- )}
- <div className="flex flex-grow flex-col gap-3">
- {/* Legacy Plugins */}
- {message?.plugin && <Plugin plugin={message?.plugin} />}
- <MessageContent
- ask={ask}
- edit={edit}
- isLast={isLast}
- text={text ?? ''}
- message={message}
- enterEdit={enterEdit}
- error={!!(error && !searchResult)}
- isSubmitting={isSubmitting}
- unfinished={unfinished ?? false}
- isCreatedByUser={isCreatedByUser ?? true}
- siblingIdx={siblingIdx ?? 0}
- setSiblingIdx={
- setSiblingIdx ??
- (() => {
- return;
- })
- }
- />
- </div>
- <HoverButtons
- isEditing={edit}
- isSubmitting={isSubmitting}
- message={message}
- conversation={conversation ?? null}
- enterEdit={enterEdit}
- regenerate={() => regenerateMessage()}
- handleContinue={handleContinue}
- copyToClipboard={copyToClipboard}
- />
- <SubRow subclasses="switch-container">
- <SiblingSwitch
- siblingIdx={siblingIdx}
- siblingCount={siblingCount}
- setSiblingIdx={setSiblingIdx}
- />
- </SubRow>
- </div>
- </div>
- </div>
- <MultiMessage
- messageId={messageId}
- conversation={conversation}
- messagesTree={children ?? []}
- scrollToBottom={scrollToBottom}
- currentEditId={currentEditId}
- setCurrentEditId={setCurrentEditId}
- />
- </>
- );
-}
diff --git a/client/src/components/Messages/MultiMessage.tsx b/client/src/components/Messages/MultiMessage.tsx
deleted file mode 100644
index 08a17c33fd..0000000000
--- a/client/src/components/Messages/MultiMessage.tsx
+++ /dev/null
@@ -1,74 +0,0 @@
-import { useEffect } from 'react';
-import { useRecoilState } from 'recoil';
-import type { TMessageProps } from '~/common';
-// eslint-disable-next-line import/no-cycle
-import Message from './Message';
-import store from '~/store';
-
-export default function MultiMessage({
- messageId,
- conversation,
- messagesTree,
- scrollToBottom,
- currentEditId,
- setCurrentEditId,
- isSearchView,
-}: TMessageProps) {
- const [siblingIdx, setSiblingIdx] = useRecoilState(store.messagesSiblingIdxFamily(messageId));
-
- const setSiblingIdxRev = (value: number) => {
- setSiblingIdx((messagesTree?.length ?? 0) - value - 1);
- };
-
- useEffect(() => {
- // reset siblingIdx when the tree changes, mostly when a new message is submitting.
- setSiblingIdx(0);
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [messagesTree?.length]);
-
- // if (!messageList?.length) return null;
- if (!(messagesTree && messagesTree?.length)) {
- return null;
- }
-
- if (siblingIdx >= messagesTree?.length) {
- setSiblingIdx(0);
- return null;
- }
-
- const message = messagesTree[messagesTree.length - siblingIdx - 1];
- if (isSearchView) {
- return (
- <>
- {messagesTree
- ? messagesTree.map((message) => (
- <Message
- key={message.messageId}
- conversation={conversation}
- message={message}
- scrollToBottom={scrollToBottom}
- currentEditId={currentEditId}
- setCurrentEditId={null}
- siblingIdx={1}
- siblingCount={1}
- setSiblingIdx={null}
- />
- ))
- : null}
- </>
- );
- }
- return (
- <Message
- key={message.messageId}
- conversation={conversation}
- message={message}
- scrollToBottom={scrollToBottom}
- currentEditId={currentEditId}
- setCurrentEditId={setCurrentEditId}
- siblingIdx={messagesTree.length - siblingIdx - 1}
- siblingCount={messagesTree.length}
- setSiblingIdx={setSiblingIdxRev}
- />
- );
-}
diff --git a/client/src/components/Messages/SiblingSwitch.tsx b/client/src/components/Messages/SiblingSwitch.tsx
deleted file mode 100644
index 72c154662a..0000000000
--- a/client/src/components/Messages/SiblingSwitch.tsx
+++ /dev/null
@@ -1,71 +0,0 @@
-import type { TMessageProps } from '~/common';
-
-type TSiblingSwitchProps = Pick<TMessageProps, 'siblingIdx' | 'siblingCount' | 'setSiblingIdx'>;
-
-export default function SiblingSwitch({
- siblingIdx,
- siblingCount,
- setSiblingIdx,
-}: TSiblingSwitchProps) {
- if (siblingIdx === undefined) {
- return null;
- } else if (siblingCount === undefined) {
- return null;
- }
-
- const previous = () => {
- setSiblingIdx && setSiblingIdx(siblingIdx - 1);
- };
-
- const next = () => {
- setSiblingIdx && setSiblingIdx(siblingIdx + 1);
- };
-
- return siblingCount > 1 ? (
- <>
- <button
- className="disabled:text-gray-300 dark:text-white dark:disabled:text-gray-400"
- onClick={previous}
- disabled={siblingIdx == 0}
- >
- <svg
- stroke="currentColor"
- fill="none"
- strokeWidth="1.5"
- viewBox="0 0 24 24"
- strokeLinecap="round"
- strokeLinejoin="round"
- className="h-3 w-3"
- height="1em"
- width="1em"
- xmlns="http://www.w3.org/2000/svg"
- >
- <polyline points="15 18 9 12 15 6" />
- </svg>
- </button>
- <span className="flex-shrink-0 flex-grow">
- {siblingIdx + 1} / {siblingCount}
- </span>
- <button
- className="disabled:text-gray-300 dark:text-white dark:disabled:text-gray-400"
- onClick={next}
- disabled={siblingIdx == siblingCount - 1}
- >
- <svg
- stroke="currentColor"
- fill="none"
- strokeWidth="1.5"
- viewBox="0 0 24 24"
- strokeLinecap="round"
- strokeLinejoin="round"
- className="h-3 w-3"
- height="1em"
- width="1em"
- xmlns="http://www.w3.org/2000/svg"
- >
- <polyline points="9 18 15 12 9 6" />
- </svg>
- </button>
- </>
- ) : null;
-}
diff --git a/client/src/components/Nav/NewChat.tsx b/client/src/components/Nav/NewChat.tsx
index bdb16a4a99..a060235739 100644
--- a/client/src/components/Nav/NewChat.tsx
+++ b/client/src/components/Nav/NewChat.tsx
@@ -1,29 +1,36 @@
import { useNavigate } from 'react-router-dom';
-import { EModelEndpoint } from 'librechat-data-provider';
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from '~/components/ui';
-import { useLocalize, useNewConvo, useLocalStorage } from '~/hooks';
+import { getEndpointField, getIconEndpoint, getIconKey } from '~/utils';
import { icons } from '~/components/Chat/Menus/Endpoints/Icons';
+import ConvoIconURL from '~/components/Endpoints/ConvoIconURL';
+import { useLocalize, useNewConvo } from '~/hooks';
import { NewChatIcon } from '~/components/svg';
-import { getEndpointField } from '~/utils';
+import store from '~/store';
export default function NewChat({
+ index = 0,
toggleNav,
subHeaders,
}: {
+ index?: number;
toggleNav: () => void;
subHeaders?: React.ReactNode;
}) {
- const { newConversation: newConvo } = useNewConvo();
+ /** Note: this component needs an explicit index passed if using more than one */
+ const { newConversation: newConvo } = useNewConvo(index);
const navigate = useNavigate();
const localize = useLocalize();
const { data: endpointsConfig } = useGetEndpointsQuery();
- const [convo] = useLocalStorage('lastConversationSetup', { endpoint: EModelEndpoint.openAI });
- const { endpoint } = convo;
+ const { conversation } = store.useCreateConversationAtom(index);
+ let { endpoint = '' } = conversation ?? {};
+ const iconURL = conversation?.iconURL ?? '';
+ endpoint = getIconEndpoint({ endpointsConfig, iconURL, endpoint });
+
const endpointType = getEndpointField(endpointsConfig, endpoint, 'type');
- const iconURL = getEndpointField(endpointsConfig, endpoint, 'iconURL');
- const iconKey = endpointType ? 'unknown' : endpoint ?? 'unknown';
+ const endpointIconURL = getEndpointField(endpointsConfig, endpoint, 'iconURL');
+ const iconKey = getIconKey({ endpoint, endpointsConfig, endpointType, endpointIconURL });
const Icon = icons[iconKey];
const clickHandler = (event: React.MouseEvent<HTMLAnchorElement>) => {
@@ -47,17 +54,22 @@ export default function NewChat({
className="group flex h-10 items-center gap-2 rounded-lg px-2 font-medium hover:bg-gray-200 dark:hover:bg-gray-700"
>
<div className="h-7 w-7 flex-shrink-0">
- <div className="shadow-stroke relative flex h-full items-center justify-center rounded-full bg-white text-black dark:bg-white">
- {endpoint &&
- Icon &&
- Icon({
- size: 41,
- context: 'nav',
- className: 'h-2/3 w-2/3',
- endpoint: endpoint,
- iconURL: iconURL,
- })}
- </div>
+ {iconURL && iconURL.includes('http') ? (
+ <ConvoIconURL preset={conversation} endpointIconURL={iconURL} context="nav" />
+ ) : (
+ <div className="shadow-stroke relative flex h-full items-center justify-center rounded-full bg-white text-black dark:bg-white">
+ {endpoint &&
+ Icon &&
+ Icon({
+ size: 41,
+ context: 'nav',
+ className: 'h-2/3 w-2/3',
+ endpoint,
+ endpointType,
+ iconURL: endpointIconURL,
+ })}
+ </div>
+ )}
</div>
<div className="text-token-text-primary grow overflow-hidden text-ellipsis whitespace-nowrap text-sm">
{localize('com_ui_new_chat')}
diff --git a/client/src/components/Plugins/Store/PluginStoreDialog.tsx b/client/src/components/Plugins/Store/PluginStoreDialog.tsx
index aa61a4822d..3bc4852163 100644
--- a/client/src/components/Plugins/Store/PluginStoreDialog.tsx
+++ b/client/src/components/Plugins/Store/PluginStoreDialog.tsx
@@ -1,13 +1,16 @@
import { Search, X } from 'lucide-react';
import { Dialog } from '@headlessui/react';
-import { useState, useEffect } from 'react';
-import {
- useAvailablePluginsQuery,
- useUpdateUserPluginsMutation,
-} from 'librechat-data-provider/react-query';
-import type { TError, TPluginAction } from 'librechat-data-provider';
+import { useState, useEffect, useCallback } from 'react';
+import { useAvailablePluginsQuery } from 'librechat-data-provider/react-query';
+import type { TError, TPlugin, TPluginAction } from 'librechat-data-provider';
import type { TPluginStoreDialogProps } from '~/common/types';
-import { useLocalize, usePluginDialogHelpers, useSetIndexOptions, useAuthContext } from '~/hooks';
+import {
+ usePluginDialogHelpers,
+ useSetIndexOptions,
+ usePluginInstall,
+ useAuthContext,
+ useLocalize,
+} from '~/hooks';
import PluginPagination from './PluginPagination';
import PluginStoreItem from './PluginStoreItem';
import PluginAuthForm from './PluginAuthForm';
@@ -16,7 +19,6 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
const localize = useLocalize();
const { user } = useAuthContext();
const { data: availablePlugins } = useAvailablePluginsQuery();
- const updateUserPlugins = useUpdateUserPluginsMutation();
const { setTools } = useSetIndexOptions();
const [userPlugins, setUserPlugins] = useState<string[]>([]);
@@ -44,50 +46,49 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
setSelectedPlugin,
} = usePluginDialogHelpers();
- const handleInstallError = (error: TError) => {
- setError(true);
- if (error.response?.data?.message) {
- setErrorMessage(error.response?.data?.message);
- }
- setTimeout(() => {
- setError(false);
- setErrorMessage('');
- }, 5000);
- };
+ const handleInstallError = useCallback(
+ (error: TError) => {
+ setError(true);
+ if (error.response?.data?.message) {
+ setErrorMessage(error.response?.data?.message);
+ }
+ setTimeout(() => {
+ setError(false);
+ setErrorMessage('');
+ }, 5000);
+ },
+ [setError, setErrorMessage],
+ );
- const handleInstall = (pluginAction: TPluginAction) => {
- updateUserPlugins.mutate(pluginAction, {
- onError: (error: unknown) => {
- handleInstallError(error as TError);
- },
- });
- setShowPluginAuthForm(false);
- };
+ const { installPlugin, uninstallPlugin } = usePluginInstall({
+ onInstallError: handleInstallError,
+ onUninstallError: handleInstallError,
+ onUninstallSuccess: (_data, variables) => {
+ setTools(variables.pluginKey, true);
+ },
+ });
- const onPluginUninstall = (plugin: string) => {
- updateUserPlugins.mutate(
- { pluginKey: plugin, action: 'uninstall', auth: null },
- {
- onError: (error: unknown) => {
- handleInstallError(error as TError);
- },
- onSuccess: () => {
- setTools(plugin, true);
- },
- },
- );
+ const handleInstall = (pluginAction: TPluginAction, plugin?: TPlugin) => {
+ if (!plugin) {
+ return;
+ }
+ installPlugin(pluginAction, plugin);
+ setShowPluginAuthForm(false);
};
const onPluginInstall = (pluginKey: string) => {
- const getAvailablePluginFromKey = availablePlugins?.find((p) => p.pluginKey === pluginKey);
- setSelectedPlugin(getAvailablePluginFromKey);
+ const plugin = availablePlugins?.find((p) => p.pluginKey === pluginKey);
+ if (!plugin) {
+ return;
+ }
+ setSelectedPlugin(plugin);
- const { authConfig, authenticated } = getAvailablePluginFromKey ?? {};
+ const { authConfig, authenticated } = plugin ?? {};
if (authConfig && authConfig.length > 0 && !authenticated) {
setShowPluginAuthForm(true);
} else {
- handleInstall({ pluginKey, action: 'install', auth: null });
+ handleInstall({ pluginKey, action: 'install', auth: null }, plugin);
}
};
@@ -107,10 +108,17 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
setSearchChanged(false);
}
}
-
- // Disabled due to state setters erroneously being flagged as dependencies
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [availablePlugins, itemsPerPage, user, searchValue, filteredPlugins, searchChanged]);
+ }, [
+ availablePlugins,
+ itemsPerPage,
+ user,
+ searchValue,
+ filteredPlugins,
+ searchChanged,
+ setMaxPage,
+ setCurrentPage,
+ setSearchChanged,
+ ]);
return (
<Dialog
@@ -165,7 +173,7 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
<div className="p-4 sm:p-6 sm:pt-4">
<PluginAuthForm
plugin={selectedPlugin}
- onSubmit={(installActionData: TPluginAction) => handleInstall(installActionData)}
+ onSubmit={(action: TPluginAction) => handleInstall(action, selectedPlugin)}
/>
</div>
)}
@@ -197,7 +205,7 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
plugin={plugin}
isInstalled={userPlugins.includes(plugin.pluginKey)}
onInstall={() => onPluginInstall(plugin.pluginKey)}
- onUninstall={() => onPluginUninstall(plugin.pluginKey)}
+ onUninstall={() => uninstallPlugin(plugin.pluginKey)}
/>
))}
</div>
diff --git a/client/src/components/SidePanel/AssistantSwitcher.tsx b/client/src/components/SidePanel/AssistantSwitcher.tsx
index 60bdd15bfb..8b9f5fc776 100644
--- a/client/src/components/SidePanel/AssistantSwitcher.tsx
+++ b/client/src/components/SidePanel/AssistantSwitcher.tsx
@@ -1,6 +1,6 @@
import { useEffect, useMemo } from 'react';
import { Combobox } from '~/components/ui';
-import { EModelEndpoint, defaultOrderQuery } from 'librechat-data-provider';
+import { EModelEndpoint, defaultOrderQuery, LocalStorageKeys } from 'librechat-data-provider';
import type { SwitcherProps } from '~/common';
import { useSetIndexOptions, useSelectAssistant, useLocalize } from '~/hooks';
import { useChatContext, useAssistantsMapContext } from '~/Providers';
@@ -25,7 +25,9 @@ export default function AssistantSwitcher({ isCollapsed }: SwitcherProps) {
useEffect(() => {
if (!selectedAssistant && assistants && assistants.length && assistantMap) {
const assistant_id =
- localStorage.getItem(`assistant_id__${index}`) ?? assistants[0]?.id ?? '';
+ localStorage.getItem(`${LocalStorageKeys.ASST_ID_PREFIX}${index}`) ??
+ assistants[0]?.id ??
+ '';
const assistant = assistantMap?.[assistant_id];
if (!assistant) {
diff --git a/client/src/components/SidePanel/SidePanel.tsx b/client/src/components/SidePanel/SidePanel.tsx
index 1f7f07da99..13ac875975 100644
--- a/client/src/components/SidePanel/SidePanel.tsx
+++ b/client/src/components/SidePanel/SidePanel.tsx
@@ -1,13 +1,17 @@
import throttle from 'lodash/throttle';
+import { EModelEndpoint, getConfigDefaults } from 'librechat-data-provider';
import { useState, useRef, useCallback, useEffect, useMemo, memo } from 'react';
-import { useGetEndpointsQuery, useUserKeyQuery } from 'librechat-data-provider/react-query';
+import {
+ useGetEndpointsQuery,
+ useGetStartupConfig,
+ useUserKeyQuery,
+} from 'librechat-data-provider/react-query';
import type { ImperativePanelHandle } from 'react-resizable-panels';
-import { EModelEndpoint, type TEndpointsConfig } from 'librechat-data-provider';
+import type { TEndpointsConfig } from 'librechat-data-provider';
import { ResizableHandleAlt, ResizablePanel, ResizablePanelGroup } from '~/components/ui/Resizable';
import { TooltipProvider, Tooltip } from '~/components/ui/Tooltip';
import useSideNavLinks from '~/hooks/Nav/useSideNavLinks';
import { useMediaQuery, useLocalStorage } from '~/hooks';
-import { Separator } from '~/components/ui/Separator';
import NavToggle from '~/components/Nav/NavToggle';
import { useChatContext } from '~/Providers';
import Switcher from './Switcher';
@@ -23,6 +27,7 @@ interface SidePanelProps {
}
const defaultMinSize = 20;
+const defaultInterface = getConfigDefaults().interface;
const SidePanel = ({
defaultLayout = [97, 3],
@@ -38,6 +43,12 @@ const SidePanel = ({
const [fullCollapse, setFullCollapse] = useState(fullPanelCollapse);
const [collapsedSize, setCollapsedSize] = useState(navCollapsedSize);
const { data: endpointsConfig = {} as TEndpointsConfig } = useGetEndpointsQuery();
+ const { data: startupConfig } = useGetStartupConfig();
+ const interfaceConfig = useMemo(
+ () => startupConfig?.interface ?? defaultInterface,
+ [startupConfig],
+ );
+
const isSmallScreen = useMediaQuery('(max-width: 767px)');
const { conversation } = useChatContext();
const { endpoint } = conversation ?? {};
@@ -69,7 +80,7 @@ const SidePanel = ({
panelRef.current?.collapse();
}, []);
- const Links = useSideNavLinks({ hidePanel, assistants, keyProvided, endpoint });
+ const Links = useSideNavLinks({ hidePanel, assistants, keyProvided, endpoint, interfaceConfig });
// eslint-disable-next-line react-hooks/exhaustive-deps
const throttledSaveLayout = useCallback(
@@ -181,19 +192,20 @@ const SidePanel = ({
: 'opacity-100',
)}
>
- <div
- className={cn(
- 'sticky left-0 right-0 top-0 z-[100] flex h-[52px] flex-wrap items-center justify-center bg-white dark:bg-gray-850',
- isCollapsed ? 'h-[52px]' : 'px-2',
- )}
- >
- <Switcher
- isCollapsed={isCollapsed}
- endpointKeyProvided={keyProvided}
- endpoint={endpoint}
- />
- <Separator className="bg-gray-100/50 dark:bg-gray-600" />
- </div>
+ {interfaceConfig.modelSelect && (
+ <div
+ className={cn(
+ 'sticky left-0 right-0 top-0 z-[100] flex h-[52px] flex-wrap items-center justify-center bg-white dark:bg-gray-850',
+ isCollapsed ? 'h-[52px]' : 'px-2',
+ )}
+ >
+ <Switcher
+ isCollapsed={isCollapsed}
+ endpointKeyProvided={keyProvided}
+ endpoint={endpoint}
+ />
+ </div>
+ )}
<Nav
resize={panelRef.current?.resize}
isCollapsed={isCollapsed}
diff --git a/client/src/components/SidePanel/Switcher.tsx b/client/src/components/SidePanel/Switcher.tsx
index b954b4d891..4fdaea21b8 100644
--- a/client/src/components/SidePanel/Switcher.tsx
+++ b/client/src/components/SidePanel/Switcher.tsx
@@ -1,14 +1,25 @@
import { EModelEndpoint } from 'librechat-data-provider';
import type { SwitcherProps } from '~/common';
+import { Separator } from '~/components/ui/Separator';
import AssistantSwitcher from './AssistantSwitcher';
import ModelSwitcher from './ModelSwitcher';
export default function Switcher(props: SwitcherProps) {
if (props.endpoint === EModelEndpoint.assistants && props.endpointKeyProvided) {
- return <AssistantSwitcher {...props} />;
+ return (
+ <>
+ <AssistantSwitcher {...props} />
+ <Separator className="bg-gray-100/50 dark:bg-gray-600" />
+ </>
+ );
} else if (props.endpoint === EModelEndpoint.assistants) {
return null;
}
- return <ModelSwitcher {...props} />;
+ return (
+ <>
+ <ModelSwitcher {...props} />
+ <Separator className="bg-gray-100/50 dark:bg-gray-600" />
+ </>
+ );
}
diff --git a/client/src/components/ui/MultiSelectDropDown.tsx b/client/src/components/ui/MultiSelectDropDown.tsx
index 7fb2856525..300d032486 100644
--- a/client/src/components/ui/MultiSelectDropDown.tsx
+++ b/client/src/components/ui/MultiSelectDropDown.tsx
@@ -16,6 +16,8 @@ export type TMultiSelectDropDownProps = {
showAbove?: boolean;
showLabel?: boolean;
containerClassName?: string;
+ optionsClassName?: string;
+ labelClassName?: string;
isSelected: (value: string) => boolean;
className?: string;
searchPlaceholder?: string;
@@ -31,6 +33,8 @@ function MultiSelectDropDown({
showAbove = false,
showLabel = true,
containerClassName,
+ optionsClassName = '',
+ labelClassName = '',
isSelected,
className,
searchPlaceholder,
@@ -72,7 +76,7 @@ function MultiSelectDropDown({
<>
<Listbox.Button
className={cn(
- 'relative flex w-full cursor-default flex-col rounded-md border border-black/10 bg-white py-2 pl-3 pr-10 text-left focus:outline-none focus:ring-0 focus:ring-offset-0 dark:border-white/20 dark:bg-gray-800 sm:text-sm',
+ 'relative flex w-full cursor-default flex-col rounded-md border border-black/10 bg-white py-2 pl-3 pr-10 text-left focus:outline-none focus:ring-0 focus:ring-offset-0 dark:border-gray-600 dark:border-white/20 dark:bg-gray-800 sm:text-sm',
className ?? '',
)}
id={excludeIds[0]}
@@ -82,7 +86,7 @@ function MultiSelectDropDown({
{' '}
{showLabel && (
<Listbox.Label
- className="block text-xs text-gray-700 dark:text-gray-500"
+ className={cn('block text-xs text-gray-700 dark:text-gray-500', labelClassName)}
id={excludeIds[1]}
data-headlessui-state=""
>
@@ -153,6 +157,7 @@ function MultiSelectDropDown({
ref={menuRef}
className={cn(
'absolute z-50 mt-2 max-h-60 w-full overflow-auto rounded bg-white text-base text-xs ring-1 ring-black/10 focus:outline-none dark:bg-gray-800 dark:ring-white/20 dark:last:border-0 md:w-[100%]',
+ optionsClassName,
)}
>
{searchRender}
diff --git a/client/src/components/ui/MultiSelectPop.tsx b/client/src/components/ui/MultiSelectPop.tsx
index c2c928ff3f..3f43772915 100644
--- a/client/src/components/ui/MultiSelectPop.tsx
+++ b/client/src/components/ui/MultiSelectPop.tsx
@@ -1,4 +1,3 @@
-import React, { useMemo, useState } from 'react';
import { Wrench } from 'lucide-react';
import { Root, Trigger, Content, Portal } from '@radix-ui/react-popover';
import type { TPlugin } from 'librechat-data-provider';
@@ -115,7 +114,7 @@ function MultiSelectPop({
side="bottom"
align="center"
className={cn(
- 'mt-2 max-h-60 min-w-full overflow-hidden overflow-y-auto rounded-lg border border-gray-200 bg-white shadow-lg dark:border-gray-700 dark:bg-gray-700 dark:text-white',
+ 'mt-2 max-h-[52vh] min-w-full overflow-hidden overflow-y-auto rounded-lg border border-gray-200 bg-white shadow-lg dark:border-gray-700 dark:bg-gray-700 dark:text-white',
hasSearchRender && 'relative',
)}
>
diff --git a/client/src/data-provider/mutations.ts b/client/src/data-provider/mutations.ts
index bada848247..e207b8958e 100644
--- a/client/src/data-provider/mutations.ts
+++ b/client/src/data-provider/mutations.ts
@@ -1,3 +1,4 @@
+import { LocalStorageKeys } from 'librechat-data-provider';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import type { UseMutationResult } from '@tanstack/react-query';
import type t from 'librechat-data-provider';
@@ -264,10 +265,10 @@ export const useLogoutUserMutation = (
onMutate: (...args) => {
setDefaultPreset(null);
queryClient.removeQueries();
- localStorage.removeItem('lastConversationSetup');
- localStorage.removeItem('lastSelectedModel');
- localStorage.removeItem('lastSelectedTools');
- localStorage.removeItem('filesToDelete');
+ localStorage.removeItem(LocalStorageKeys.LAST_CONVO_SETUP);
+ localStorage.removeItem(LocalStorageKeys.LAST_MODEL);
+ localStorage.removeItem(LocalStorageKeys.LAST_TOOLS);
+ localStorage.removeItem(LocalStorageKeys.FILES_TO_DELETE);
// localStorage.removeItem('lastAssistant');
options?.onMutate?.(...args);
},
diff --git a/client/src/hooks/Assistants/useSelectAssistant.ts b/client/src/hooks/Assistants/useSelectAssistant.ts
index be451ea95a..929d2df55b 100644
--- a/client/src/hooks/Assistants/useSelectAssistant.ts
+++ b/client/src/hooks/Assistants/useSelectAssistant.ts
@@ -1,9 +1,9 @@
import { useCallback } from 'react';
import { EModelEndpoint, defaultOrderQuery } from 'librechat-data-provider';
import type { TConversation, TPreset } from 'librechat-data-provider';
+import useDefaultConvo from '~/hooks/Conversations/useDefaultConvo';
import { useListAssistantsQuery } from '~/data-provider';
import { useChatContext } from '~/Providers/ChatContext';
-import useDefaultConvo from '~/hooks/useDefaultConvo';
import { mapAssistants } from '~/utils';
export default function useSelectAssistant() {
diff --git a/client/src/hooks/Config/index.ts b/client/src/hooks/Config/index.ts
index 4665f58d45..8be1beefda 100644
--- a/client/src/hooks/Config/index.ts
+++ b/client/src/hooks/Config/index.ts
@@ -1 +1 @@
-export { default as useConfigOverride } from './useConfigOverride';
+export { default as useAppStartup } from './useAppStartup';
diff --git a/client/src/hooks/Config/useAppStartup.ts b/client/src/hooks/Config/useAppStartup.ts
new file mode 100644
index 0000000000..cf1de06a46
--- /dev/null
+++ b/client/src/hooks/Config/useAppStartup.ts
@@ -0,0 +1,101 @@
+import { useEffect } from 'react';
+import { useRecoilState, useSetRecoilState } from 'recoil';
+import { LocalStorageKeys } from 'librechat-data-provider';
+import { useAvailablePluginsQuery } from 'librechat-data-provider/react-query';
+import type { TStartupConfig, TPlugin, TUser } from 'librechat-data-provider';
+import { data as modelSpecs } from '~/components/Chat/Menus/Models/fakeData';
+import { mapPlugins, selectPlugins, processPlugins } from '~/utils';
+import useConfigOverride from './useConfigOverride';
+import store from '~/store';
+
+const pluginStore: TPlugin = {
+ name: 'Plugin store',
+ pluginKey: 'pluginStore',
+ isButton: true,
+ description: '',
+ icon: '',
+ authConfig: [],
+ authenticated: false,
+};
+
+export default function useAppStartup({
+ startupConfig,
+ user,
+}: {
+ startupConfig?: TStartupConfig;
+ user?: TUser;
+}) {
+ useConfigOverride();
+ const setAvailableTools = useSetRecoilState(store.availableTools);
+ const [defaultPreset, setDefaultPreset] = useRecoilState(store.defaultPreset);
+ const { data: allPlugins } = useAvailablePluginsQuery({
+ enabled: !!user?.plugins,
+ select: selectPlugins,
+ });
+
+ /** Set the app title */
+ useEffect(() => {
+ if (startupConfig?.appTitle) {
+ document.title = startupConfig.appTitle;
+ localStorage.setItem(LocalStorageKeys.APP_TITLE, startupConfig.appTitle);
+ }
+ }, [startupConfig]);
+
+ /** Set the default spec's preset as default */
+ useEffect(() => {
+ if (defaultPreset && defaultPreset.spec) {
+ return;
+ }
+
+ if (!modelSpecs || !modelSpecs.length) {
+ return;
+ }
+
+ const defaultSpec = modelSpecs.find((spec) => spec.default);
+
+ if (!defaultSpec) {
+ return;
+ }
+
+ setDefaultPreset({
+ ...defaultSpec.preset,
+ iconURL: defaultSpec.iconURL,
+ spec: defaultSpec.name,
+ });
+ }, [defaultPreset, setDefaultPreset]);
+
+ /** Set the available Plugins */
+ useEffect(() => {
+ if (!user) {
+ return;
+ }
+
+ if (!allPlugins) {
+ return;
+ }
+
+ if (!user.plugins || user.plugins.length === 0) {
+ setAvailableTools({ pluginStore });
+ return;
+ }
+
+ const tools = [...user.plugins]
+ .map((el) => allPlugins.map[el])
+ .filter((el): el is TPlugin => el !== undefined);
+
+ /* Filter Last Selected Tools */
+ const localStorageItem = localStorage.getItem(LocalStorageKeys.LAST_TOOLS);
+ if (!localStorageItem) {
+ return setAvailableTools({ pluginStore, ...mapPlugins(tools) });
+ }
+ const lastSelectedTools = processPlugins(JSON.parse(localStorageItem) ?? [], allPlugins.map);
+ const filteredTools = lastSelectedTools
+ .filter((tool: TPlugin) =>
+ tools.some((existingTool) => existingTool.pluginKey === tool.pluginKey),
+ )
+ .filter((tool: TPlugin) => !!tool);
+ localStorage.setItem(LocalStorageKeys.LAST_TOOLS, JSON.stringify(filteredTools));
+
+ setAvailableTools({ pluginStore, ...mapPlugins(tools) });
+ }, [allPlugins, user, setAvailableTools]);
+}
diff --git a/client/src/hooks/Conversations/index.ts b/client/src/hooks/Conversations/index.ts
index acefd54b22..e517acb58a 100644
--- a/client/src/hooks/Conversations/index.ts
+++ b/client/src/hooks/Conversations/index.ts
@@ -1,4 +1,9 @@
export { default as usePresets } from './usePresets';
export { default as useGetSender } from './useGetSender';
+export { default as useDefaultConvo } from './useDefaultConvo';
+export { default as useConversation } from './useConversation';
+export { default as useConversations } from './useConversations';
export { default as useDebouncedInput } from './useDebouncedInput';
+export { default as useNavigateToConvo } from './useNavigateToConvo';
+export { default as useSetIndexOptions } from './useSetIndexOptions';
export { default as useParameterEffects } from './useParameterEffects';
diff --git a/client/src/hooks/useConversation.ts b/client/src/hooks/Conversations/useConversation.ts
similarity index 98%
rename from client/src/hooks/useConversation.ts
rename to client/src/hooks/Conversations/useConversation.ts
index 4e124a4138..1a977f1456 100644
--- a/client/src/hooks/useConversation.ts
+++ b/client/src/hooks/Conversations/useConversation.ts
@@ -10,7 +10,7 @@ import type {
TEndpointsConfig,
} from 'librechat-data-provider';
import { buildDefaultConvo, getDefaultEndpoint, getEndpointField } from '~/utils';
-import useOriginNavigate from './useOriginNavigate';
+import useOriginNavigate from '../useOriginNavigate';
import store from '~/store';
const useConversation = () => {
diff --git a/client/src/hooks/useConversations.ts b/client/src/hooks/Conversations/useConversations.ts
similarity index 100%
rename from client/src/hooks/useConversations.ts
rename to client/src/hooks/Conversations/useConversations.ts
diff --git a/client/src/hooks/useDefaultConvo.ts b/client/src/hooks/Conversations/useDefaultConvo.ts
similarity index 100%
rename from client/src/hooks/useDefaultConvo.ts
rename to client/src/hooks/Conversations/useDefaultConvo.ts
diff --git a/client/src/hooks/useNavigateToConvo.tsx b/client/src/hooks/Conversations/useNavigateToConvo.tsx
similarity index 89%
rename from client/src/hooks/useNavigateToConvo.tsx
rename to client/src/hooks/Conversations/useNavigateToConvo.tsx
index 5b8798f9c5..0a0e1ae812 100644
--- a/client/src/hooks/useNavigateToConvo.tsx
+++ b/client/src/hooks/Conversations/useNavigateToConvo.tsx
@@ -3,17 +3,14 @@ import { useSetRecoilState, useResetRecoilState } from 'recoil';
import { QueryKeys } from 'librechat-data-provider';
import type { TConversation, TEndpointsConfig, TModelsConfig } from 'librechat-data-provider';
import { buildDefaultConvo, getDefaultEndpoint, getEndpointField } from '~/utils';
-import useOriginNavigate from './useOriginNavigate';
-import useSetStorage from './useSetStorage';
+import useOriginNavigate from '../useOriginNavigate';
import store from '~/store';
const useNavigateToConvo = (index = 0) => {
- const setStorage = useSetStorage();
const queryClient = useQueryClient();
const navigate = useOriginNavigate();
const { setConversation } = store.useCreateConversationAtom(index);
const setSubmission = useSetRecoilState(store.submissionByIndex(index));
- // const setConversation = useSetRecoilState(store.conversationByIndex(index));
const resetLatestMessage = useResetRecoilState(store.latestMessageFamily(index));
const navigateToConvo = (conversation: TConversation, _resetLatestMessage = true) => {
@@ -50,7 +47,6 @@ const useNavigateToConvo = (index = 0) => {
models,
});
}
- setStorage(convo);
setConversation(convo);
navigate(convo?.conversationId);
};
diff --git a/client/src/hooks/usePresetIndexOptions.ts b/client/src/hooks/Conversations/usePresetIndexOptions.ts
similarity index 62%
rename from client/src/hooks/usePresetIndexOptions.ts
rename to client/src/hooks/Conversations/usePresetIndexOptions.ts
index 47732a2522..d1220976fe 100644
--- a/client/src/hooks/usePresetIndexOptions.ts
+++ b/client/src/hooks/Conversations/usePresetIndexOptions.ts
@@ -1,11 +1,15 @@
-import { TPreset } from 'librechat-data-provider';
+import { useRecoilValue, useSetRecoilState } from 'recoil';
+import type { TPreset, TPlugin } from 'librechat-data-provider';
import type { TSetOptionsPayload, TSetExample, TSetOption } from '~/common';
import { useChatContext } from '~/Providers/ChatContext';
import { cleanupPreset } from '~/utils';
+import store from '~/store';
type TUsePresetOptions = (preset?: TPreset | boolean | null) => TSetOptionsPayload | boolean;
-const usePresetOptions: TUsePresetOptions = (_preset) => {
+const usePresetIndexOptions: TUsePresetOptions = (_preset) => {
+ const setShowPluginStoreDialog = useSetRecoilState(store.showPluginStoreDialog);
+ const availableTools = useRecoilValue(store.availableTools);
const { preset, setPreset } = useChatContext();
if (!_preset) {
@@ -99,9 +103,52 @@ const usePresetOptions: TUsePresetOptions = (_preset) => {
);
};
- const checkPluginSelection: (value: string) => boolean = () => false;
- const setTools: (newValue: string) => void = () => {
- return;
+ function checkPluginSelection(value: string) {
+ if (!preset?.tools) {
+ return false;
+ }
+ return preset.tools.find((el) => {
+ if (typeof el === 'string') {
+ return el === value;
+ }
+ return el.pluginKey === value;
+ })
+ ? true
+ : false;
+ }
+
+ const setTools: (newValue: string, remove?: boolean) => void = (newValue, remove) => {
+ if (newValue === 'pluginStore') {
+ setShowPluginStoreDialog(true);
+ return;
+ }
+
+ const update = {};
+ const current =
+ preset?.tools
+ ?.map((tool: string | TPlugin) => {
+ if (typeof tool === 'string') {
+ return availableTools[tool];
+ }
+ return tool;
+ })
+ ?.filter((el) => !!el) || [];
+ const isSelected = checkPluginSelection(newValue);
+ const tool = availableTools[newValue];
+ if (isSelected || remove) {
+ update['tools'] = current.filter((el) => el.pluginKey !== newValue);
+ } else {
+ update['tools'] = [...current, tool];
+ }
+
+ setPreset((prevState) =>
+ cleanupPreset({
+ preset: {
+ ...prevState,
+ ...update,
+ },
+ }),
+ );
};
return {
@@ -116,4 +163,4 @@ const usePresetOptions: TUsePresetOptions = (_preset) => {
};
};
-export default usePresetOptions;
+export default usePresetIndexOptions;
diff --git a/client/src/hooks/Conversations/usePresets.ts b/client/src/hooks/Conversations/usePresets.ts
index f3723eb137..51253efece 100644
--- a/client/src/hooks/Conversations/usePresets.ts
+++ b/client/src/hooks/Conversations/usePresets.ts
@@ -11,9 +11,9 @@ import {
useDeletePresetMutation,
useGetPresetsQuery,
} from '~/data-provider';
+import { cleanupPreset, getEndpointField, removeUnavailableTools } from '~/utils';
+import useDefaultConvo from '~/hooks/Conversations/useDefaultConvo';
import { useChatContext, useToastContext } from '~/Providers';
-import { cleanupPreset, getEndpointField } from '~/utils';
-import useDefaultConvo from '~/hooks/useDefaultConvo';
import { useAuthContext } from '~/hooks/AuthContext';
import { NotificationSeverity } from '~/common';
import useLocalize from '~/hooks/useLocalize';
@@ -28,6 +28,7 @@ export default function usePresets() {
const { user, isAuthenticated } = useAuthContext();
const modularChat = useRecoilValue(store.modularChat);
+ const availableTools = useRecoilValue(store.availableTools);
const setPresetModalVisible = useSetRecoilState(store.presetModalVisible);
const [_defaultPreset, setDefaultPreset] = useRecoilState(store.defaultPreset);
const presetsQuery = useGetPresetsQuery({ enabled: !!user && isAuthenticated });
@@ -151,11 +152,13 @@ export default function usePresets() {
importPreset(jsonPreset);
};
- const onSelectPreset = (newPreset: TPreset) => {
- if (!newPreset) {
+ const onSelectPreset = (_newPreset: TPreset) => {
+ if (!_newPreset) {
return;
}
+ const newPreset = removeUnavailableTools(_newPreset, availableTools);
+
const toastTitle = newPreset.title
? `"${newPreset.title}"`
: localize('com_endpoint_preset_title');
diff --git a/client/src/hooks/useSetIndexOptions.ts b/client/src/hooks/Conversations/useSetIndexOptions.ts
similarity index 74%
rename from client/src/hooks/useSetIndexOptions.ts
rename to client/src/hooks/Conversations/useSetIndexOptions.ts
index 24520348c9..7e664420f7 100644
--- a/client/src/hooks/useSetIndexOptions.ts
+++ b/client/src/hooks/Conversations/useSetIndexOptions.ts
@@ -1,15 +1,8 @@
import { useRecoilValue, useSetRecoilState } from 'recoil';
-import {
- TPreset,
- TPlugin,
- tConvoUpdateSchema,
- EModelEndpoint,
- TConversation,
-} from 'librechat-data-provider';
+import { TPreset, TPlugin, TConversation, tConvoUpdateSchema } from 'librechat-data-provider';
import type { TSetExample, TSetOption, TSetOptionsPayload } from '~/common';
import usePresetIndexOptions from './usePresetIndexOptions';
import { useChatContext } from '~/Providers/ChatContext';
-import useLocalStorage from './useLocalStorage';
import store from '~/store';
type TUseSetOptions = (preset?: TPreset | boolean | null) => TSetOptionsPayload;
@@ -18,11 +11,6 @@ const useSetIndexOptions: TUseSetOptions = (preset = false) => {
const setShowPluginStoreDialog = useSetRecoilState(store.showPluginStoreDialog);
const availableTools = useRecoilValue(store.availableTools);
const { conversation, setConversation } = useChatContext();
- const [lastBingSettings, setLastBingSettings] = useLocalStorage('lastBingSettings', {});
- const [lastModel, setLastModel] = useLocalStorage('lastSelectedModel', {
- primaryModel: '',
- secondaryModel: '',
- });
const result = usePresetIndexOptions(preset);
@@ -31,16 +19,10 @@ const useSetIndexOptions: TUseSetOptions = (preset = false) => {
}
const setOption: TSetOption = (param) => (newValue) => {
- const { endpoint } = conversation ?? {};
const update = {};
update[param] = newValue;
- if (param === 'model' && endpoint) {
- const lastModelUpdate = { ...lastModel, [endpoint]: newValue };
- setLastModel(lastModelUpdate);
- } else if (param === 'jailbreak' && endpoint) {
- setLastBingSettings({ ...lastBingSettings, jailbreak: newValue });
- } else if (param === 'presetOverride') {
+ if (param === 'presetOverride') {
const currentOverride = conversation?.presetOverride || {};
update['presetOverride'] = {
...currentOverride,
@@ -116,7 +98,14 @@ const useSetIndexOptions: TUseSetOptions = (preset = false) => {
if (!conversation?.tools) {
return false;
}
- return conversation.tools.find((el) => el.pluginKey === value) ? true : false;
+ return conversation.tools.find((el) => {
+ if (typeof el === 'string') {
+ return el === value;
+ }
+ return el.pluginKey === value;
+ })
+ ? true
+ : false;
}
const setAgentOption: TSetOption = (param) => (newValue) => {
@@ -124,12 +113,7 @@ const useSetIndexOptions: TUseSetOptions = (preset = false) => {
const convo = JSON.parse(editableConvo);
const { agentOptions } = convo;
agentOptions[param] = newValue;
- console.log('agentOptions', agentOptions, param, newValue);
- if (param === 'model' && typeof newValue === 'string') {
- const lastModelUpdate = { ...lastModel, [EModelEndpoint.gptPlugins]: newValue };
- lastModelUpdate.secondaryModel = newValue;
- setLastModel(lastModelUpdate);
- }
+
setConversation(
(prevState) =>
tConvoUpdateSchema.parse({
@@ -146,17 +130,23 @@ const useSetIndexOptions: TUseSetOptions = (preset = false) => {
}
const update = {};
- const current = conversation?.tools || [];
+ const current =
+ conversation?.tools
+ ?.map((tool: string | TPlugin) => {
+ if (typeof tool === 'string') {
+ return availableTools[tool];
+ }
+ return tool;
+ })
+ ?.filter((el) => !!el) || [];
const isSelected = checkPluginSelection(newValue);
- const tool =
- availableTools[availableTools.findIndex((el: TPlugin) => el.pluginKey === newValue)];
+ const tool = availableTools[newValue];
if (isSelected || remove) {
update['tools'] = current.filter((el) => el.pluginKey !== newValue);
} else {
update['tools'] = [...current, tool];
}
- localStorage.setItem('lastSelectedTools', JSON.stringify(update['tools']));
setConversation(
(prevState) =>
tConvoUpdateSchema.parse({
diff --git a/client/src/hooks/Files/useSetFilesToDelete.ts b/client/src/hooks/Files/useSetFilesToDelete.ts
index 64f31f3f3d..c33558ee4c 100644
--- a/client/src/hooks/Files/useSetFilesToDelete.ts
+++ b/client/src/hooks/Files/useSetFilesToDelete.ts
@@ -1,5 +1,7 @@
+import { LocalStorageKeys } from 'librechat-data-provider';
+
export default function useSetFilesToDelete() {
const setFilesToDelete = (files: Record<string, unknown>) =>
- localStorage.setItem('filesToDelete', JSON.stringify(files));
+ localStorage.setItem(LocalStorageKeys.FILES_TO_DELETE, JSON.stringify(files));
return setFilesToDelete;
}
diff --git a/client/src/hooks/Messages/useMessageHelpers.ts b/client/src/hooks/Messages/useMessageHelpers.tsx
similarity index 79%
rename from client/src/hooks/Messages/useMessageHelpers.ts
rename to client/src/hooks/Messages/useMessageHelpers.tsx
index 5d22d183d2..bcf4949fc4 100644
--- a/client/src/hooks/Messages/useMessageHelpers.ts
+++ b/client/src/hooks/Messages/useMessageHelpers.tsx
@@ -1,16 +1,11 @@
import copy from 'copy-to-clipboard';
import { useEffect, useRef, useCallback } from 'react';
import { EModelEndpoint, ContentTypes } from 'librechat-data-provider';
-import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
-import type { TMessage } from 'librechat-data-provider';
import type { TMessageProps } from '~/common';
import { useChatContext, useAssistantsMapContext } from '~/Providers';
-import Icon from '~/components/Endpoints/Icon';
-import { getEndpointField } from '~/utils';
export default function useMessageHelpers(props: TMessageProps) {
const latestText = useRef<string | number>('');
- const { data: endpointsConfig } = useGetEndpointsQuery();
const { message, currentEditId, setCurrentEditId } = props;
const {
@@ -62,18 +57,6 @@ export default function useMessageHelpers(props: TMessageProps) {
const assistant =
conversation?.endpoint === EModelEndpoint.assistants && assistantMap?.[message?.model ?? ''];
- const iconEndpoint = message?.endpoint ?? conversation?.endpoint;
- const icon = Icon({
- ...conversation,
- ...(message as TMessage),
- iconURL: !assistant
- ? getEndpointField(endpointsConfig, iconEndpoint, 'iconURL')
- : (assistant?.metadata?.avatar as string | undefined) ?? '',
- model: message?.model ?? conversation?.model,
- assistantName: assistant ? (assistant.name as string | undefined) : '',
- size: 28.8,
- });
-
const regenerateMessage = () => {
if ((isSubmitting && isCreatedByUser) || !message) {
return;
@@ -105,7 +88,6 @@ export default function useMessageHelpers(props: TMessageProps) {
return {
ask,
- icon,
edit,
isLast,
assistant,
diff --git a/client/src/hooks/Nav/useSideNavLinks.ts b/client/src/hooks/Nav/useSideNavLinks.ts
index 0656eac5dc..4c1a826507 100644
--- a/client/src/hooks/Nav/useSideNavLinks.ts
+++ b/client/src/hooks/Nav/useSideNavLinks.ts
@@ -4,7 +4,7 @@ import {
// Settings2,
} from 'lucide-react';
import { EModelEndpoint } from 'librechat-data-provider';
-import type { TConfig } from 'librechat-data-provider';
+import type { TConfig, TInterfaceConfig } from 'librechat-data-provider';
import type { NavLink } from '~/common';
import PanelSwitch from '~/components/SidePanel/Builder/PanelSwitch';
// import Parameters from '~/components/SidePanel/Parameters/Panel';
@@ -16,11 +16,13 @@ export default function useSideNavLinks({
assistants,
keyProvided,
endpoint,
+ interfaceConfig,
}: {
hidePanel: () => void;
assistants?: TConfig | null;
keyProvided: boolean;
endpoint?: EModelEndpoint | null;
+ interfaceConfig: Partial<TInterfaceConfig>;
}) {
const Links = useMemo(() => {
const links: NavLink[] = [];
@@ -37,7 +39,8 @@ export default function useSideNavLinks({
endpoint === EModelEndpoint.assistants &&
assistants &&
assistants.disableBuilder !== true &&
- keyProvided
+ keyProvided &&
+ interfaceConfig.parameters
) {
links.push({
title: 'com_sidepanel_assistant_builder',
@@ -65,7 +68,7 @@ export default function useSideNavLinks({
});
return links;
- }, [assistants, keyProvided, hidePanel, endpoint]);
+ }, [assistants, keyProvided, hidePanel, endpoint, interfaceConfig.parameters]);
return Links;
}
diff --git a/client/src/hooks/Plugins/index.ts b/client/src/hooks/Plugins/index.ts
index 7b7268128b..53db4f0d27 100644
--- a/client/src/hooks/Plugins/index.ts
+++ b/client/src/hooks/Plugins/index.ts
@@ -1 +1,2 @@
+export { default as usePluginInstall } from './usePluginInstall';
export { default as usePluginDialogHelpers } from './usePluginDialogHelpers';
diff --git a/client/src/hooks/Plugins/usePluginInstall.ts b/client/src/hooks/Plugins/usePluginInstall.ts
new file mode 100644
index 0000000000..f42580199f
--- /dev/null
+++ b/client/src/hooks/Plugins/usePluginInstall.ts
@@ -0,0 +1,77 @@
+// hooks/Plugins/usePluginInstall.ts
+import { useCallback } from 'react';
+import { useUpdateUserPluginsMutation } from 'librechat-data-provider/react-query';
+import type {
+ TError,
+ TUser,
+ TUpdateUserPlugins,
+ TPlugin,
+ TPluginAction,
+} from 'librechat-data-provider';
+import { useSetRecoilState } from 'recoil';
+import store from '~/store';
+
+interface PluginStoreHandlers {
+ onInstallError?: (error: TError) => void;
+ onUninstallError?: (error: TError) => void;
+ onInstallSuccess?: (data: TUser, variables: TUpdateUserPlugins, context: unknown) => void;
+ onUninstallSuccess?: (data: TUser, variables: TUpdateUserPlugins, context: unknown) => void;
+}
+
+export default function usePluginInstall(handlers: PluginStoreHandlers = {}) {
+ const setAvailableTools = useSetRecoilState(store.availableTools);
+ const { onInstallError, onInstallSuccess, onUninstallError, onUninstallSuccess } = handlers;
+ const updateUserPlugins = useUpdateUserPluginsMutation();
+
+ const installPlugin = useCallback(
+ (pluginAction: TPluginAction, plugin: TPlugin) => {
+ updateUserPlugins.mutate(pluginAction, {
+ onError: (error: unknown) => {
+ if (onInstallError) {
+ onInstallError(error as TError);
+ }
+ },
+ onSuccess: (...rest) => {
+ setAvailableTools((prev) => {
+ return { ...prev, [plugin.pluginKey]: plugin };
+ });
+ if (onInstallSuccess) {
+ onInstallSuccess(...rest);
+ }
+ },
+ });
+ },
+ [updateUserPlugins, onInstallError, onInstallSuccess, setAvailableTools],
+ );
+
+ const uninstallPlugin = useCallback(
+ (plugin: string) => {
+ updateUserPlugins.mutate(
+ { pluginKey: plugin, action: 'uninstall', auth: null },
+ {
+ onError: (error: unknown) => {
+ if (onUninstallError) {
+ onUninstallError(error as TError);
+ }
+ },
+ onSuccess: (...rest) => {
+ setAvailableTools((prev) => {
+ const newAvailableTools = { ...prev };
+ delete newAvailableTools[plugin];
+ return newAvailableTools;
+ });
+ if (onUninstallSuccess) {
+ onUninstallSuccess(...rest);
+ }
+ },
+ },
+ );
+ },
+ [updateUserPlugins, onUninstallError, onUninstallSuccess, setAvailableTools],
+ );
+
+ return {
+ installPlugin,
+ uninstallPlugin,
+ };
+}
diff --git a/client/src/hooks/SSE/useSSE.ts b/client/src/hooks/SSE/useSSE.ts
index 84c3449123..2342253871 100644
--- a/client/src/hooks/SSE/useSSE.ts
+++ b/client/src/hooks/SSE/useSSE.ts
@@ -7,12 +7,13 @@ import {
/* @ts-ignore */
SSE,
QueryKeys,
- EndpointURLs,
Constants,
+ EndpointURLs,
createPayload,
tPresetSchema,
tMessageSchema,
EModelEndpoint,
+ LocalStorageKeys,
tConvoUpdateSchema,
removeNullishValues,
} from 'librechat-data-provider';
@@ -34,7 +35,6 @@ import { useGenTitleMutation } from '~/data-provider';
import useContentHandler from './useContentHandler';
import { useAuthContext } from '../AuthContext';
import useChatHelpers from '../useChatHelpers';
-import useSetStorage from '../useSetStorage';
import store from '~/store';
type TResData = {
@@ -59,7 +59,6 @@ type TSyncData = {
};
export default function useSSE(submission: TSubmission | null, index = 0) {
- const setStorage = useSetStorage();
const queryClient = useQueryClient();
const genTitle = useGenTitleMutation();
@@ -165,13 +164,12 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
...convoUpdate,
};
- setStorage(update);
return update;
});
setIsSubmitting(false);
},
- [setMessages, setConversation, setStorage, genTitle, queryClient, setIsSubmitting],
+ [setMessages, setConversation, genTitle, queryClient, setIsSubmitting],
);
const syncHandler = useCallback(
@@ -208,7 +206,6 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
messages: [requestMessage.messageId, responseMessage.messageId],
}) as TConversation;
- setStorage(update);
return update;
});
@@ -227,7 +224,7 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
resetLatestMessage();
},
- [setMessages, setConversation, setStorage, queryClient, setShowStopButton, resetLatestMessage],
+ [setMessages, setConversation, queryClient, setShowStopButton, resetLatestMessage],
);
const createdHandler = useCallback(
@@ -273,7 +270,6 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
title,
}) as TConversation;
- setStorage(update);
return update;
});
@@ -289,7 +285,7 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
});
resetLatestMessage();
},
- [setMessages, setConversation, setStorage, queryClient, resetLatestMessage],
+ [setMessages, setConversation, queryClient, resetLatestMessage],
);
const finalHandler = useCallback(
@@ -336,21 +332,12 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
update.model = prevState.model;
}
- setStorage(update);
return update;
});
setIsSubmitting(false);
},
- [
- setMessages,
- setConversation,
- setStorage,
- genTitle,
- queryClient,
- setIsSubmitting,
- setShowStopButton,
- ],
+ [genTitle, queryClient, setMessages, setConversation, setIsSubmitting, setShowStopButton],
);
const errorHandler = useCallback(
@@ -430,8 +417,9 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
async (conversationId = '', submission: TSubmission) => {
let runAbortKey = '';
try {
- const conversation = (JSON.parse(localStorage.getItem('lastConversationSetup') ?? '') ??
- {}) as TConversation;
+ const conversation = (JSON.parse(
+ localStorage.getItem(LocalStorageKeys.LAST_CONVO_SETUP) ?? '',
+ ) ?? {}) as TConversation;
const { conversationId, messages } = conversation;
runAbortKey = `${conversationId}:${messages?.[messages.length - 1]}`;
} catch (error) {
diff --git a/client/src/hooks/index.ts b/client/src/hooks/index.ts
index ee6d8b2519..eeeef0164d 100644
--- a/client/src/hooks/index.ts
+++ b/client/src/hooks/index.ts
@@ -17,20 +17,11 @@ export { default as useTimeout } from './useTimeout';
export { default as useNewConvo } from './useNewConvo';
export { default as useLocalize } from './useLocalize';
export { default as useMediaQuery } from './useMediaQuery';
-export { default as useSetOptions } from './useSetOptions';
-export { default as useSetStorage } from './useSetStorage';
export { default as useChatHelpers } from './useChatHelpers';
export { default as useGenerations } from './useGenerations';
export { default as useScrollToRef } from './useScrollToRef';
export { default as useLocalStorage } from './useLocalStorage';
-export { default as useConversation } from './useConversation';
-export { default as useDefaultConvo } from './useDefaultConvo';
-export { default as useServerStream } from './useServerStream';
-export { default as useConversations } from './useConversations';
export { default as useDelayedRender } from './useDelayedRender';
export { default as useOnClickOutside } from './useOnClickOutside';
-export { default as useMessageHandler } from './useMessageHandler';
export { default as useOriginNavigate } from './useOriginNavigate';
-export { default as useNavigateToConvo } from './useNavigateToConvo';
-export { default as useSetIndexOptions } from './useSetIndexOptions';
export { default as useGenerationsByLatest } from './useGenerationsByLatest';
diff --git a/client/src/hooks/useChatHelpers.ts b/client/src/hooks/useChatHelpers.ts
index 755e3ffb70..0a3d42b957 100644
--- a/client/src/hooks/useChatHelpers.ts
+++ b/client/src/hooks/useChatHelpers.ts
@@ -211,6 +211,7 @@ export default function useChatHelpers(index = 0, paramId: string | undefined) {
unfinished: false,
isCreatedByUser: false,
isEdited: isEditOrContinue,
+ iconURL: convo.iconURL,
error: false,
};
diff --git a/client/src/hooks/useMessageHandler.ts b/client/src/hooks/useMessageHandler.ts
deleted file mode 100644
index 63757f9fbb..0000000000
--- a/client/src/hooks/useMessageHandler.ts
+++ /dev/null
@@ -1,207 +0,0 @@
-import { v4 } from 'uuid';
-import { parseConvo, getResponseSender } from 'librechat-data-provider';
-import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
-import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
-import type { TMessage, TSubmission, TEndpointOption } from 'librechat-data-provider';
-import type { TAskFunction } from '~/common';
-import useUserKey from './Input/useUserKey';
-import store from '~/store';
-
-const useMessageHandler = () => {
- const [latestMessage, setLatestMessage] = useRecoilState(store.latestMessage);
- const setSiblingIdx = useSetRecoilState(
- store.messagesSiblingIdxFamily(latestMessage?.parentMessageId),
- );
- const currentConversation = useRecoilValue(store.conversation) || { endpoint: null };
- const setSubmission = useSetRecoilState(store.submission);
- const isSubmitting = useRecoilValue(store.isSubmitting);
- const { data: endpointsConfig } = useGetEndpointsQuery();
- const [messages, setMessages] = useRecoilState(store.messages);
- const { endpoint } = currentConversation;
- const { getExpiry } = useUserKey(endpoint ?? '');
-
- const ask: TAskFunction = (
- { text, parentMessageId = null, conversationId = null, messageId = null },
- {
- editedText = null,
- editedMessageId = null,
- isRegenerate = false,
- isContinued = false,
- isEdited = false,
- } = {},
- ) => {
- if (!!isSubmitting || text === '') {
- return;
- }
-
- if (endpoint === null) {
- console.error('No endpoint available');
- return;
- }
-
- conversationId = conversationId ?? currentConversation?.conversationId;
- if (conversationId == 'search') {
- console.error('cannot send any message under search view!');
- return;
- }
-
- if (isContinued && !latestMessage) {
- console.error('cannot continue AI message without latestMessage!');
- return;
- }
-
- const isEditOrContinue = isEdited || isContinued;
-
- // set the endpoint option
- const convo = parseConvo(endpoint, currentConversation);
- const endpointOption = {
- ...convo,
- endpoint,
- key: getExpiry(),
- } as TEndpointOption;
- const responseSender = getResponseSender(endpointOption);
-
- let currentMessages: TMessage[] | null = messages ?? [];
-
- // construct the query message
- // this is not a real messageId, it is used as placeholder before real messageId returned
- text = text.trim();
- const fakeMessageId = v4();
- parentMessageId =
- parentMessageId || latestMessage?.messageId || '00000000-0000-0000-0000-000000000000';
-
- if (conversationId == 'new') {
- parentMessageId = '00000000-0000-0000-0000-000000000000';
- currentMessages = [];
- conversationId = null;
- }
- const currentMsg: TMessage = {
- text,
- sender: 'User',
- isCreatedByUser: true,
- parentMessageId,
- conversationId,
- messageId: isContinued && messageId ? messageId : fakeMessageId,
- error: false,
- };
-
- // construct the placeholder response message
- const generation = editedText ?? latestMessage?.text ?? '';
- const responseText = isEditOrContinue ? generation : '';
-
- const responseMessageId = editedMessageId ?? latestMessage?.messageId ?? null;
- const initialResponse: TMessage = {
- sender: responseSender,
- text: responseText,
- parentMessageId: isRegenerate ? messageId : fakeMessageId,
- messageId: responseMessageId ?? `${isRegenerate ? messageId : fakeMessageId}_`,
- conversationId,
- unfinished: false,
- isCreatedByUser: false,
- isEdited: isEditOrContinue,
- error: false,
- };
-
- if (isContinued) {
- currentMessages = currentMessages.filter((msg) => msg.messageId !== responseMessageId);
- }
-
- const submission: TSubmission = {
- conversation: {
- ...currentConversation,
- conversationId,
- },
- endpointOption,
- message: {
- ...currentMsg,
- generation,
- responseMessageId,
- overrideParentMessageId: isRegenerate ? messageId : null,
- },
- messages: currentMessages,
- isEdited: isEditOrContinue,
- isContinued,
- isRegenerate,
- initialResponse,
- };
-
- if (isRegenerate) {
- setMessages([...submission.messages, initialResponse]);
- } else {
- setMessages([...submission.messages, currentMsg, initialResponse]);
- }
- setLatestMessage(initialResponse);
- setSubmission(submission);
- };
-
- const regenerate = ({ parentMessageId }) => {
- const parentMessage = messages?.find((element) => element.messageId == parentMessageId);
-
- if (parentMessage && parentMessage.isCreatedByUser) {
- ask({ ...parentMessage }, { isRegenerate: true });
- } else {
- console.error(
- 'Failed to regenerate the message: parentMessage not found or not created by user.',
- );
- }
- };
-
- const continueGeneration = () => {
- if (!latestMessage) {
- console.error('Failed to regenerate the message: latestMessage not found.');
- return;
- }
-
- const parentMessage = messages?.find(
- (element) => element.messageId == latestMessage.parentMessageId,
- );
-
- if (parentMessage && parentMessage.isCreatedByUser) {
- ask({ ...parentMessage }, { isContinued: true, isRegenerate: true, isEdited: true });
- } else {
- console.error(
- 'Failed to regenerate the message: parentMessage not found, or not created by user.',
- );
- }
- };
-
- const stopGenerating = () => {
- setSubmission(null);
- };
-
- const handleStopGenerating = (e: React.MouseEvent<HTMLButtonElement>) => {
- e.preventDefault();
- stopGenerating();
- };
-
- const handleRegenerate = (e: React.MouseEvent<HTMLButtonElement>) => {
- e.preventDefault();
- const parentMessageId = latestMessage?.parentMessageId;
- if (!parentMessageId) {
- console.error('Failed to regenerate the message: parentMessageId not found.');
- return;
- }
- regenerate({ parentMessageId });
- };
-
- const handleContinue = (e: React.MouseEvent<HTMLButtonElement>) => {
- e.preventDefault();
- continueGeneration();
- setSiblingIdx(0);
- };
-
- return {
- ask,
- regenerate,
- stopGenerating,
- handleStopGenerating,
- handleRegenerate,
- handleContinue,
- endpointsConfig,
- latestMessage,
- isSubmitting,
- messages,
- };
-};
-
-export default useMessageHandler;
diff --git a/client/src/hooks/useNewConvo.ts b/client/src/hooks/useNewConvo.ts
index fafb34223d..6923240e28 100644
--- a/client/src/hooks/useNewConvo.ts
+++ b/client/src/hooks/useNewConvo.ts
@@ -1,35 +1,45 @@
import { useCallback, useRef } from 'react';
-import { EModelEndpoint, FileSources, defaultOrderQuery } from 'librechat-data-provider';
-import { useGetEndpointsQuery, useGetModelsQuery } from 'librechat-data-provider/react-query';
import {
- useSetRecoilState,
- useResetRecoilState,
- useRecoilCallback,
+ useGetModelsQuery,
+ useGetStartupConfig,
+ useGetEndpointsQuery,
+} from 'librechat-data-provider/react-query';
+import {
+ FileSources,
+ EModelEndpoint,
+ LocalStorageKeys,
+ defaultOrderQuery,
+} from 'librechat-data-provider';
+import {
useRecoilState,
useRecoilValue,
+ useSetRecoilState,
+ useRecoilCallback,
+ useResetRecoilState,
} from 'recoil';
import type {
- TConversation,
- TSubmission,
TPreset,
+ TSubmission,
TModelsConfig,
+ TConversation,
TEndpointsConfig,
} from 'librechat-data-provider';
import {
+ getEndpointField,
buildDefaultConvo,
getDefaultEndpoint,
- getEndpointField,
+ getDefaultModelSpec,
+ getModelSpecIconURL,
updateLastSelectedModel,
} from '~/utils';
import { useDeleteFilesMutation, useListAssistantsQuery } from '~/data-provider';
import useOriginNavigate from './useOriginNavigate';
-import useSetStorage from './useSetStorage';
import { mainTextareaId } from '~/common';
import store from '~/store';
const useNewConvo = (index = 0) => {
- const setStorage = useSetStorage();
const navigate = useOriginNavigate();
+ const { data: startupConfig } = useGetStartupConfig();
const defaultPreset = useRecoilValue(store.defaultPreset);
const { setConversation } = store.useCreateConversationAtom(index);
const [files, setFiles] = useRecoilState(store.filesByIndex(index));
@@ -94,7 +104,8 @@ const useNewConvo = (index = 0) => {
if (!conversation.assistant_id && isAssistantEndpoint) {
conversation.assistant_id =
- localStorage.getItem(`assistant_id__${index}`) ?? assistants[0]?.id;
+ localStorage.getItem(`${LocalStorageKeys.ASST_ID_PREFIX}${index}`) ??
+ assistants[0]?.id;
}
if (
@@ -102,9 +113,7 @@ const useNewConvo = (index = 0) => {
isAssistantEndpoint &&
conversation.conversationId === 'new'
) {
- const assistant = assistants.find(
- (assistant) => assistant.id === conversation.assistant_id,
- );
+ const assistant = assistants.find((asst) => asst.id === conversation.assistant_id);
conversation.model = assistant?.model;
updateLastSelectedModel({
endpoint: EModelEndpoint.assistants,
@@ -125,7 +134,6 @@ const useNewConvo = (index = 0) => {
});
}
- setStorage(conversation);
setConversation(conversation);
setSubmission({} as TSubmission);
if (!keepLatestMessage) {
@@ -133,7 +141,7 @@ const useNewConvo = (index = 0) => {
}
if (conversation.conversationId === 'new' && !modelsData) {
- const appTitle = localStorage.getItem('appTitle');
+ const appTitle = localStorage.getItem(LocalStorageKeys.APP_TITLE);
if (appTitle) {
document.title = appTitle;
}
@@ -154,7 +162,7 @@ const useNewConvo = (index = 0) => {
const newConversation = useCallback(
({
template = {},
- preset,
+ preset: _preset,
modelsData,
buildDefault = true,
keepLatestMessage = false,
@@ -174,6 +182,16 @@ const useNewConvo = (index = 0) => {
updatedAt: '',
};
+ let preset = _preset;
+ const defaultModelSpec = getDefaultModelSpec(startupConfig?.modelSpecs?.list);
+ if (!preset && startupConfig && startupConfig.modelSpecs?.prioritize && defaultModelSpec) {
+ preset = {
+ ...defaultModelSpec.preset,
+ iconURL: getModelSpecIconURL(defaultModelSpec),
+ spec: defaultModelSpec.name,
+ } as TConversation;
+ }
+
if (conversation.conversationId === 'new' && !modelsData) {
const filesToDelete = Array.from(files.values())
.filter((file) => file.filepath && file.source && !file.embedded && file.temp_file_id)
@@ -185,7 +203,7 @@ const useNewConvo = (index = 0) => {
}));
setFiles(new Map());
- localStorage.setItem('filesToDelete', JSON.stringify({}));
+ localStorage.setItem(LocalStorageKeys.FILES_TO_DELETE, JSON.stringify({}));
if (filesToDelete.length > 0) {
mutateAsync({ files: filesToDelete });
@@ -194,7 +212,7 @@ const useNewConvo = (index = 0) => {
switchToConversation(conversation, preset, modelsData, buildDefault, keepLatestMessage);
},
- [switchToConversation, files, mutateAsync, setFiles],
+ [switchToConversation, files, mutateAsync, setFiles, startupConfig],
);
return {
diff --git a/client/src/hooks/usePresetOptions.ts b/client/src/hooks/usePresetOptions.ts
deleted file mode 100644
index 190200967a..0000000000
--- a/client/src/hooks/usePresetOptions.ts
+++ /dev/null
@@ -1,120 +0,0 @@
-import { TPreset } from 'librechat-data-provider';
-import type { TSetOptionsPayload, TSetExample, TSetOption } from '~/common';
-import { useRecoilState } from 'recoil';
-import { cleanupPreset } from '~/utils';
-import store from '~/store';
-
-type TUsePresetOptions = (preset?: TPreset | boolean | null) => TSetOptionsPayload | boolean;
-
-const usePresetOptions: TUsePresetOptions = (_preset) => {
- const [preset, setPreset] = useRecoilState(store.preset);
-
- if (!_preset) {
- return false;
- }
- const getConversation: () => TPreset | null = () => preset;
-
- const setOption: TSetOption = (param) => (newValue) => {
- const update = {};
- update[param] = newValue;
- setPreset((prevState) =>
- cleanupPreset({
- preset: {
- ...prevState,
- ...update,
- },
- }),
- );
- };
-
- const setExample: TSetExample = (i, type, newValue = null) => {
- const update = {};
- const current = preset?.examples?.slice() || [];
- const currentExample = { ...current[i] } || {};
- currentExample[type] = { content: newValue };
- current[i] = currentExample;
- update['examples'] = current;
- setPreset((prevState) =>
- cleanupPreset({
- preset: {
- ...prevState,
- ...update,
- },
- }),
- );
- };
-
- const addExample: () => void = () => {
- const update = {};
- const current = preset?.examples?.slice() || [];
- current.push({ input: { content: '' }, output: { content: '' } });
- update['examples'] = current;
- setPreset((prevState) =>
- cleanupPreset({
- preset: {
- ...prevState,
- ...update,
- },
- }),
- );
- };
-
- const removeExample: () => void = () => {
- const update = {};
- const current = preset?.examples?.slice() || [];
- if (current.length <= 1) {
- update['examples'] = [{ input: { content: '' }, output: { content: '' } }];
- setPreset((prevState) =>
- cleanupPreset({
- preset: {
- ...prevState,
- ...update,
- },
- }),
- );
- return;
- }
- current.pop();
- update['examples'] = current;
- setPreset((prevState) =>
- cleanupPreset({
- preset: {
- ...prevState,
- ...update,
- },
- }),
- );
- };
-
- const setAgentOption: TSetOption = (param) => (newValue) => {
- const editablePreset = JSON.parse(JSON.stringify(_preset));
- const { agentOptions } = editablePreset;
- agentOptions[param] = newValue;
- setPreset((prevState) =>
- cleanupPreset({
- preset: {
- ...prevState,
- agentOptions,
- },
- }),
- );
- };
-
- const checkPluginSelection: (value: string) => boolean = () => false;
- const setTools: (newValue: string) => void = () => {
- return;
- };
-
- return {
- setOption,
- setExample,
- addExample,
- removeExample,
- getConversation,
- checkPluginSelection,
- setAgentOption,
- setTools,
- };
-};
-
-export default usePresetOptions;
diff --git a/client/src/hooks/useServerStream.ts b/client/src/hooks/useServerStream.ts
deleted file mode 100644
index 81aa66b7fc..0000000000
--- a/client/src/hooks/useServerStream.ts
+++ /dev/null
@@ -1,290 +0,0 @@
-import { useEffect } from 'react';
-import { useResetRecoilState, useSetRecoilState } from 'recoil';
-import {
- /* @ts-ignore */
- SSE,
- createPayload,
- tMessageSchema,
- tConversationSchema,
-} from 'librechat-data-provider';
-import { useGetUserBalance, useGetStartupConfig } from 'librechat-data-provider/react-query';
-import type { TResPlugin, TMessage, TConversation, TSubmission } from 'librechat-data-provider';
-import useConversations from './useConversations';
-import { useAuthContext } from './AuthContext';
-
-import store from '~/store';
-
-type TResData = {
- plugin: TResPlugin;
- final?: boolean;
- initial?: boolean;
- requestMessage: TMessage;
- responseMessage: TMessage;
- conversation: TConversation;
-};
-
-export default function useServerStream(submission: TSubmission | null) {
- const setMessages = useSetRecoilState(store.messages);
- const setIsSubmitting = useSetRecoilState(store.isSubmitting);
- const setConversation = useSetRecoilState(store.conversation);
- const resetLatestMessage = useResetRecoilState(store.latestMessage);
- const { token, isAuthenticated } = useAuthContext();
-
- const { data: startupConfig } = useGetStartupConfig();
- const { refreshConversations } = useConversations();
- const balanceQuery = useGetUserBalance({
- enabled: !!isAuthenticated && startupConfig?.checkBalance,
- });
-
- const messageHandler = (data: string, submission: TSubmission) => {
- const {
- messages,
- message,
- plugin,
- plugins,
- initialResponse,
- isRegenerate = false,
- } = submission;
-
- if (isRegenerate) {
- setMessages([
- ...messages,
- {
- ...initialResponse,
- text: data,
- parentMessageId: message?.overrideParentMessageId ?? null,
- messageId: message?.overrideParentMessageId + '_',
- plugin: plugin ?? null,
- plugins: plugins ?? [],
- submitting: true,
- // unfinished: true
- },
- ]);
- } else {
- setMessages([
- ...messages,
- message,
- {
- ...initialResponse,
- text: data,
- parentMessageId: message?.messageId,
- messageId: message?.messageId + '_',
- plugin: plugin ?? null,
- plugins: plugins ?? [],
- submitting: true,
- // unfinished: true
- },
- ]);
- }
- };
-
- const cancelHandler = (data: TResData, submission: TSubmission) => {
- const { requestMessage, responseMessage, conversation } = data;
- const { messages, isRegenerate = false } = submission;
-
- // update the messages
- if (isRegenerate) {
- setMessages([...messages, responseMessage]);
- } else {
- setMessages([...messages, requestMessage, responseMessage]);
- }
- setIsSubmitting(false);
-
- // refresh title
- if (requestMessage.parentMessageId == '00000000-0000-0000-0000-000000000000') {
- setTimeout(() => {
- refreshConversations();
- }, 2000);
-
- // in case it takes too long.
- setTimeout(() => {
- refreshConversations();
- }, 5000);
- }
-
- setConversation((prevState) => ({
- ...prevState,
- ...conversation,
- }));
- };
-
- const createdHandler = (data: TResData, submission: TSubmission) => {
- const { messages, message, initialResponse, isRegenerate = false } = submission;
-
- if (isRegenerate) {
- setMessages([
- ...messages,
- {
- ...initialResponse,
- parentMessageId: message?.overrideParentMessageId ?? null,
- messageId: message?.overrideParentMessageId + '_',
- submitting: true,
- },
- ]);
- } else {
- setMessages([
- ...messages,
- message,
- {
- ...initialResponse,
- parentMessageId: message?.messageId,
- messageId: message?.messageId + '_',
- submitting: true,
- },
- ]);
- }
-
- const { conversationId } = message;
- setConversation((prevState) =>
- tConversationSchema.parse({
- ...prevState,
- conversationId,
- }),
- );
- resetLatestMessage();
- };
-
- const finalHandler = (data: TResData, submission: TSubmission) => {
- const { requestMessage, responseMessage, conversation } = data;
- const { messages, isRegenerate = false } = submission;
-
- // update the messages
- if (isRegenerate) {
- setMessages([...messages, responseMessage]);
- } else {
- setMessages([...messages, requestMessage, responseMessage]);
- }
- setIsSubmitting(false);
-
- // refresh title
- if (requestMessage.parentMessageId == '00000000-0000-0000-0000-000000000000') {
- setTimeout(() => {
- refreshConversations();
- }, 2000);
-
- // in case it takes too long.
- setTimeout(() => {
- refreshConversations();
- }, 5000);
- }
-
- setConversation((prevState) => ({
- ...prevState,
- ...conversation,
- }));
- };
-
- const errorHandler = (data: TResData, submission: TSubmission) => {
- const { messages, message } = submission;
-
- console.log('Error:', data);
- const errorResponse = tMessageSchema.parse({
- ...data,
- error: true,
- parentMessageId: message?.messageId,
- });
- setIsSubmitting(false);
- setMessages([...messages, message, errorResponse]);
- return;
- };
-
- const abortConversation = (conversationId = '', submission: TSubmission) => {
- console.log(submission);
- const { endpoint } = submission?.conversation || {};
-
- fetch(`/api/ask/${endpoint}/abort`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- Authorization: `Bearer ${token}`,
- },
- body: JSON.stringify({
- abortKey: conversationId,
- }),
- })
- .then((response) => response.json())
- .then((data) => {
- console.log('aborted', data);
- cancelHandler(data, submission);
- })
- .catch((error) => {
- console.error('Error aborting request');
- console.error(error);
- // errorHandler({ text: 'Error aborting request' }, { ...submission, message });
- });
- return;
- };
-
- useEffect(() => {
- if (submission === null) {
- return;
- }
- if (Object.keys(submission).length === 0) {
- return;
- }
-
- let { message } = submission;
-
- const { server, payload } = createPayload(submission);
-
- const events = new SSE(server, {
- payload: JSON.stringify(payload),
- headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
- });
-
- events.onmessage = (e: MessageEvent) => {
- const data = JSON.parse(e.data);
-
- if (data.final) {
- const { plugins } = data;
- finalHandler(data, { ...submission, plugins, message });
- startupConfig?.checkBalance && balanceQuery.refetch();
- console.log('final', data);
- }
- if (data.created) {
- message = {
- ...data.message,
- overrideParentMessageId: message?.overrideParentMessageId,
- };
- createdHandler(data, { ...submission, message });
- } else {
- const text = data.text || data.response;
- const { plugin, plugins } = data;
-
- if (data.message) {
- messageHandler(text, { ...submission, plugin, plugins, message });
- }
- }
- };
-
- events.onopen = () => console.log('connection is opened');
-
- events.oncancel = () =>
- abortConversation(message?.conversationId ?? submission?.conversationId, submission);
-
- events.onerror = function (e: MessageEvent) {
- console.log('error in opening conn.');
- startupConfig?.checkBalance && balanceQuery.refetch();
- events.close();
-
- const data = JSON.parse(e.data);
-
- errorHandler(data, { ...submission, message });
- };
-
- setIsSubmitting(true);
- events.stream();
-
- return () => {
- const isCancelled = events.readyState <= 1;
- events.close();
- // setSource(null);
- if (isCancelled) {
- const e = new Event('cancel');
- events.dispatchEvent(e);
- }
- setIsSubmitting(false);
- };
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [submission]);
-}
diff --git a/client/src/hooks/useSetOptions.ts b/client/src/hooks/useSetOptions.ts
deleted file mode 100644
index b27c09e21c..0000000000
--- a/client/src/hooks/useSetOptions.ts
+++ /dev/null
@@ -1,142 +0,0 @@
-import { TConversation, TPreset, TPlugin, tConversationSchema } from 'librechat-data-provider';
-import type { TSetExample, TSetOption, TSetOptionsPayload } from '~/common';
-import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
-import usePresetOptions from './usePresetOptions';
-import store from '~/store';
-
-type TUseSetOptions = (preset?: TPreset | boolean | null) => TSetOptionsPayload;
-
-const useSetOptions: TUseSetOptions = (preset = false) => {
- const setShowPluginStoreDialog = useSetRecoilState(store.showPluginStoreDialog);
- const [conversation, setConversation] = useRecoilState(store.conversation);
- const availableTools = useRecoilValue(store.availableTools);
-
- const result = usePresetOptions(preset);
-
- if (result && typeof result !== 'boolean') {
- return result;
- }
-
- const setOption: TSetOption = (param) => (newValue) => {
- const update = {};
- update[param] = newValue;
- setConversation((prevState) =>
- tConversationSchema.parse({
- ...prevState,
- ...update,
- }),
- );
- };
-
- const setExample: TSetExample = (i, type, newValue = null) => {
- const update = {};
- const current = conversation?.examples?.slice() || [];
- const currentExample = { ...current[i] } || {};
- currentExample[type] = { content: newValue };
- current[i] = currentExample;
- update['examples'] = current;
- setConversation((prevState) =>
- tConversationSchema.parse({
- ...prevState,
- ...update,
- }),
- );
- };
-
- const addExample: () => void = () => {
- const update = {};
- const current = conversation?.examples?.slice() || [];
- current.push({ input: { content: '' }, output: { content: '' } });
- update['examples'] = current;
- setConversation((prevState) =>
- tConversationSchema.parse({
- ...prevState,
- ...update,
- }),
- );
- };
-
- const removeExample: () => void = () => {
- const update = {};
- const current = conversation?.examples?.slice() || [];
- if (current.length <= 1) {
- update['examples'] = [{ input: { content: '' }, output: { content: '' } }];
- setConversation((prevState) =>
- tConversationSchema.parse({
- ...prevState,
- ...update,
- }),
- );
- return;
- }
- current.pop();
- update['examples'] = current;
- setConversation((prevState) =>
- tConversationSchema.parse({
- ...prevState,
- ...update,
- }),
- );
- };
-
- const getConversation: () => TConversation | null = () => conversation;
-
- function checkPluginSelection(value: string) {
- if (!conversation?.tools) {
- return false;
- }
- return conversation.tools.find((el) => el.pluginKey === value) ? true : false;
- }
-
- const setAgentOption: TSetOption = (param) => (newValue) => {
- const editableConvo = JSON.stringify(conversation);
- const convo = JSON.parse(editableConvo);
- const { agentOptions } = convo;
- agentOptions[param] = newValue;
- setConversation((prevState) =>
- tConversationSchema.parse({
- ...prevState,
- agentOptions,
- }),
- );
- };
-
- const setTools: (newValue: string) => void = (newValue) => {
- if (newValue === 'pluginStore') {
- setShowPluginStoreDialog(true);
- return;
- }
-
- const update = {};
- const current = conversation?.tools || [];
- const isSelected = checkPluginSelection(newValue);
- const tool =
- availableTools[availableTools.findIndex((el: TPlugin) => el.pluginKey === newValue)];
- if (isSelected) {
- update['tools'] = current.filter((el) => el.pluginKey !== newValue);
- } else {
- update['tools'] = [...current, tool];
- }
-
- localStorage.setItem('lastSelectedTools', JSON.stringify(update['tools']));
- setConversation((prevState) =>
- tConversationSchema.parse({
- ...prevState,
- ...update,
- }),
- );
- };
-
- return {
- setOption,
- setExample,
- addExample,
- removeExample,
- setAgentOption,
- getConversation,
- checkPluginSelection,
- setTools,
- };
-};
-
-export default useSetOptions;
diff --git a/client/src/hooks/useSetStorage.ts b/client/src/hooks/useSetStorage.ts
deleted file mode 100644
index 22b6c712fa..0000000000
--- a/client/src/hooks/useSetStorage.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import type { TConversation } from 'librechat-data-provider';
-import useLocalStorage from './useLocalStorage';
-
-const useSetStorage = () => {
- const [lastBingSettings, setLastBingSettings] = useLocalStorage('lastBingSettings', {});
- const setLastConvo = useLocalStorage('lastConversationSetup', {})[1];
- const [lastModel, setLastModel] = useLocalStorage('lastSelectedModel', {
- primaryModel: '',
- secondaryModel: '',
- });
-
- const setStorage = (conversation: TConversation) => {
- const { endpoint } = conversation;
- if (endpoint && endpoint !== 'bingAI') {
- const lastModelUpdate = { ...lastModel, [endpoint]: conversation?.model };
- if (endpoint === 'gptPlugins') {
- lastModelUpdate.secondaryModel = conversation?.agentOptions?.model ?? '';
- }
- setLastModel(lastModelUpdate);
- } else if (endpoint === 'bingAI') {
- const { jailbreak, toneStyle } = conversation;
- setLastBingSettings({ ...lastBingSettings, jailbreak, toneStyle });
- }
-
- setLastConvo(conversation);
- };
-
- return setStorage;
-};
-
-export default useSetStorage;
diff --git a/client/src/localization/languages/Eng.ts b/client/src/localization/languages/Eng.ts
index 554bba92c3..a122250ba1 100644
--- a/client/src/localization/languages/Eng.ts
+++ b/client/src/localization/languages/Eng.ts
@@ -115,6 +115,7 @@ export default {
com_ui_new_footer: 'All AI conversations in one place.',
com_ui_enter: 'Enter',
com_ui_submit: 'Submit',
+ com_ui_none_selected: 'None selected',
com_ui_upload_success: 'Successfully uploaded file',
com_ui_upload_error: 'There was an error uploading your file',
com_ui_upload_invalid: 'Invalid file for upload. Must be an image not exceeding 2 MB',
diff --git a/client/src/routes/ChatRoute.tsx b/client/src/routes/ChatRoute.tsx
index 622c91bc67..8b215e67b3 100644
--- a/client/src/routes/ChatRoute.tsx
+++ b/client/src/routes/ChatRoute.tsx
@@ -1,28 +1,29 @@
import { useEffect, useRef } from 'react';
import { useParams } from 'react-router-dom';
+import { defaultOrderQuery } from 'librechat-data-provider';
import {
useGetModelsQuery,
useGetStartupConfig,
useGetEndpointsQuery,
} from 'librechat-data-provider/react-query';
-import { defaultOrderQuery } from 'librechat-data-provider';
import type { TPreset } from 'librechat-data-provider';
import { useGetConvoIdQuery, useListAssistantsQuery } from '~/data-provider';
-import { useNewConvo, useConfigOverride } from '~/hooks';
+import { getDefaultModelSpec, getModelSpecIconURL } from '~/utils';
+import { useNewConvo, useAppStartup } from '~/hooks';
import ChatView from '~/components/Chat/ChatView';
import useAuthRedirect from './useAuthRedirect';
import { Spinner } from '~/components/svg';
import store from '~/store';
export default function ChatRoute() {
- const index = 0;
+ const { data: startupConfig } = useGetStartupConfig();
+ const { isAuthenticated, user } = useAuthRedirect();
+ useAppStartup({ startupConfig, user });
- useConfigOverride();
+ const index = 0;
const { conversationId } = useParams();
- const { data: startupConfig } = useGetStartupConfig();
const { conversation } = store.useCreateConversationAtom(index);
- const { isAuthenticated } = useAuthRedirect();
const { newConversation } = useNewConvo();
const hasSetConversation = useRef(false);
@@ -39,27 +40,34 @@ export default function ChatRoute() {
res.data.map(({ id, name, metadata, model }) => ({ id, name, metadata, model })),
});
- useEffect(() => {
- if (startupConfig?.appTitle) {
- document.title = startupConfig.appTitle;
- localStorage.setItem('appTitle', startupConfig.appTitle);
- }
- }, [startupConfig]);
-
useEffect(() => {
if (
+ startupConfig &&
conversationId === 'new' &&
endpointsQuery.data &&
modelsQuery.data &&
!modelsQuery.data?.initial &&
!hasSetConversation.current
) {
+ const spec = getDefaultModelSpec(startupConfig.modelSpecs?.list);
+
newConversation({
modelsData: modelsQuery.data,
template: conversation ? conversation : undefined,
+ ...(spec
+ ? {
+ preset: {
+ ...spec.preset,
+ iconURL: getModelSpecIconURL(spec),
+ spec: spec.name,
+ },
+ }
+ : {}),
});
+
hasSetConversation.current = true;
} else if (
+ startupConfig &&
initialConvoQuery.data &&
endpointsQuery.data &&
modelsQuery.data &&
@@ -75,17 +83,33 @@ export default function ChatRoute() {
});
hasSetConversation.current = true;
} else if (
+ startupConfig &&
!hasSetConversation.current &&
!modelsQuery.data?.initial &&
conversationId === 'new' &&
assistants
) {
+ const spec = getDefaultModelSpec(startupConfig.modelSpecs?.list);
newConversation({
modelsData: modelsQuery.data,
template: conversation ? conversation : undefined,
+ ...(spec
+ ? {
+ preset: {
+ ...spec.preset,
+ iconURL: getModelSpecIconURL(spec),
+ spec: spec.name,
+ },
+ }
+ : {}),
});
hasSetConversation.current = true;
- } else if (!hasSetConversation.current && !modelsQuery.data?.initial && assistants) {
+ } else if (
+ startupConfig &&
+ !hasSetConversation.current &&
+ !modelsQuery.data?.initial &&
+ assistants
+ ) {
newConversation({
template: initialConvoQuery.data,
preset: initialConvoQuery.data as TPreset,
@@ -96,7 +120,7 @@ export default function ChatRoute() {
}
/* Creates infinite render if all dependencies included due to newConversation invocations exceeding call stack before hasSetConversation.current becomes truthy */
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [initialConvoQuery.data, endpointsQuery.data, modelsQuery.data, assistants]);
+ }, [startupConfig, initialConvoQuery.data, endpointsQuery.data, modelsQuery.data, assistants]);
if (endpointsQuery.isLoading || modelsQuery.isLoading) {
return <Spinner className="m-auto text-black dark:text-white" />;
diff --git a/client/src/routes/Root.tsx b/client/src/routes/Root.tsx
index 41419c364e..529de11726 100644
--- a/client/src/routes/Root.tsx
+++ b/client/src/routes/Root.tsx
@@ -1,9 +1,9 @@
import { useEffect, useState } from 'react';
import { Outlet } from 'react-router-dom';
-import { useRecoilValue, useSetRecoilState } from 'recoil';
+import { useSetRecoilState } from 'recoil';
import { useGetSearchEnabledQuery } from 'librechat-data-provider/react-query';
import type { ContextType } from '~/common';
-import { useAuthContext, useServerStream, useAssistantsMap, useFileMap } from '~/hooks';
+import { useAuthContext, useAssistantsMap, useFileMap } from '~/hooks';
import { AssistantsMapContext, FileMapContext } from '~/Providers';
import { Nav, MobileNav } from '~/components/Nav';
import store from '~/store';
@@ -15,9 +15,6 @@ export default function Root() {
return savedNavVisible !== null ? JSON.parse(savedNavVisible) : true;
});
- const submission = useRecoilValue(store.submission);
- useServerStream(submission ?? null);
-
const setIsSearchEnabled = useSetRecoilState(store.isSearchEnabled);
const fileMap = useFileMap({ isAuthenticated });
diff --git a/client/src/routes/useAuthRedirect.ts b/client/src/routes/useAuthRedirect.ts
index c6d4517e58..f4d2d8588d 100644
--- a/client/src/routes/useAuthRedirect.ts
+++ b/client/src/routes/useAuthRedirect.ts
@@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom';
import { useAuthContext } from '~/hooks';
export default function useAuthRedirect() {
- const { isAuthenticated } = useAuthContext();
+ const { user, isAuthenticated } = useAuthContext();
const navigate = useNavigate();
useEffect(() => {
@@ -19,6 +19,7 @@ export default function useAuthRedirect() {
}, [isAuthenticated, navigate]);
return {
+ user,
isAuthenticated,
};
}
diff --git a/client/src/store/families.ts b/client/src/store/families.ts
index 38d809eead..43bcd72ccf 100644
--- a/client/src/store/families.ts
+++ b/client/src/store/families.ts
@@ -6,8 +6,10 @@ import {
useRecoilValue,
useSetRecoilState,
} from 'recoil';
+import { LocalStorageKeys } from 'librechat-data-provider';
import type { TMessage, TPreset, TConversation, TSubmission } from 'librechat-data-provider';
import type { TOptionSettings, ExtendedFile } from '~/common';
+import { storeEndpointSettings } from '~/utils';
import { useEffect } from 'react';
const conversationByIndex = atomFamily<TConversation | null, string | number>({
@@ -15,11 +17,23 @@ const conversationByIndex = atomFamily<TConversation | null, string | number>({
default: null,
effects: [
({ onSet, node }) => {
- onSet(async (newValue: TConversation | null) => {
+ onSet(async (newValue) => {
const index = Number(node.key.split('__')[1]);
if (newValue?.assistant_id) {
- localStorage.setItem(`assistant_id__${index}`, newValue.assistant_id);
+ localStorage.setItem(`${LocalStorageKeys.ASST_ID_PREFIX}${index}`, newValue.assistant_id);
}
+ if (newValue?.spec) {
+ localStorage.setItem(LocalStorageKeys.LAST_SPEC, newValue.spec);
+ }
+ if (newValue?.tools && Array.isArray(newValue.tools)) {
+ localStorage.setItem(
+ LocalStorageKeys.LAST_TOOLS,
+ JSON.stringify(newValue.tools.filter((el) => !!el)),
+ );
+ }
+
+ storeEndpointSettings(newValue);
+ localStorage.setItem(LocalStorageKeys.LAST_CONVO_SETUP, JSON.stringify(newValue));
});
},
] as const,
diff --git a/client/src/store/user.ts b/client/src/store/user.ts
index d86bdc2373..ac771aea06 100644
--- a/client/src/store/user.ts
+++ b/client/src/store/user.ts
@@ -6,9 +6,9 @@ const user = atom<TUser | undefined>({
default: undefined,
});
-const availableTools = atom<TPlugin[]>({
+const availableTools = atom<Record<string, TPlugin>>({
key: 'availableTools',
- default: [],
+ default: {},
});
export default {
diff --git a/client/src/style.css b/client/src/style.css
index 18a979f201..c0f8fd4607 100644
--- a/client/src/style.css
+++ b/client/src/style.css
@@ -283,20 +283,6 @@ select {
display: none;
}
-.endpointOptionsPopover-container {
- pointer-events: none;
- opacity: 0;
- transition: all 0.2s ease-in-out;
- transform: scaleY(0);
- transform-origin: bottom center;
-}
-
-.endpointOptionsPopover-container.show {
- pointer-events: fill;
- opacity: 1;
- transform: scaleY(1)
-}
-
.creative-tab {
/* background: linear-gradient(90deg, #904887 10.79%, #8B257E 87.08%); */
background: linear-gradient(90deg, #904887 10.79%, #8B257E 87.08%);
diff --git a/client/src/utils/buildDefaultConvo.ts b/client/src/utils/buildDefaultConvo.ts
index 6332d6bd62..93edcbf8d2 100644
--- a/client/src/utils/buildDefaultConvo.ts
+++ b/client/src/utils/buildDefaultConvo.ts
@@ -1,6 +1,6 @@
-import { parseConvo } from 'librechat-data-provider';
+import { parseConvo, EModelEndpoint } from 'librechat-data-provider';
+import type { TConversation } from 'librechat-data-provider';
import getLocalStorageItems from './getLocalStorageItems';
-import type { TConversation, EModelEndpoint } from 'librechat-data-provider';
const buildDefaultConvo = ({
conversation,
@@ -29,7 +29,7 @@ const buildDefaultConvo = ({
const availableModels = models;
const model = lastConversationSetup?.model ?? lastSelectedModel?.[endpoint];
const secondaryModel =
- endpoint === 'gptPlugins'
+ endpoint === EModelEndpoint.gptPlugins
? lastConversationSetup?.agentOptions?.model ?? lastSelectedModel?.secondaryModel
: null;
@@ -64,7 +64,7 @@ const buildDefaultConvo = ({
endpoint,
};
- defaultConvo.tools = lastSelectedTools ?? defaultConvo.tools;
+ defaultConvo.tools = lastConversationSetup?.tools ?? lastSelectedTools ?? defaultConvo.tools;
defaultConvo.jailbreak = jailbreak ?? defaultConvo.jailbreak;
defaultConvo.toneStyle = toneStyle ?? defaultConvo.toneStyle;
diff --git a/client/src/utils/convos.ts b/client/src/utils/convos.ts
index 96299a33a2..e9f7ca75d6 100644
--- a/client/src/utils/convos.ts
+++ b/client/src/utils/convos.ts
@@ -1,13 +1,14 @@
import {
- parseISO,
+ format,
isToday,
- isWithinInterval,
subDays,
getYear,
+ parseISO,
startOfDay,
startOfYear,
- format,
+ isWithinInterval,
} from 'date-fns';
+import { EModelEndpoint, LocalStorageKeys } from 'librechat-data-provider';
import type {
TConversation,
ConversationData,
@@ -182,3 +183,29 @@ export const getConversationById = (
}
return undefined;
};
+
+export function storeEndpointSettings(conversation: TConversation | null) {
+ if (!conversation) {
+ return;
+ }
+ const { endpoint, model, agentOptions, jailbreak, toneStyle } = conversation;
+
+ if (!endpoint) {
+ return;
+ }
+
+ if (endpoint === EModelEndpoint.bingAI) {
+ const settings = { jailbreak, toneStyle };
+ localStorage.setItem(LocalStorageKeys.LAST_BING, JSON.stringify(settings));
+ return;
+ }
+
+ const lastModel = JSON.parse(localStorage.getItem(LocalStorageKeys.LAST_MODEL) || '{}');
+ lastModel[endpoint] = model;
+
+ if (endpoint === EModelEndpoint.gptPlugins) {
+ lastModel.secondaryModel = agentOptions?.model || model || '';
+ }
+
+ localStorage.setItem(LocalStorageKeys.LAST_MODEL, JSON.stringify(lastModel));
+}
diff --git a/client/src/utils/endpoints.ts b/client/src/utils/endpoints.ts
index 4815713760..cfbf1a0942 100644
--- a/client/src/utils/endpoints.ts
+++ b/client/src/utils/endpoints.ts
@@ -1,5 +1,16 @@
-import { defaultEndpoints } from 'librechat-data-provider';
-import type { EModelEndpoint, TEndpointsConfig, TConfig } from 'librechat-data-provider';
+import {
+ EModelEndpoint,
+ defaultEndpoints,
+ modularEndpoints,
+ LocalStorageKeys,
+} from 'librechat-data-provider';
+import type {
+ TConfig,
+ TPreset,
+ TModelSpec,
+ TConversation,
+ TEndpointsConfig,
+} from 'librechat-data-provider';
import type { LocalizeFunction } from '~/common';
export const getAssistantName = ({
@@ -48,6 +59,7 @@ export const getAvailableEndpoints = (
return availableEndpoints;
};
+/** Get the specified field from the endpoint config */
export function getEndpointField<K extends keyof TConfig>(
endpointsConfig: TEndpointsConfig | undefined,
endpoint: EModelEndpoint | string | null | undefined,
@@ -72,6 +84,9 @@ export function mapEndpoints(endpointsConfig: TEndpointsConfig) {
);
}
+/**
+ * Ensures the last selected model stays up to date, as conversation may
+ * update without updating last convo setup when same endpoint */
export function updateLastSelectedModel({
endpoint,
model,
@@ -82,12 +97,133 @@ export function updateLastSelectedModel({
if (!model) {
return;
}
- const lastConversationSetup = JSON.parse(localStorage.getItem('lastConversationSetup') || '{}');
- const lastSelectedModels = JSON.parse(localStorage.getItem('lastSelectedModel') || '{}');
+ const lastConversationSetup = JSON.parse(
+ localStorage.getItem(LocalStorageKeys.LAST_CONVO_SETUP) || '{}',
+ );
+
if (lastConversationSetup.endpoint === endpoint) {
lastConversationSetup.model = model;
- localStorage.setItem('lastConversationSetup', JSON.stringify(lastConversationSetup));
+ localStorage.setItem(LocalStorageKeys.LAST_CONVO_SETUP, JSON.stringify(lastConversationSetup));
}
+
+ const lastSelectedModels = JSON.parse(localStorage.getItem(LocalStorageKeys.LAST_MODEL) || '{}');
lastSelectedModels[endpoint] = model;
- localStorage.setItem('lastSelectedModel', JSON.stringify(lastSelectedModels));
+ localStorage.setItem(LocalStorageKeys.LAST_MODEL, JSON.stringify(lastSelectedModels));
+}
+
+interface ConversationInitParams {
+ conversation: TConversation | null;
+ newEndpoint: EModelEndpoint | string;
+ endpointsConfig: TEndpointsConfig;
+ modularChat?: boolean;
+}
+
+interface InitiatedTemplateResult {
+ template: Partial<TPreset>;
+ shouldSwitch: boolean;
+ isExistingConversation: boolean;
+ isCurrentModular: boolean;
+ isNewModular: boolean;
+ newEndpointType: EModelEndpoint | undefined;
+}
+
+/** Get the conditional logic for switching conversations */
+export function getConvoSwitchLogic(params: ConversationInitParams): InitiatedTemplateResult {
+ const { conversation, newEndpoint, endpointsConfig, modularChat } = params;
+
+ const currentEndpoint = conversation?.endpoint;
+ const template: Partial<TPreset> = {
+ ...conversation,
+ endpoint: newEndpoint,
+ conversationId: 'new',
+ };
+
+ const isAssistantSwitch =
+ newEndpoint === EModelEndpoint.assistants &&
+ currentEndpoint === EModelEndpoint.assistants &&
+ currentEndpoint === newEndpoint;
+
+ const conversationId = conversation?.conversationId;
+ const isExistingConversation = !!(conversationId && conversationId !== 'new');
+
+ const currentEndpointType =
+ getEndpointField(endpointsConfig, currentEndpoint, 'type') ?? currentEndpoint;
+ const newEndpointType =
+ getEndpointField(endpointsConfig, newEndpoint, 'type') ??
+ (newEndpoint as EModelEndpoint | undefined);
+
+ const hasEndpoint = modularEndpoints.has(currentEndpoint ?? '');
+ const hasCurrentEndpointType = modularEndpoints.has(currentEndpointType ?? '');
+ const isCurrentModular = hasEndpoint || hasCurrentEndpointType || isAssistantSwitch;
+
+ const hasNewEndpoint = modularEndpoints.has(newEndpoint ?? '');
+ const hasNewEndpointType = modularEndpoints.has(newEndpointType ?? '');
+ const isNewModular = hasNewEndpoint || hasNewEndpointType || isAssistantSwitch;
+
+ const endpointsMatch = currentEndpoint === newEndpoint;
+ const shouldSwitch = endpointsMatch || modularChat || isAssistantSwitch;
+
+ return {
+ template,
+ shouldSwitch,
+ isExistingConversation,
+ isCurrentModular,
+ newEndpointType,
+ isNewModular,
+ };
+}
+
+/** Gets the default spec by order.
+ *
+ * First, the admin defined default, then last selected spec, followed by first spec
+ */
+export function getDefaultModelSpec(modelSpecs?: TModelSpec[]) {
+ const defaultSpec = modelSpecs?.find((spec) => spec.default);
+ const lastSelectedSpecName = localStorage.getItem(LocalStorageKeys.LAST_SPEC);
+ const lastSelectedSpec = modelSpecs?.find((spec) => spec.name === lastSelectedSpecName);
+ return defaultSpec || lastSelectedSpec || modelSpecs?.[0];
+}
+
+/** Gets the default spec iconURL by order or definition.
+ *
+ * First, the admin defined default, then last selected spec, followed by first spec
+ */
+export function getModelSpecIconURL(modelSpec: TModelSpec) {
+ return modelSpec.iconURL ?? modelSpec.preset.iconURL ?? modelSpec.preset.endpoint ?? '';
+}
+
+/** Gets the default frontend-facing endpoint, dependent on iconURL definition.
+ *
+ * If the iconURL is defined in the endpoint config, use it, otherwise use the endpoint
+ */
+export function getIconEndpoint({
+ endpointsConfig,
+ iconURL,
+ endpoint,
+}: {
+ endpointsConfig: TEndpointsConfig | undefined;
+ iconURL: string | undefined;
+ endpoint: string | null | undefined;
+}) {
+ return (endpointsConfig?.[iconURL ?? ''] ? iconURL ?? endpoint : endpoint) ?? '';
+}
+
+/** Gets the key to use for the default endpoint iconURL, as defined by the custom config */
+export function getIconKey({
+ endpoint,
+ endpointType: _eType,
+ endpointsConfig,
+ endpointIconURL: iconURL,
+}: {
+ endpoint?: string | null;
+ endpointsConfig?: TEndpointsConfig | undefined;
+ endpointType?: string | null;
+ endpointIconURL?: string;
+}) {
+ const endpointType = _eType ?? getEndpointField(endpointsConfig, endpoint, 'type');
+ const endpointIconURL = iconURL ?? getEndpointField(endpointsConfig, endpoint, 'iconURL');
+ if (endpointIconURL && EModelEndpoint[endpointIconURL]) {
+ return endpointIconURL;
+ }
+ return endpointType ? 'unknown' : endpoint ?? 'unknown';
}
diff --git a/client/src/utils/getLocalStorageItems.ts b/client/src/utils/getLocalStorageItems.ts
index b93ebf7287..2c1a4d4964 100644
--- a/client/src/utils/getLocalStorageItems.ts
+++ b/client/src/utils/getLocalStorageItems.ts
@@ -1,9 +1,11 @@
+import { LocalStorageKeys } from 'librechat-data-provider';
+
export default function getLocalStorageItems() {
const items = {
- lastSelectedModel: localStorage.getItem('lastSelectedModel'),
- lastSelectedTools: localStorage.getItem('lastSelectedTools'),
- lastBingSettings: localStorage.getItem('lastBingSettings'),
- lastConversationSetup: localStorage.getItem('lastConversationSetup'),
+ lastSelectedModel: localStorage.getItem(LocalStorageKeys.LAST_MODEL),
+ lastSelectedTools: localStorage.getItem(LocalStorageKeys.LAST_TOOLS),
+ lastBingSettings: localStorage.getItem(LocalStorageKeys.LAST_BING),
+ lastConversationSetup: localStorage.getItem(LocalStorageKeys.LAST_CONVO_SETUP),
};
const lastSelectedModel = items.lastSelectedModel ? JSON.parse(items.lastSelectedModel) : {};
diff --git a/client/src/utils/map.ts b/client/src/utils/map.ts
index 0be5860a3b..e4708aa4b3 100644
--- a/client/src/utils/map.ts
+++ b/client/src/utils/map.ts
@@ -1,4 +1,5 @@
-import type { TFile, Assistant } from 'librechat-data-provider';
+import type { TFile, Assistant, TPlugin } from 'librechat-data-provider';
+import type { TPluginMap } from '~/common';
/** Maps Files by `file_id` for quick lookup */
export function mapFiles(files: TFile[]) {
@@ -21,3 +22,43 @@ export function mapAssistants(assistants: Assistant[]) {
return assistantMap;
}
+
+/** Maps Plugins by `pluginKey` for quick lookup */
+export function mapPlugins(plugins: TPlugin[]): TPluginMap {
+ return plugins.reduce((acc, plugin) => {
+ acc[plugin.pluginKey] = plugin;
+ return acc;
+ }, {} as TPluginMap);
+}
+
+/** Transform query data to object with list and map fields */
+export const selectPlugins = (
+ data: TPlugin[] | undefined,
+): {
+ list: TPlugin[];
+ map: TPluginMap;
+} => {
+ if (!data) {
+ return {
+ list: [],
+ map: {},
+ };
+ }
+
+ return {
+ list: data,
+ map: mapPlugins(data),
+ };
+};
+
+/** Transform array to TPlugin values */
+export function processPlugins(tools: (string | TPlugin)[], allPlugins?: TPluginMap): TPlugin[] {
+ return tools
+ .map((tool: string | TPlugin) => {
+ if (typeof tool === 'string') {
+ return allPlugins?.[tool];
+ }
+ return tool;
+ })
+ .filter((tool: TPlugin | undefined): tool is TPlugin => tool !== undefined);
+}
diff --git a/client/src/utils/presets.ts b/client/src/utils/presets.ts
index 45a7cd21fd..b63c1a99d8 100644
--- a/client/src/utils/presets.ts
+++ b/client/src/utils/presets.ts
@@ -1,4 +1,4 @@
-import type { TPreset } from 'librechat-data-provider';
+import type { TPreset, TPlugin } from 'librechat-data-provider';
import { EModelEndpoint } from 'librechat-data-provider';
export const getPresetIcon = (preset: TPreset, Icon) => {
@@ -53,3 +53,33 @@ export const getPresetTitle = (preset: TPreset) => {
return `${title}${modelInfo}${label ? ` (${label})` : ''}`.trim();
};
+
+/** Remove unavailable tools from the preset */
+export const removeUnavailableTools = (
+ preset: TPreset,
+ availableTools: Record<string, TPlugin>,
+) => {
+ const newPreset = { ...preset };
+
+ if (newPreset.tools && newPreset.tools.length > 0) {
+ newPreset.tools = newPreset.tools
+ .filter((tool) => {
+ let pluginKey: string;
+ if (typeof tool === 'string') {
+ pluginKey = tool;
+ } else {
+ ({ pluginKey } = tool);
+ }
+
+ return !!availableTools[pluginKey];
+ })
+ .map((tool) => {
+ if (typeof tool === 'string') {
+ return tool;
+ }
+ return tool.pluginKey;
+ });
+ }
+
+ return newPreset;
+};
diff --git a/docs/install/configuration/azure_openai.md b/docs/install/configuration/azure_openai.md
index 3dcd3f1e64..5c74beff18 100644
--- a/docs/install/configuration/azure_openai.md
+++ b/docs/install/configuration/azure_openai.md
@@ -1,7 +1,7 @@
---
title: 🅰️ Azure OpenAI
description: Comprehensive guide for configuring Azure OpenAI through the `librechat.yaml` file AKA the LibreChat Config file. This document is your one-stop resource for understanding and customizing Azure settings and models.
-weight: -10
+weight: -9
---
# Azure OpenAI
diff --git a/docs/install/configuration/config_changelog.md b/docs/install/configuration/config_changelog.md
new file mode 100644
index 0000000000..8b8171c89c
--- /dev/null
+++ b/docs/install/configuration/config_changelog.md
@@ -0,0 +1,87 @@
+---
+title: 🖥️ Config Changelog
+description: Changelog for the custom configuration file
+weight: -10
+---
+
+# 🖥️ Config Changelog
+
+## v1.0.8
+
+- Added additional fields to [interface config](./custom_config.md#interface-object-structure) to toggle access to specific features:
+ - `endpointsMenu`, `modelSelect`, `parameters`, `sidePanel`, `presets`
+- Now ensures the following fields always have defaults set:
+ - `cache`, `imageOutputType`, `fileStrategy`, `registration`
+- Added [`modelSpecs`](./custom_config.md#model-specs-object-structure) for a configurable UI experience, simplifying model selection with specific presets and tools.
+- Added [`filteredTools`](./custom_config.md#filteredtools) to disable specific plugins/tools without any changes to the codebase
+ - Affects both `gptPlugins` and `assistants` endpoints
+- [`iconURL`](./custom_config.md#iconurl) can now be to set to one of the main endpoints to use existing project icons
+ - "openAI" | "azureOpenAI" | "google" | "anthropic" | "assistants" | "gptPlugins"
+- Invalid YAML format is now logged for easier debugging
+
+## v1.0.7
+
+- Removed `stop` from OpenAI/custom endpoint default parameters
+- Added `current_model` option for [`titleModel`](./custom_config.md#titlemodel) and [`summaryModel`](./custom_config.md#summarymodel) endpoint settings in order to use the active conversation's model for those methods.
+
+## v1.0.6
+
+- Added [`imageOutputType`](./custom_config.md#imageoutputtype) field to specify the output type for image generation.
+- Added [`secureImageLinks`](./custom_config.md#secureimagelinks) to optionally lock down access to generated images.
+
+## v1.0.5
+
+- Added [Azure OpenAI Assistants configuration](./custom_config.md#assistants) settings
+- Added initial [interface settings](./custom_config.md#interface-object-structure) (privacy policy & terms of service)
+- Added the following fields to the [Azure Group Config](./custom_config.md#group-object-structure):
+ - `serverless`, `addParams`, `dropParams`, `forcePrompt`
+
+## v1.0.4
+
+- Added initial [Azure OpenAI configuration](./custom_config.md#azure-openai-object-structure) settings
+
+## v1.0.3
+
+- Added [OpenAI Assistants configuration](./custom_config.md#assistants-endpoint-object-structure) settings
+- Added the following fields to custom endpoint settings:
+ - [`addParams`](./custom_config.md#addparams), [`dropParams`](./custom_config.md#dropparams)
+- Added [Rate Limit Configuration](./custom_config.md#ratelimits) settings
+- Added [File Configuration](./custom_config.md#fileconfig) settings
+
+## v1.0.2
+- Added `userIdQuery` to custom endpoint [models](./custom_config.md#models) settings
+- Added [Registration Configuration](./custom_config.md#registration) settings
+- Added [`headers`](./custom_config.md#headers) to custom endpoint settings
+
+## v1.0.1
+- Added [`fileStrategy`](./custom_config.md#filestrategy) to custom config
+
+## v1.0.0
+
+This initial release introduces a robust configuration schema using Zod for validation, designed to manage API endpoints and associated settings in a structured and type-safe manner.
+
+Features:
+
+1. **Endpoint Configuration Schema (`endpointSchema`)**:
+ - **Name Validation**: Ensures that the endpoint name is not one of the default `EModelEndpoint` values.
+ - **API Key**: Requires a string value for API key identification.
+ - **Base URL**: Requires a string value for the base URL of the endpoint.
+ - **Models Configuration**:
+ - **Default Models**: Requires an array of strings with at least one model specified.
+ - **Fetch Option**: Optional boolean to enable model fetching.
+ - **Additional Optional Settings**:
+ - **Title Convo**: Optional boolean to toggle conversation titles.
+ - **Title Method**: Optional choice between 'completion' and 'functions' methods.
+ - **Title Model**: Optional string for model specification in titles.
+ - **Summarize**: Optional boolean for enabling summary features.
+ - **Summary Model**: Optional string specifying the model used for summaries.
+ - **Force Prompt**: Optional boolean to force prompt inclusion.
+ - **Model Display Label**: Optional string for labeling the model in UI displays.
+
+2. **Main Configuration Schema (`configSchema`)**:
+ - **Version**: String to specify the config schema version.
+ - **Cache**: Boolean to toggle caching mechanisms.
+ - **Endpoints**:
+ - **Custom Endpoints**: Array of partially applied `endpointSchema` to allow custom endpoint configurations.
+ - Ensures strict object structure without additional properties.
+
diff --git a/docs/install/configuration/custom_config.md b/docs/install/configuration/custom_config.md
index caf1d24bdb..3a46b898ff 100644
--- a/docs/install/configuration/custom_config.md
+++ b/docs/install/configuration/custom_config.md
@@ -14,7 +14,7 @@ This file enables the integration of custom AI endpoints, enabling you to connec
This includes providers like [Mistral AI](https://docs.mistral.ai/platform/client/), as well as reverse proxies that facilitate access to OpenAI servers, adding them alongside existing endpoints like Anthropic.
-![image](https://github.com/danny-avila/LibreChat/assets/110412045/fd0d2307-008f-4e1d-b75b-4f141070ce71)
+**[INSERT UPDATED IMAGE HERE]**
Future updates will streamline configuration further by migrating some settings from [your `.env` file](./dotenv.md) to `librechat.yaml`.
@@ -49,268 +49,371 @@ For Docker, you need to make use of an [override file](./docker_override.md), na
- First, make sure your containers stop running with `docker compose down`
- Create or edit existing `docker-compose.override.yml` at the root of the project:
-```yaml
-# For more details on the override file, see the Docker Override Guide:
-# https://docs.librechat.ai/install/configuration/docker_override.html
+!!! tip "docker-compose.override.yml"
-version: '3.4'
+ ```yaml
+ # For more details on the override file, see the Docker Override Guide:
+ # https://docs.librechat.ai/install/configuration/docker_override.html
-services:
- api:
- volumes:
- - ./librechat.yaml:/app/librechat.yaml # local/filepath:container/filepath
-```
+ version: '3.4'
+
+ services:
+ api:
+ volumes:
+ - ./librechat.yaml:/app/librechat.yaml # local/filepath:container/filepath
+ ```
- **Note:** If you are using `CONFIG_PATH` for an alternative filepath for this file, make sure to specify it accordingly.
- Start docker again, and you should see your config file settings apply
```bash
-docker compose up # no need to rebuild
+# no need to rebuild
+docker compose up
```
## Example Config
-```yaml
-version: 1.0.5
-cache: true
-# fileStrategy: "firebase" # If using Firebase CDN
-fileConfig:
- endpoints:
- assistants:
- fileLimit: 5
- # Maximum size for an individual file in MB
- fileSizeLimit: 10
- # Maximum total size for all files in a single request in MB
- totalSizeLimit: 50
- # In case you wish to limit certain filetypes
- # supportedMimeTypes:
- # - "image/.*"
- # - "application/pdf"
- openAI:
- # Disables file uploading to the OpenAI endpoint
- disabled: true
- default:
- totalSizeLimit: 20
- # Example for custom endpoints
- # YourCustomEndpointName:
- # fileLimit: 2
- # fileSizeLimit: 5
- # Global server file size limit in MB
- serverFileSizeLimit: 100
- # Limit for user avatar image size in MB, default: 2 MB
- avatarSizeLimit: 4
-rateLimits:
- fileUploads:
- ipMax: 100
- # Rate limit window for file uploads per IP
- ipWindowInMinutes: 60
- userMax: 50
- # Rate limit window for file uploads per user
- userWindowInMinutes: 60
-registration:
- socialLogins: ["google", "facebook", "github", "discord", "openid"]
- allowedDomains:
- - "example.com"
- - "anotherdomain.com"
-endpoints:
- assistants:
- # Disable Assistants Builder Interface by setting to `true`
- disableBuilder: false
- # Polling interval for checking assistant updates
- pollIntervalMs: 750
- # Timeout for assistant operations
- timeoutMs: 180000
- # Should only be one or the other, either `supportedIds` or `excludedIds`
- supportedIds: ["asst_supportedAssistantId1", "asst_supportedAssistantId2"]
- # excludedIds: ["asst_excludedAssistantId"]
- # (optional) Models that support retrieval, will default to latest known OpenAI models that support the feature
- # retrievalModels: ["gpt-4-turbo-preview"]
- # (optional) Assistant Capabilities available to all users. Omit the ones you wish to exclude. Defaults to list below.
- # capabilities: ["code_interpreter", "retrieval", "actions", "tools", "image_vision"]
- custom:
- - name: "Mistral"
- apiKey: "${MISTRAL_API_KEY}"
- baseURL: "https://api.mistral.ai/v1"
- models:
- default: ["mistral-tiny", "mistral-small", "mistral-medium", "mistral-large-latest"]
- # Attempt to dynamically fetch available models
- fetch: true
- userIdQuery: false
- iconURL: "https://example.com/mistral-icon.png"
- titleConvo: true
- titleModel: "mistral-tiny"
- modelDisplayLabel: "Mistral AI"
- # addParams:
- # Mistral API specific value for moderating messages
- # safe_prompt: true
- dropParams:
- - "stop"
- - "user"
- - "presence_penalty"
- - "frequency_penalty"
- # headers:
- # x-custom-header: "${CUSTOM_HEADER_VALUE}"
- - name: "OpenRouter"
- apiKey: "${OPENROUTER_API_KEY}"
- baseURL: "https://openrouter.ai/api/v1"
- models:
- default: ["gpt-3.5-turbo"]
- fetch: false
- titleConvo: true
- titleModel: "gpt-3.5-turbo"
- modelDisplayLabel: "OpenRouter"
- dropParams:
- - "stop"
- - "frequency_penalty"
-```
+??? tip "Click here to expand/collapse example"
-This example configuration file sets up LibreChat with detailed options across several key areas:
-
-- **Caching**: Enabled to improve performance.
-- **File Handling**:
- - **File Strategy**: Commented out but hints at possible integration with Firebase for file storage.
- - **File Configurations**: Customizes file upload limits and allowed MIME types for different endpoints, including a global server file size limit and a specific limit for user avatar images.
-- **Rate Limiting**: Defines thresholds for the maximum number of file uploads allowed per IP and user within a specified time window, aiming to prevent abuse.
-- **Registration**:
- - Allows registration from specified social login providers and email domains, enhancing security and user management.
-- **Endpoints**:
- - **Assistants**: Configures the assistants' endpoint with a polling interval and a timeout for operations, and provides an option to disable the builder interface.
- - **Custom Endpoints**:
- - Configures two external AI service endpoints, Mistral and OpenRouter, including API keys, base URLs, model handling, and specific feature toggles like conversation titles, summarization, and parameter adjustments.
- - For Mistral, it enables dynamic model fetching, applies additional parameters for safe prompts, and explicitly drops unsupported parameters.
- - For OpenRouter, it sets up a basic configuration without dynamic model fetching and specifies a model for conversation titles.
+ ```yaml
+ version: 1.0.5
+ cache: true
+ # fileStrategy: "firebase" # If using Firebase CDN
+ fileConfig:
+ endpoints:
+ assistants:
+ fileLimit: 5
+ # Maximum size for an individual file in MB
+ fileSizeLimit: 10
+ # Maximum total size for all files in a single request in MB
+ totalSizeLimit: 50
+ # In case you wish to limit certain filetypes
+ # supportedMimeTypes:
+ # - "image/.*"
+ # - "application/pdf"
+ openAI:
+ # Disables file uploading to the OpenAI endpoint
+ disabled: true
+ default:
+ totalSizeLimit: 20
+ # Example for custom endpoints
+ # YourCustomEndpointName:
+ # fileLimit: 2
+ # fileSizeLimit: 5
+ # Global server file size limit in MB
+ serverFileSizeLimit: 100
+ # Limit for user avatar image size in MB, default: 2 MB
+ avatarSizeLimit: 4
+ rateLimits:
+ fileUploads:
+ ipMax: 100
+ # Rate limit window for file uploads per IP
+ ipWindowInMinutes: 60
+ userMax: 50
+ # Rate limit window for file uploads per user
+ userWindowInMinutes: 60
+ registration:
+ socialLogins: ["google", "facebook", "github", "discord", "openid"]
+ allowedDomains:
+ - "example.com"
+ - "anotherdomain.com"
+ endpoints:
+ assistants:
+ # Disable Assistants Builder Interface by setting to `true`
+ disableBuilder: false
+ # Polling interval for checking assistant updates
+ pollIntervalMs: 750
+ # Timeout for assistant operations
+ timeoutMs: 180000
+ # Should only be one or the other, either `supportedIds` or `excludedIds`
+ supportedIds: ["asst_supportedAssistantId1", "asst_supportedAssistantId2"]
+ # excludedIds: ["asst_excludedAssistantId"]
+ # (optional) Models that support retrieval, will default to latest known OpenAI models that support the feature
+ # retrievalModels: ["gpt-4-turbo-preview"]
+ # (optional) Assistant Capabilities available to all users. Omit the ones you wish to exclude. Defaults to list below.
+ # capabilities: ["code_interpreter", "retrieval", "actions", "tools", "image_vision"]
+ custom:
+ - name: "Mistral"
+ apiKey: "${MISTRAL_API_KEY}"
+ baseURL: "https://api.mistral.ai/v1"
+ models:
+ default: ["mistral-tiny", "mistral-small", "mistral-medium", "mistral-large-latest"]
+ # Attempt to dynamically fetch available models
+ fetch: true
+ userIdQuery: false
+ iconURL: "https://example.com/mistral-icon.png"
+ titleConvo: true
+ titleModel: "mistral-tiny"
+ modelDisplayLabel: "Mistral AI"
+ # addParams:
+ # Mistral API specific value for moderating messages
+ # safe_prompt: true
+ dropParams:
+ - "stop"
+ - "user"
+ - "presence_penalty"
+ - "frequency_penalty"
+ # headers:
+ # x-custom-header: "${CUSTOM_HEADER_VALUE}"
+ - name: "OpenRouter"
+ apiKey: "${OPENROUTER_API_KEY}"
+ baseURL: "https://openrouter.ai/api/v1"
+ models:
+ default: ["gpt-3.5-turbo"]
+ fetch: false
+ titleConvo: true
+ titleModel: "gpt-3.5-turbo"
+ modelDisplayLabel: "OpenRouter"
+ dropParams:
+ - "stop"
+ - "frequency_penalty"
+ ```
+
+ This example configuration file sets up LibreChat with detailed options across several key areas:
+
+ - **Caching**: Enabled to improve performance.
+ - **File Handling**:
+ - **File Strategy**: Commented out but hints at possible integration with Firebase for file storage.
+ - **File Configurations**: Customizes file upload limits and allowed MIME types for different endpoints, including a global server file size limit and a specific limit for user avatar images.
+ - **Rate Limiting**: Defines thresholds for the maximum number of file uploads allowed per IP and user within a specified time window, aiming to prevent abuse.
+ - **Registration**:
+ - Allows registration from specified social login providers and email domains, enhancing security and user management.
+ - **Endpoints**:
+ - **Assistants**: Configures the assistants' endpoint with a polling interval and a timeout for operations, and provides an option to disable the builder interface.
+ - **Custom Endpoints**:
+ - Configures two external AI service endpoints, Mistral and OpenRouter, including API keys, base URLs, model handling, and specific feature toggles like conversation titles, summarization, and parameter adjustments.
+ - For Mistral, it enables dynamic model fetching, applies additional parameters for safe prompts, and explicitly drops unsupported parameters.
+ - For OpenRouter, it sets up a basic configuration without dynamic model fetching and specifies a model for conversation titles.
## Config Structure
**Note:** Fields not specifically mentioned as required are optional.
-### Version
-- **Key**: `version`
-- **Type**: String
-- **Description**: Specifies the version of the configuration file.
-- **Example**: `version: 1.0.5`
-- **Required**
-
-### Cache Settings
-- **Key**: `cache`
-- **Type**: Boolean
-- **Description**: Toggles caching on or off. Set to `true` to enable caching.
-- **Example**: `cache: true`
-
-### File Strategy
-- **Key**: `fileStrategy`
-- **Type**: String = "local" | ["firebase"](../../features/firebase.md)
-- **Description**: Determines where to save user uploaded/generated files. Defaults to `"local"` if omitted.
-- **Example**: `fileStrategy: "firebase"`
-
-### Image Links
-- **Key**: `secureImageLinks`
-- **Type**: Boolean
-- **Description**: Whether or not to secure access to image links that are hosted locally by the app. Default: false.
-- **Example**: `secureImageLinks: true`
-
-### Image Output Type
-- **Key**: `imageOutputType`
-- **Type**: String, "png" | "webp" | "jpeg"
-- **Description**: The image output type for image responses. Defaults to "png" if omitted.
-- **Note**: Case-sensitive. Google endpoint only supports "jpeg" and "png" output types.
-- **Example**: `imageOutputType: "webp"`
-
-### File Configuration
-- **Key**: `fileConfig`
-- **Type**: Object
-- **Description**: Configures file handling settings for the application, including size limits and MIME type restrictions.
-
- - **Sub-Key**: `endpoints`
- - **Type**: Record/Object
- - **Description**: Specifies file handling configurations for individual endpoints, allowing customization per endpoint basis.
- - [Endpoint File Config Object Structure](#endpoint-file-config-object-structure)
-
- - **Sub-Key**: `serverFileSizeLimit`
- - **Type**: Number
- - **Description**: The maximum file size (in MB) that the server will accept. Applies globally across all endpoints unless overridden by endpoint-specific settings.
-
- - **Sub-Key**: `avatarSizeLimit`
- - **Type**: Number
- - **Description**: Maximum size (in MB) for user avatar images.
-
-### Rate Limiting
-
-- **Key**: `rateLimits`
-- **Type**: Object
-- **Description**: Defines rate limiting policies to prevent abuse by limiting the number of requests.
- - **Sub-Key**: `fileUploads`
- - **Type**: Object
- - **Description**: Configures rate limits specifically for file upload operations.
- - **Sub-Key**: `ipMax`
- - **Type**: Number
- - **Description**: Maximum number of uploads allowed per IP address per window.
- - **Sub-Key**: `ipWindowInMinutes`
- - **Type**: Number
- - **Description**: Time window in minutes for the IP-based upload limit.
- - **Sub-Key**: `userMax`
- - **Type**: Number
- - **Description**: Maximum number of uploads allowed per user per window.
- - **Sub-Key**: `userWindowInMinutes`
- - **Type**: Number
- - **Description**: Time window in minutes for the user-based upload limit.
-
-- **Example**:
-```yaml
-rateLimits:
- fileUploads:
- ipMax: 100
- ipWindowInMinutes: 60
- userMax: 50
- userWindowInMinutes: 60
-```
+### version
+!!! tip "version"
+ - **Key**: `version`
+
+ - **Type**: String
+ - **Description**: Specifies the version of the configuration file.
+ - **Example**: `version: 1.0.5`
+ - **Required**
+
+### cache
+!!! tip "cache"
+ - **Key**: `cache`
+
+ - **Type**: Boolean
+ - **Description**: Toggles caching on or off. Set to `true` to enable caching (default).
+ - **Example**: `cache: true`
+
+### fileStrategy
+!!! tip "fileStrategy"
+ - **Key**: `fileStrategy`
+ - **Type**: String
+ - **Options**: "local" | ["firebase"](../../features/firebase.md)
+ - **Description**: Determines where to save user uploaded/generated files. Defaults to `"local"` if omitted.
+ - **Example**: `fileStrategy: "firebase"`
+
+### filteredTools
+!!! tip "filteredTools"
+ - **Key**: `filteredTools`
+ - Type: Array of Strings
+ - Example:
+ ```yaml
+ filteredTools: ["scholarai", "calculator"]
+ ```
+ - **Description**: Filters out specific tools from both Plugins and OpenAI Assistants endpoints
+ - **Notes**:
+ - Affects both `gptPlugins` and `assistants` endpoints
+ - You can find the names of the tools to filter in [`api/app/clients/tools/manifest.json`](https://github.com/danny-avila/LibreChat/blob/main/api/app/clients/tools/manifest.json)
+ - Use the `pluginKey` value
+ - Also, any listed under the ".well-known" directory [`api/app/clients/tools/.well-known`](https://github.com/danny-avila/LibreChat/blob/main/api/app/clients/tools/.well-known)
+ - Use the `name_for_model` value
+
+### secureImageLinks
+!!! tip "secureImageLinks"
+ - **Key**: `secureImageLinks`
+ - **Type**: Boolean
+ - **Description**: Whether or not to secure access to image links that are hosted locally by the app. Default: false.
+ - **Example**: `secureImageLinks: true`
+
+### imageOutputType
+!!! tip "imageOutputType"
+ - **Key**: `imageOutputType`
+ - **Type**: String
+ - **Options**: "png" | "webp" | "jpeg"
+ - **Description**: The image output type for image responses. Defaults to "png" if omitted.
+ - **Note**: Case-sensitive. Google endpoint only supports "jpeg" and "png" output types.
+ - **Example**: `imageOutputType: "webp"`
+
+### fileConfig
+!!! tip "fileConfig"
+
+ - **Key**: `fileConfig`
+
+ - **Type**: Object
+ - **Description**: Configures file handling settings for the application, including size limits and MIME type restrictions.
+ - <u>**Sub-keys:**</u>
+ - `endpoints`
+ - **Type**: Record/Object
+ - **Description**: Specifies file handling configurations for individual endpoints, allowing customization per endpoint basis.
+
+ - `serverFileSizeLimit`
+ - **Type**: Number
+ - **Description**: The maximum file size (in MB) that the server will accept. Applies globally across all endpoints unless overridden by endpoint-specific settings.
+
+ - `avatarSizeLimit`
+ - **Type**: Number
+ - **Description**: Maximum size (in MB) for user avatar images.
+
+ - [File Config Object Structure](#file-config-object-structure)
+
+### rateLimits
+!!! tip "rateLimits"
+
+ - **Key**: `rateLimits`
+ - **Type**: Object
+ - **Description**: Defines rate limiting policies to prevent abuse by limiting the number of requests.
+ - <u>**Sub-keys:**</u>
+ - `fileUploads`
+ - **Type**: Object
+ - **Description**: Configures rate limits specifically for file upload operations.
+ - **Sub-keys:**
+ - `ipMax`
+ - **Type**: Number
+ - **Description**: Maximum number of uploads allowed per IP address per window.
+ - `ipWindowInMinutes`
+ - **Type**: Number
+ - **Description**: Time window in minutes for the IP-based upload limit.
+ - `userMax`
+ - **Type**: Number
+ - **Description**: Maximum number of uploads allowed per user per window.
+ - `userWindowInMinutes`
+ - **Type**: Number
+ - **Description**: Time window in minutes for the user-based upload limit.
+
+ - **Example**:
+ ```yaml
+ rateLimits:
+ fileUploads:
+ ipMax: 100
+ ipWindowInMinutes: 60
+ userMax: 50
+ userWindowInMinutes: 60
+ ```
-### Registration
-- **Key**: `registration`
-- **Type**: Object
-- **Description**: Configures registration-related settings for the application.
- - **Sub-Key**: `socialLogins`
- - [More info](#socialLogins)
- - **Sub-Key**: `allowedDomains`
- - [More info](#allowedDomains)
-- [Registration Object Structure](#registration-object-structure)
-
-### Endpoints
-- **Key**: `endpoints`
-- **Type**: Object
-- **Description**: Defines custom API endpoints for the application.
- - **Sub-Key**: `custom`
- - **Type**: Array of Objects
- - **Description**: Each object in the array represents a unique endpoint configuration.
- - [Full Custom Endpoint Object Structure](#custom-endpoint-object-structure)
- - **Sub-Key**: `azureOpenAI`
- - **Type**: Object
- - **Description**: Azure OpenAI endpoint-specific configuration
- - [Full Azure OpenAI Endpoint Object Structure](#azure-openai-object-structure)
- - **Sub-Key**: `assistants`
- - **Type**: Object
- - **Description**: Assistants endpoint-specific configuration.
- - [Full Assistants Endpoint Object Structure](#assistants-endpoint-object-structure)
-
-## Endpoint File Config Object Structure
+### registration
+!!! tip "registration"
+ - **Key**: `registration`
+ - **Type**: Object
+ - **Description**: Configures registration-related settings for the application.
+ - <u>**Sub-keys:**</u>
+ - `socialLogins`: [More info](#socialLogins)
+ - `allowedDomains`: [More info](#allowedDomains)
+ - [Registration Object Structure](#registration-object-structure)
+
+### interface
+!!! tip "interface"
+
+ - **Key**: `interface`
+
+ - **Type**: Object
+ - **Description**: Configures user interface elements within the application, allowing for customization of visibility and behavior of various components.
+ - <u>**Sub-keys:**</u>
+ - `privacyPolicy`
+ - **Type**: Object
+ - **Description**: Contains settings related to the privacy policy link provided in the user interface.
+
+ - `termsOfService`
+ - **Type**: Object
+ - **Description**: Contains settings related to the terms of service link provided in the user interface.
+
+ - `endpointsMenu`
+ - **Type**: Boolean
+ - **Description**: Controls the visibility of the endpoints dropdown menu in the interface.
+
+ - `modelSelect`
+ - **Type**: Boolean
+ - **Description**: Determines whether the model selection feature is available in the UI.
+ - **Note**: Also disables the model and assistants selection dropdown from the right-most side panel.
+
+ - `parameters`
+ - **Type**: Boolean
+ - **Description**: Toggles the visibility of parameter configuration options AKA conversation settings.
+
+ - `sidePanel`
+ - **Type**: Boolean
+ - **Description**: Controls the visibility of the right-most side panel in the application's interface.
+
+ - `presets`
+ - **Type**: Boolean
+ - **Description**: Enables or disables the presets menu in the application's UI.
+
+ - [Interface Object Structure](#interface-object-structure)
+
+### modelSpecs
+!!! tip "modelSpecs"
+
+ - **Key**: `modelSpecs`
+
+ - **Type**: Object
+ - **Description**: Configures model specifications, allowing for detailed setup and customization of AI models and their behaviors within the application.
+ - <u>**Sub-keys:**</u>
+ - `enforce`
+ - **Type**: Boolean
+ - **Description**: Determines whether the model specifications should strictly override other configuration settings.
+
+ - `prioritize`
+ - **Type**: Boolean
+ - **Description**: Specifies if model specifications should take priority over the default configuration when both are applicable.
+
+ - `list`
+ - **Type**: Array of Objects
+ - **Description**: Contains a list of individual model specifications detailing various configurations and behaviors.
+
+ - [Model Specs Object Structure](#model-specs-object-structure)
+
+### endpoints
+!!! tip "endpoints"
+ - **Key**: `endpoints`
+ - **Type**: Object
+ - **Description**: Defines custom API endpoints for the application.
+ - <u>**Sub-keys:**</u>
+ - `custom`
+ - **Type**: Array of Objects
+ - **Description**: Each object in the array represents a unique endpoint configuration.
+ - [Full Custom Endpoint Object Structure](#custom-endpoint-object-structure)
+ - `azureOpenAI`
+ - **Type**: Object
+ - **Description**: Azure OpenAI endpoint-specific configuration
+ - [Full Azure OpenAI Endpoint Object Structure](#azure-openai-object-structure)
+ - `assistants`
+ - **Type**: Object
+ - **Description**: Assistants endpoint-specific configuration.
+ - [Full Assistants Endpoint Object Structure](#assistants-endpoint-object-structure)
+
+## File Config Object Structure
### **Overview**
- - `disabled`: Whether file handling is disabled for the endpoint.
- - `fileLimit`: The maximum number of files allowed per upload request.
- - `fileSizeLimit`: The maximum size for a single file. In units of MB (e.g. use `20` for 20 megabytes)
- - `totalSizeLimit`: The total maximum size for all files in a single request. In units of MB (e.g. use `20` for 20 megabytes)
- - `supportedMimeTypes`: A list of [Regular Expressions](https://en.wikipedia.org/wiki/Regular_expression) specifying what MIME types are allowed for upload. This can be customized to restrict file types.
+The `fileConfig` object allows you to configure file handling settings for the application, including size limits and MIME type restrictions. This section provides a detailed breakdown of the `fileConfig` object structure.
+
+There are 3 main fields under `fileConfig`:
+
+ - `endpoints`
+ - `serverFileSizeLimit`
+ - `avatarSizeLimit`
**Notes:**
- At the time of writing, the Assistants endpoint [supports filetypes from this list](https://platform.openai.com/docs/assistants/tools/supported-files).
-- The OpenAI, Azure OpenAI, Google, and Custom endpoints only suppport images.
+- OpenAI, Azure OpenAI, Google, and Custom endpoints support files through the [RAG API.](../../features/rag_api.md)
- Any other endpoints not mentioned, like Plugins, do not support file uploads (yet).
- The Assistants endpoint has a defined endpoint value of `assistants`. All other endpoints use the defined value `default`
- For non-assistants endpoints, you can adjust file settings for all of them under `default`
- If you'd like to adjust settings for a specific endpoint, you can list their corresponding endpoint names:
- - `assistants` (does not use `default` as it has defined defaults separate from the others.)
+ - `assistants`
+ - does not use "default" as it has defined defaults separate from the others.
- `openAI`
- `azureOpenAI`
- `google`
@@ -320,462 +423,929 @@ rateLimits:
### Example
-```yaml
-fileConfig:
- endpoints:
- assistants:
- fileLimit: 5
- fileSizeLimit: 10
- totalSizeLimit: 50
- supportedMimeTypes:
- - "image/.*"
- - "application/pdf"
- openAI:
- disabled: true
- default:
- totalSizeLimit: 20
- YourCustomEndpointName:
- fileLimit: 5
- fileSizeLimit: 1000
- supportedMimeTypes:
- - "image/.*"
- serverFileSizeLimit: 1000
- avatarSizeLimit: 2
-```
+??? tip "Click here to expand/collapse example"
+ ```yaml
+ fileConfig:
+ endpoints:
+ assistants:
+ fileLimit: 5
+ fileSizeLimit: 10
+ totalSizeLimit: 50
+ supportedMimeTypes:
+ - "image/.*"
+ - "application/pdf"
+ openAI:
+ disabled: true
+ default:
+ totalSizeLimit: 20
+ YourCustomEndpointName:
+ fileLimit: 5
+ fileSizeLimit: 1000
+ supportedMimeTypes:
+ - "image/.*"
+ serverFileSizeLimit: 1000
+ avatarSizeLimit: 2
+ ```
-### **disabled**:
-
-> Indicates whether file uploading is disabled for a specific endpoint.
-
-- Type: Boolean
-- Default: `false` (i.e., uploading is enabled by default)
-- Example:
- ```yaml
- openAI:
- disabled: true
- ```
-- **Note**: Setting this to `true` prevents any file uploads to the specified endpoint, overriding any other file-related settings.
-
-### **fileLimit**:
-
-> The maximum number of files allowed in a single upload request.
-
-- Type: Integer
-- Default: Varies by endpoint
-- Example:
- ```yaml
- assistants:
- fileLimit: 5
- ```
-- **Note**: Helps control the volume of uploads and manage server load.
-
-### **fileSizeLimit**:
-
-> The maximum size allowed for each individual file, specified in megabytes (MB).
-
-- Type: Integer
-- Default: Varies by endpoint
-- Example:
- ```yaml
- YourCustomEndpointName:
- fileSizeLimit: 1000
- ```
-- **Note**: This limit ensures that no single file exceeds the specified size, allowing for better resource allocation and management.
-
-### **totalSizeLimit**:
-
-> The total maximum size allowed for all files in a single request, specified in megabytes (MB).
-
-- Type: Integer
-- Default: Varies by endpoint
-- Example:
- ```yaml
- assistants:
- totalSizeLimit: 50
- ```
-- **Note**: This setting is crucial for preventing excessive bandwidth and storage usage by any single upload request.
-
-### **supportedMimeTypes**:
-
-> A list of regular expressions defining the MIME types permitted for upload.
-
-- Type: Array of Strings
-- Default: Varies by endpoint
-- Example:
- ```yaml
- assistants:
- supportedMimeTypes:
- - "image/.*"
- - "application/pdf"
- ```
-- **Note**: This allows for precise control over the types of files that can be uploaded. Invalid regex is ignored.
-
-### **serverFileSizeLimit**:
-
-> The global maximum size for any file uploaded to the server, specified in megabytes (MB).
-
-- Type: Integer
-- Example:
- ```yaml
- fileConfig:
- serverFileSizeLimit: 1000
- ```
-- **Note**: Acts as an overarching limit for file uploads across all endpoints, ensuring that no file exceeds this size server-wide.
-
-### **avatarSizeLimit**:
-
-> The maximum size allowed for avatar images, specified in megabytes (MB).
-
-- Type: Integer
-- Example:
- ```yaml
- fileConfig:
- avatarSizeLimit: 2
- ```
-- **Note**: Specifically tailored for user avatar uploads, allowing for control over image sizes to maintain consistent quality and loading times.
+### **serverFileSizeLimit**
-## Registration Object Structure
+!!! tip "fileConfig / serverFileSizeLimit"
-```yaml
-# Example Registration Object Structure
-registration:
- socialLogins: ["google", "facebook", "github", "discord", "openid"]
- allowedDomains:
- - "gmail.com"
- - "protonmail.com"
-```
+ > The global maximum size for any file uploaded to the server, specified in megabytes (MB).
+
+ - Type: Integer
+ - Example:
+ ```yaml
+ fileConfig:
+ serverFileSizeLimit: 1000
+ ```
+ - **Note**: Acts as an overarching limit for file uploads across all endpoints, ensuring that no file exceeds this size server-wide.
+
+### **avatarSizeLimit**
+
+!!! tip "fileConfig / avatarSizeLimit"
+
+ > The maximum size allowed for avatar images, specified in megabytes (MB).
+
+ - Type: Integer
+ - Example:
+ ```yaml
+ fileConfig:
+ avatarSizeLimit: 2
+ ```
+ - **Note**: Specifically tailored for user avatar uploads, allowing for control over image sizes to maintain consistent quality and loading times.
+
+### **endpoints**
+
+!!! tip "fileConfig / endpoints"
+
+ > Configures file handling settings for individual endpoints, allowing customization per endpoint basis.
+
+ - Type: Record/Object
+ - **Description**: Specifies file handling configurations for individual endpoints, allowing customization per endpoint basis.
+
+Each object under endpoints is a record that can have the following settings:
+
+#### **Overview**
+
+ - `disabled`
+ - Whether file handling is disabled for the endpoint.
+ - `fileLimit`
+ - The maximum number of files allowed per upload request.
+ - `fileSizeLimit`
+ - The maximum size for a single file. In units of MB (e.g. use `20` for 20 megabytes)
+ - `totalSizeLimit`
+ - The total maximum size for all files in a single request. In units of MB (e.g. use `20` for 20 megabytes)
+ - `supportedMimeTypes`
+ - A list of [Regular Expressions](https://en.wikipedia.org/wiki/Regular_expression) specifying what MIME types are allowed for upload. This can be customized to restrict file types.
+
+### **disabled**
+
+!!! tip "fileConfig / endpoints / {endpoint_record} / disabled"
+
+ > Indicates whether file uploading is disabled for a specific endpoint.
+
+ - Type: Boolean
+ - Default: `false` (i.e., uploading is enabled by default)
+ - Example:
+ ```yaml
+ openAI:
+ disabled: true
+ ```
+ - **Note**: Setting this to `true` prevents any file uploads to the specified endpoint, overriding any other file-related settings.
+
+### **fileLimit**
+
+!!! tip "fileConfig / endpoints / {endpoint_record} / fileLimit"
-### **socialLogins**:
+ > The maximum number of files allowed in a single upload request.
- > Defines the available social login providers and their display order.
+ - Type: Integer
+ - Default: Varies by endpoint
+ - Example:
+ ```yaml
+ assistants:
+ fileLimit: 5
+ ```
+ - **Note**: Helps control the volume of uploads and manage server load.
- - Type: Array of Strings
- - Example:
+### **fileSizeLimit**
+
+!!! tip "fileConfig / endpoints / {endpoint_record} / fileSizeLimit"
+
+ > The maximum size allowed for each individual file, specified in megabytes (MB).
+
+ - Type: Integer
+ - Default: Varies by endpoint
+ - Example:
+ ```yaml
+ YourCustomEndpointName:
+ fileSizeLimit: 1000
+ ```
+ - **Note**: This limit ensures that no single file exceeds the specified size, allowing for better resource allocation and management.
+
+### **totalSizeLimit**
+
+!!! tip "fileConfig / endpoints / {endpoint_record} / totalSizeLimit"
+
+ > The total maximum size allowed for all files in a single request, specified in megabytes (MB).
+
+ - Type: Integer
+ - Default: Varies by endpoint
+ - Example:
+ ```yaml
+ assistants:
+ totalSizeLimit: 50
+ ```
+ - **Note**: This setting is crucial for preventing excessive bandwidth and storage usage by any single upload request.
+
+### **supportedMimeTypes**
+
+!!! tip "fileConfig / endpoints / {endpoint_record} / supportedMimeTypes"
+
+ > A list of regular expressions defining the MIME types permitted for upload.
+
+ - Type: Array of Strings
+ - Default: Varies by endpoint
+ - Example:
+ ```yaml
+ assistants:
+ supportedMimeTypes:
+ - "image/.*"
+ - "application/pdf"
+ ```
+ - **Note**: This allows for precise control over the types of files that can be uploaded. Invalid regex is ignored.
+
+## Interface Object Structure
+
+### **Overview**
+
+The `interface` object allows for customization of various user interface elements within the application, including visibility and behavior settings for components such as menus, panels, and links. This section provides a detailed breakdown of the `interface` object structure.
+
+There are 7 main fields under `interface`:
+
+ - `privacyPolicy`
+ - `termsOfService`
+ - `endpointsMenu`
+ - `modelSelect`
+ - `parameters`
+ - `sidePanel`
+ - `presets`
+
+**Notes:**
+
+- The `interface` configurations are applied globally within the application.
+- Default values are provided for most settings but can be overridden based on specific requirements or conditions.
+- Conditional logic in the application can further modify these settings based on other configurations like model specifications.
+
+### Example
+
+??? tip "Click here to expand/collapse example"
```yaml
- socialLogins: ["google", "facebook", "github", "discord", "openid"]
+ interface:
+ privacyPolicy:
+ externalUrl: "https://example.com/privacy"
+ openNewTab: true
+ termsOfService:
+ externalUrl: "https://example.com/terms"
+ openNewTab: true
+ endpointsMenu: true
+ modelSelect: false
+ parameters: true
+ sidePanel: true
+ presets: false
```
- - **Note**: The order of the providers in the list determines their appearance order on the login/registration page. Each provider listed must be [properly configured](./user_auth_system.md#social-authentication-setup-and-configuration) within the system to be active and available for users. This configuration allows for a tailored authentication experience, emphasizing the most relevant or preferred social login options for your user base.
-### **allowedDomains**:
+### **privacyPolicy**
+
+!!! tip "interface / privacyPolicy"
+
+ > Contains settings related to the privacy policy link provided in the user interface.
+
+ - Type: Object
+ - **Description**: Allows for the specification of a custom URL and the option to open it in a new tab.
+ - **Sub-keys**:
+ - `externalUrl`
+ - Type: String (URL)
+ - Description: The URL pointing to the privacy policy document.
+ - `openNewTab`
+ - Type: Boolean
+ - Description: Specifies whether the link should open in a new tab.
+
+### **termsOfService**
+
+!!! tip "interface / termsOfService"
+
+ > Contains settings related to the terms of service link provided in the user interface.
+
+ - Type: Object
+ - **Description**: Allows for the specification of a custom URL and the option to open it in a new tab.
+ - **Sub-keys**:
+ - `externalUrl`
+ - Type: String (URL)
+ - Description: The URL pointing to the terms of service document.
+ - `openNewTab`
+ - Type: Boolean
+ - Description: Specifies whether the link should open in a new tab.
+
+### **endpointsMenu**
+
+!!! tip "interface / endpointsMenu"
+
+ > Controls the visibility of the endpoints menu in the interface.
+
+ - Type: Boolean
+ - Default: `true`
+ - Example:
+ ```yaml
+ interface:
+ endpointsMenu: false
+ ```
+ - **Note**: Toggling this setting allows administrators to customize the availability of endpoint selections within the application.
+
+### **modelSelect**
+
+!!! tip "interface / modelSelect"
+
+ > Determines whether the model selection feature is available in the UI.
+
+ - Type: Boolean
+ - Default: `true`
+ - Example:
+ ```yaml
+ interface:
+ modelSelect: true
+ ```
+ - **Note**: Enabling this feature allows users to select different models directly from the interface.
+
+### **parameters**
+
+!!! tip "interface / parameters"
+
+ > Toggles the visibility of parameter configuration options within the interface.
+
+ - Type: Boolean
+ - Default: `true`
+ - Example:
+ ```yaml
+ interface:
+ parameters: false
+ ```
+ - **Note**: This setting is crucial for users who need to adjust parameters for specific functionalities within the application.
+
+### **sidePanel**
+
+!!! tip "interface / sidePanel"
+
+ > Controls the visibility of the side panel in the application's interface.
+
+ - Type: Boolean
+ - Default: `true`
+ - Example:
+ ```yaml
+ interface:
+ sidePanel: true
+ ```
+ - **Note**: The side panel typically contains additional navigation or information relevant to the application's context.
+
+### **presets**
+
+!!! tip "interface / presets"
+
+ > Enables or disables the use of presets in the application's UI.
+
+ - Type: Boolean
+ - Default: `true`
+ - Example:
+ ```yaml
+ interface:
+ presets: true
+ ```
+ - **Note**: Presets can simplify user interactions by providing pre-configured settings or operations, enhancing user experience and efficiency.
+
+
+## Model Specs Object Structure
+
+### **Overview**
- > A list specifying allowed email domains for registration.
+The `modelSpecs` object helps you provide a simpler UI experience for AI models within your application.
- - Type: Array of Strings
- - Example:
+There are 3 main fields under `modelSpecs`:
+
+ - `enforce` (optional; default: false)
+ - `prioritize` (optional; default: true)
+ - `list` (required)
+
+**Notes:**
+
+- If `enforce` is set to true, model specifications can potentially conflict with other interface settings such as `endpointsMenu`, `modelSelect`, `presets`, and `parameters`.
+- The `list` array contains detailed configurations for each model, including presets that dictate specific behaviors, appearances, and capabilities.
+- If interface fields are not specified, having a list of model specs will disable the following interface elements:
+ - `endpointsMenu`
+ - `modelSelect`
+ - `parameters`
+ - `presets`
+- If you would like to enable these interface elements along with model specs, you can set them to `true` in the `interface` object.
+
+### Example
+
+??? tip "Click here to expand/collapse example"
```yaml
- allowedDomains:
- - "gmail.com"
- - "protonmail.com"
+ modelSpecs:
+ enforce: true
+ prioritize: true
+ list:
+ - name: "commander_01"
+ label: "Commander in Chief"
+ description: "An AI roleplaying as the 50th President."
+ iconURL: "https://example.com/icon.jpg"
+ preset: {Refer to the detailed preset configuration example below}
```
- - **Required**
- - **Note**: Users with email domains not listed will be restricted from registering.
-Given the additional details and correction regarding `supportedMimeTypes` being a list of regex strings and the omission of the `assistantEndpoint` configuration, let's revise and add the necessary documentation sections.
+### **enforce**
+
+!!! tip "modelSpecs / enforce"
+
+ > Determines whether the model specifications should strictly override other configuration settings.
+
+ - Type: Boolean
+ - Default: `false`
+ - Example:
+ ```yaml
+ modelSpecs:
+ enforce: true
+ ```
+ - **Note**: Setting this to `true` can lead to conflicts with interface options if not managed carefully.
+
+### **prioritize**
+
+!!! tip "modelSpecs / prioritize"
+
+ > Specifies if model specifications should take priority over the default configuration when both are applicable.
+
+ - Type: Boolean
+ - Default: `true`
+ - Example:
+ ```yaml
+ modelSpecs:
+ prioritize: false
+ ```
+ - **Note**: When set to `true`, it ensures that a modelSpec is always selected in the UI. Doing this may prevent users from selecting different endpoints for the selected spec.
+
+### **list**
+
+!!! tip "modelSpecs / list"
+
+ > Contains a list of individual model specifications detailing various configurations and behaviors.
+
+ - Type: Array of Objects
+ - **Description**: Each object in the list details the configuration for a specific model, including its behaviors, appearance, and capabilities related to the application's functionality.
+
+Each spec object in the `list` can have the following settings:
+
+#### **Overview**
+
+ - `name`
+ - Unique identifier for the model.
+ - `label`
+ - A user-friendly name or label for the model, shown in the header dropdown.
+ - `description`
+ - A brief description of the model and its intended use or role, shown in the header dropdown menu.
+ - `iconURL`
+ - URL or a predefined endpoint name for the model's icon.
+ - `default`
+ - Specifies if this model spec is the default selection, to be auto-selected on every new chat.
+ - `showIconInMenu`
+ - Controls whether the model's icon appears in the header dropdown menu.
+ - `showIconInHeader`
+ - Controls whether the model's icon appears in the header dropdown button, left of its name.
+ - `preset`
+ - Detailed preset configurations that define the behavior and capabilities of the model (see preset object structure section below for more details).
+
+### Preset Object Structure
+
+The preset field for a modelSpec list item is made up of a comprehensive configuration blueprint for AI models within the system. It is designed to specify the operational settings of AI models, tailoring their behavior, outputs, and interactions with other system components and endpoints.
+
+#### **modelLabel**
+
+!!! tip "modelSpecs / list / {spec_item} / preset / modelLabel"
+
+ > The label used to identify the model in user interfaces or logs. It provides a human-readable name for the model, which is displayed in the UI, as well as made aware to the AI.
+
+ - Type: String (nullable, optional)
+ - Default: None
+ - Example:
+ ```yaml
+ preset:
+ modelLabel: "Customer Support Bot"
+ ```
+
+#### **endpoint**
+
+!!! tip "modelSpecs / list / {spec_item} / preset / endpoint"
+
+ > Specifies the endpoint the model communicates with to execute operations. This setting determines the external or internal service that the model interfaces with.
+
+ - Type: Enum (`EModelEndpoint`) or String (nullable)
+ - Example:
+ ```yaml
+ preset:
+ endpoint: "openAI"
+ ```
+
+#### **greeting**
+
+!!! tip "modelSpecs / list / {spec_item} / preset / greeting"
+
+ > A predefined message that is visible in the UI before a new chat is started.
+
+ - Type: String (optional)
+ - Example:
+ ```yaml
+ preset:
+ greeting: "Hello! How can I assist you today?"
+ ```
+
+#### **promptPrefix**
+
+!!! tip "modelSpecs / list / {spec_item} / preset / promptPrefix"
+
+ > A static text prepended to every prompt sent to the model, setting a consistent context for responses.
+
+ - Type: String (nullable, optional)
+ - Example:
+ ```yaml
+ preset:
+ promptPrefix: "As a financial advisor, ..."
+ ```
+ - **Note**: When using "assistants" as the endpoint, this becomes the OpenAI field `additional_instructions`
+
+#### **model_options**
+
+!!! tip "modelSpecs / list / {spec_item} / preset / {model_option}"
+
+ > These settings control the stochastic nature and behavior of model responses, affecting creativity, relevance, and variability.
+
+ - Types:
+ - `temperature`: Number (optional)
+ - `top_p`: Number (optional)
+ - `top_k`: Number (optional)
+ - `frequency_penalty`: Number (optional)
+ - `presence_penalty`: Number (optional)
+ - `stop`: Array of Strings (optional)
+
+ - Examples:
+ ```yaml
+ preset:
+ temperature: 0.7
+ top_p: 0.9
+ ```
+
+#### **resendFiles**
+
+!!! tip "modelSpecs / list / {spec_item} / preset / resendFiles"
+
+ > Indicates whether files should be resent in scenarios where persistent sessions are not maintained.
+
+ - Type: Boolean (optional)
+ - Example:
+ ```yaml
+ preset:
+ resendFiles: true
+ ```
+
+#### **imageDetail**
+
+!!! tip "modelSpecs / list / {spec_item} / preset / imageDetail"
+
+ > Specifies the level of detail required in image analysis tasks, applicable to models with vision capabilities (OpenAI spec).
+
+ - Type: `eImageDetailSchema` (optional)
+ - Example:
+ ```yaml
+ preset:
+ imageDetail: "high"
+ ```
+
+#### **agentOptions**
+
+!!! tip "modelSpecs / list / {spec_item} / preset / agentOptions"
+
+ > Specific to `gptPlugins` endpoint. Can be omitted either partially or completely for default settings
+
+ - Type: Record/Object (optional)
+ - Sub-fields include:
+ - `agent`: Type of agent (either "functions" or "classic"; default: "functions")
+ - `skipCompletion`: Whether to skip automatic completion suggestions (default: true)
+ - `model`: Model version or identifier (default: "gpt-4-turbo")
+ - `temperature`: Randomness in the model's responses (default: 0)
+
+ - Example:
+ ```yaml
+ preset:
+ agentOptions:
+ agent: "functions"
+ skipCompletion: false
+ model: "gpt-4-turbo"
+ temperature: 0.5
+ ```
+
+#### **tools**
+
+!!! tip "modelSpecs / list / {spec_item} / preset / tools"
+
+ > Specific to `gptPlugins` endpoint. List of tool/plugin names.
+
+ - Type: Array of Strings
+ - Optional
+ - Example:
+ ```yaml
+ preset:
+ tools: ["dalle", "tavily_search_results_json", "azure-ai-search", "traversaal_search"]
+ ```
+
+ **Notes**:
+
+ - At the moment, only tools that have credentials provided for them via .env file can be used with modelSpecs, unless the user already had the tool installed.
+ - You can find the names of the tools to filter in [`api/app/clients/tools/manifest.json`](https://github.com/danny-avila/LibreChat/blob/main/api/app/clients/tools/manifest.json)
+ - Use the `pluginKey` value
+ - Also, any listed under the ".well-known" directory [`api/app/clients/tools/.well-known`](https://github.com/danny-avila/LibreChat/blob/main/api/app/clients/tools/.well-known)
+ - Use the `name_for_model` value
+
+#### **assistant_options**
+
+!!! tip "modelSpecs / list / {spec_item} / preset / {assistant_option}"
+
+ > Configurations specific to assistants, such as identifying an assistant, overriding the assistant's instructions.
+
+ - Types:
+ - `assistant_id`: String (optional)
+ - `instructions`: String (optional)
+
+ - Examples:
+ ```yaml
+ preset:
+ assistant_id: "asst_98765"
+ # Overrides the assistant's default instructions
+ instructions: "Please handle customer queries regarding order status."
+ ```
+
+## Registration Object Structure
+
+### Example
+
+??? tip "Click here to expand/collapse example"
+ ```yaml
+ # Example Registration Object Structure
+ registration:
+ socialLogins: ["google", "facebook", "github", "discord", "openid"]
+ allowedDomains:
+ - "gmail.com"
+ - "protonmail.com"
+ ```
+
+### **socialLogins**
+
+!!! tip "registration / socialLogins"
+
+ > Defines the available social login providers and their display order.
+
+ - Type: Array of Strings
+ - Example:
+ ```yaml
+ socialLogins: ["google", "facebook", "github", "discord", "openid"]
+ ```
+ - **Note**: The order of the providers in the list determines their appearance order on the login/registration page. Each provider listed must be [properly configured](./user_auth_system.md#social-authentication-setup-and-configuration) within the system to be active and available for users. This configuration allows for a tailored authentication experience, emphasizing the most relevant or preferred social login options for your user base.
+
+### **allowedDomains**
+
+!!! tip "registration / allowedDomains"
+
+ > A list specifying allowed email domains for registration.
+
+ - Type: Array of Strings
+ - Example:
+ ```yaml
+ allowedDomains:
+ - "gmail.com"
+ - "protonmail.com"
+ ```
+ - **Required**
+ - **Note**: Users with email domains not listed will be restricted from registering.
## Assistants Endpoint Object Structure
### Example
-```yaml
-endpoints:
- assistants:
- disableBuilder: false
- pollIntervalMs: 500
- timeoutMs: 10000
- # Use either `supportedIds` or `excludedIds` but not both
- supportedIds: ["asst_supportedAssistantId1", "asst_supportedAssistantId2"]
- # excludedIds: ["asst_excludedAssistantId"]
- # (optional) Models that support retrieval, will default to latest known OpenAI models that support the feature
- # retrievalModels: ["gpt-4-turbo-preview"]
- # (optional) Assistant Capabilities available to all users. Omit the ones you wish to exclude. Defaults to list below.
- # capabilities: ["code_interpreter", "retrieval", "actions", "tools", "image_vision"]
-```
-> This configuration enables the builder interface for assistants, sets a polling interval of 500ms to check for run updates, and establishes a timeout of 10 seconds for assistant run operations.
+??? tip "Click here to expand/collapse example"
+ ```yaml
+ endpoints:
+ assistants:
+ disableBuilder: false
+ pollIntervalMs: 500
+ timeoutMs: 10000
+ # Use either `supportedIds` or `excludedIds` but not both
+ supportedIds: ["asst_supportedAssistantId1", "asst_supportedAssistantId2"]
+ # excludedIds: ["asst_excludedAssistantId"]
+ # (optional) Models that support retrieval, will default to latest known OpenAI models that support the feature
+ # retrievalModels: ["gpt-4-turbo-preview"]
+ # (optional) Assistant Capabilities available to all users. Omit the ones you wish to exclude. Defaults to list below.
+ # capabilities: ["code_interpreter", "retrieval", "actions", "tools", "image_vision"]
+ ```
+ > This configuration enables the builder interface for assistants, sets a polling interval of 500ms to check for run updates, and establishes a timeout of 10 seconds for assistant run operations.
-In addition to custom endpoints, you can configure settings specific to the assistants endpoint.
+### **disableBuilder**
-### **disableBuilder**:
+!!! tip "endpoints / assistants / disableBuilder"
-> Controls the visibility and use of the builder interface for assistants.
+ > Controls the visibility and use of the builder interface for assistants.
-- **Type**: Boolean
-- **Example**: `disableBuilder: false`
-- **Description**: When set to `true`, disables the builder interface for the assistant, limiting direct manual interaction.
-- **Note**: Defaults to `false` if omitted.
+ - **Type**: Boolean
+ - **Example**: `disableBuilder: false`
+ - **Description**: When set to `true`, disables the builder interface for the assistant, limiting direct manual interaction.
+ - **Note**: Defaults to `false` if omitted.
-### **pollIntervalMs**:
+### **pollIntervalMs**
-> Specifies the polling interval in milliseconds for checking run updates or changes in assistant run states.
+!!! tip "endpoints / assistants / pollIntervalMs"
-- **Type**: Integer
-- **Example**: `pollIntervalMs: 500`
-- **Description**: Specifies the polling interval in milliseconds for checking assistant run updates.
-- **Note**: Defaults to `750` if omitted.
+ > Specifies the polling interval in milliseconds for checking run updates or changes in assistant run states.
-### **timeoutMs**:
+ - **Type**: Integer
+ - **Example**: `pollIntervalMs: 500`
+ - **Description**: Specifies the polling interval in milliseconds for checking assistant run updates.
+ - **Note**: Defaults to `750` if omitted.
-> Defines the maximum time in milliseconds that an assistant can run before the request is cancelled.
+### **timeoutMs**
-- **Type**: Integer
-- **Example**: `timeoutMs: 10000`
-- **Description**: Sets a timeout in milliseconds for assistant runs. Helps manage system load by limiting total run operation time.
-- **Note**: Defaults to 3 minutes (180,000 ms). Run operation times can range between 50 seconds to 2 minutes but also exceed this. If the `timeoutMs` value is exceeded, the run will be cancelled.
+!!! tip "endpoints / assistants / timeoutMs"
-### **supportedIds**:
+ > Defines the maximum time in milliseconds that an assistant can run before the request is cancelled.
- > List of supported assistant Ids
+ - **Type**: Integer
+ - **Example**: `timeoutMs: 10000`
+ - **Description**: Sets a timeout in milliseconds for assistant runs. Helps manage system load by limiting total run operation time.
+ - **Note**: Defaults to 3 minutes (180,000 ms). Run operation times can range between 50 seconds to 2 minutes but also exceed this. If the `timeoutMs` value is exceeded, the run will be cancelled.
- - Type: Array/List of Strings
- - **Description**: List of supported assistant Ids. Use this or `excludedIds` but not both (the `excludedIds` field will be ignored if so).
- - **Example**: `supportedIds: ["asst_supportedAssistantId1", "asst_supportedAssistantId2"]`
+### **supportedIds**
-### **excludedIds**:
+!!! tip "endpoints / assistants / supportedIds"
- > List of excluded assistant Ids
+ > List of supported assistant Ids
- - Type: Array/List of Strings
- - **Description**: List of excluded assistant Ids. Use this or `supportedIds` but not both (the `excludedIds` field will be ignored if so).
- - **Example**: `excludedIds: ["asst_excludedAssistantId1", "asst_excludedAssistantId2"]`
+ - Type: Array/List of Strings
+ - **Description**: List of supported assistant Ids. Use this or `excludedIds` but not both (the `excludedIds` field will be ignored if so).
+ - **Example**: `supportedIds: ["asst_supportedAssistantId1", "asst_supportedAssistantId2"]`
-### **retrievalModels**:
+### **excludedIds**
-> Specifies the models that support retrieval for the assistants endpoint.
+!!! tip "endpoints / assistants / excludedIds"
-- **Type**: Array/List of Strings
-- **Example**: `retrievalModels: ["gpt-4-turbo-preview"]`
-- **Description**: Defines the models that support retrieval capabilities for the assistants endpoint. By default, it uses the latest known OpenAI models that support the official Retrieval feature.
-- **Note**: This field is optional. If omitted, the default behavior is to use the latest known OpenAI models that support retrieval.
+ > List of excluded assistant Ids
-### **capabilities**:
+ - Type: Array/List of Strings
+ - **Description**: List of excluded assistant Ids. Use this or `supportedIds` but not both (the `excludedIds` field will be ignored if so).
+ - **Example**: `excludedIds: ["asst_excludedAssistantId1", "asst_excludedAssistantId2"]`
-> Specifies the assistant capabilities available to all users for the assistants endpoint.
+### **retrievalModels**
-- **Type**: Array/List of Strings
-- **Example**: `capabilities: ["code_interpreter", "retrieval", "actions", "tools", "image_vision"]`
-- **Description**: Defines the assistant capabilities that are available to all users for the assistants endpoint. You can omit the capabilities you wish to exclude from the list. The available capabilities are:
- - `code_interpreter`: Enables code interpretation capabilities for the assistant.
- - `image_vision`: Enables unofficial vision support for uploaded images.
- - `retrieval`: Enables retrieval capabilities for the assistant.
- - `actions`: Enables action capabilities for the assistant.
- - `tools`: Enables tool capabilities for the assistant.
-- **Note**: This field is optional. If omitted, the default behavior is to include all the capabilities listed in the example.
+!!! tip "endpoints / assistants / retrievalModels"
+
+ > Specifies the models that support retrieval for the assistants endpoint.
+
+ - **Type**: Array/List of Strings
+ - **Example**: `retrievalModels: ["gpt-4-turbo-preview"]`
+ - **Description**: Defines the models that support retrieval capabilities for the assistants endpoint. By default, it uses the latest known OpenAI models that support the official Retrieval feature.
+ - **Note**: This field is optional. If omitted, the default behavior is to use the latest known OpenAI models that support retrieval.
+
+### **capabilities**
+
+!!! tip "endpoints / assistants / capabilities"
+
+ > Specifies the assistant capabilities available to all users for the assistants endpoint.
+
+ - **Type**: Array/List of Strings
+ - **Example**: `capabilities: ["code_interpreter", "retrieval", "actions", "tools", "image_vision"]`
+ - **Description**: Defines the assistant capabilities that are available to all users for the assistants endpoint. You can omit the capabilities you wish to exclude from the list. The available capabilities are:
+ - `code_interpreter`: Enables code interpretation capabilities for the assistant.
+ - `image_vision`: Enables unofficial vision support for uploaded images.
+ - `retrieval`: Enables retrieval capabilities for the assistant.
+ - `actions`: Enables action capabilities for the assistant.
+ - `tools`: Enables tool capabilities for the assistant.
+ - **Note**: This field is optional. If omitted, the default behavior is to include all the capabilities listed in the example.
## Custom Endpoint Object Structure
Each endpoint in the `custom` array should have the following structure:
### Example
-```yaml
-# Example Endpoint Object Structure
-endpoints:
- custom:
- # Example using Mistral AI API
- - name: "Mistral"
- apiKey: "${YOUR_ENV_VAR_KEY}"
- baseURL: "https://api.mistral.ai/v1"
- models:
- default: ["mistral-tiny", "mistral-small", "mistral-medium", "mistral-large-latest"]
- titleConvo: true
- titleModel: "mistral-tiny"
- modelDisplayLabel: "Mistral"
- # addParams:
- # safe_prompt: true # Mistral specific value for moderating messages
- # NOTE: For Mistral, it is necessary to drop the following parameters or you will encounter a 422 Error:
- dropParams: ["stop", "user", "frequency_penalty", "presence_penalty"]
-```
+??? tip "Click here to expand/collapse example"
+ ```yaml
+ # Example Endpoint Object Structure
+ endpoints:
+ custom:
+ # Example using Mistral AI API
+ - name: "Mistral"
+ apiKey: "${YOUR_ENV_VAR_KEY}"
+ baseURL: "https://api.mistral.ai/v1"
+ models:
+ default: ["mistral-tiny", "mistral-small", "mistral-medium", "mistral-large-latest"]
+ titleConvo: true
+ titleModel: "mistral-tiny"
+ modelDisplayLabel: "Mistral"
+ # addParams:
+ # safe_prompt: true # Mistral specific value for moderating messages
+ # NOTE: For Mistral, it is necessary to drop the following parameters or you will encounter a 422 Error:
+ dropParams: ["stop", "user", "frequency_penalty", "presence_penalty"]
+ ```
-### **name**:
+### **name**
- > A unique name for the endpoint.
+!!! tip "endpoints / custom / name"
- - Type: String
- - Example: `name: "Mistral"`
- - **Required**
- - **Note**: Will be used as the "title" in the Endpoints Selector
+ > A unique name for the endpoint.
-### **apiKey**:
+ - Type: String
+ - Example: `name: "Mistral"`
+ - **Required**
+ - **Note**: Will be used as the "title" in the Endpoints Selector
- > Your API key for the service. Can reference an environment variable, or allow user to provide the value.
+### **apiKey**
- - Type: String (apiKey | `"user_provided"`)
- - Example: `apiKey: "${MISTRAL_API_KEY}"` | `apiKey: "your_api_key"` | `apiKey: "user_provided"`
- - **Required**
- - **Note**: It's highly recommended to use the env. variable reference for this field, i.e. `${YOUR_VARIABLE}`
+!!! tip "endpoints / custom / apiKey"
-### **baseURL**:
+ > Your API key for the service. Can reference an environment variable, or allow user to provide the value.
- > Base URL for the API. Can reference an environment variable, or allow user to provide the value.
+ - Type: String (apiKey | `"user_provided"`)
+ - Example: `apiKey: "${MISTRAL_API_KEY}"` | `apiKey: "your_api_key"` | `apiKey: "user_provided"`
+ - **Required**
+ - **Note**: It's highly recommended to use the env. variable reference for this field, i.e. `${YOUR_VARIABLE}`
- - Type: String (baseURL | `"user_provided"`)
- - Example: `baseURL: "https://api.mistral.ai/v1"` | `baseURL: "${MISTRAL_BASE_URL}"` | `baseURL: "user_provided"`
- - **Required**
- - **Note**: It's highly recommended to use the env. variable reference for this field, i.e. `${YOUR_VARIABLE}`
+### **baseURL**
-### **iconURL**:
+!!! tip "endpoints / custom / baseURL"
- > The URL to use as the Endpoint Icon.
+ > Base URL for the API. Can reference an environment variable, or allow user to provide the value.
- - Type: Boolean
- - Example: `iconURL: https://github.com/danny-avila/LibreChat/raw/main/docs/assets/LibreChat.svg`
- - **Note**: The following are "known endpoints" (case-insensitive), which have icons provided for them. If your endpoint `name` matches the following names, you should omit this field:
- - "Mistral"
- - "OpenRouter"
- - "Groq"
- - APIpie
- - "Anyscale"
- - "Fireworks"
- - "Perplexity"
- - "together.ai"
- - "Ollama"
+ - Type: String (baseURL | `"user_provided"`)
+ - Example: `baseURL: "https://api.mistral.ai/v1"` | `baseURL: "${MISTRAL_BASE_URL}"` | `baseURL: "user_provided"`
+ - **Required**
+ - **Note**: It's highly recommended to use the env. variable reference for this field, i.e. `${YOUR_VARIABLE}`
-### **models**:
+### **iconURL**
- > Configuration for models.
+!!! tip "endpoints / custom / iconURL"
+
+ > The URL to use as the Endpoint Icon.
- - **Required**
- - **default**: An array of strings indicating the default models to use. At least one value is required.
- - Type: Array of Strings
- - Example: `default: ["mistral-tiny", "mistral-small", "mistral-medium"]`
- - **Note**: If fetching models fails, these defaults are used as a fallback.
- - **fetch**: When set to `true`, attempts to fetch a list of models from the API.
- Type: Boolean
- - Example: `fetch: true`
- - **Note**: May cause slowdowns during initial use of the app if the response is delayed. Defaults to `false`.
- - **userIdQuery**: When set to `true`, adds the LibreChat user ID as a query parameter to the API models request.
+ - Example: `iconURL: https://github.com/danny-avila/LibreChat/raw/main/docs/assets/LibreChat.svg`
+ - **Notes**:
+ - If you want to use existing project icons, define the endpoint `name` as one of the main endpoints (case-sensitive):
+ - "openAI" | "azureOpenAI" | "google" | "anthropic" | "assistants" | "gptPlugins"
+ - There are also "known endpoints" (case-insensitive), which have icons provided. If your endpoint `name` matches the following names, you should omit this field:
+ - "Mistral"
+ - "OpenRouter"
+ - "Groq"
+ - APIpie
+ - "Anyscale"
+ - "Fireworks"
+ - "Perplexity"
+ - "together.ai"
+ - "Ollama"
+
+### **models**
+
+!!! tip "endpoints / custom / models"
+
+ > Configuration for models.
+
+ - **Required**
+ - **default**: An array of strings indicating the default models to use. At least one value is required.
+ - Type: Array of Strings
+ - Example: `default: ["mistral-tiny", "mistral-small", "mistral-medium"]`
+ - **Note**: If fetching models fails, these defaults are used as a fallback.
+ - **fetch**: When set to `true`, attempts to fetch a list of models from the API.
+ - Type: Boolean
+ - Example: `fetch: true`
+ - **Note**: May cause slowdowns during initial use of the app if the response is delayed. Defaults to `false`.
+ - **userIdQuery**: When set to `true`, adds the LibreChat user ID as a query parameter to the API models request.
+ - Type: Boolean
+ - Example: `userIdQuery: true`
+
+### **titleConvo**
+
+!!! tip "endpoints / custom / titleConvo"
+
+ > Enables title conversation when set to `true`.
+
- Type: Boolean
- - Example: `userIdQuery: true`
+ - Example: `titleConvo: true`
-### **titleConvo**:
+### **titleMethod**
- > Enables title conversation when set to `true`.
+!!! tip "endpoints / custom / titleMethod"
- - Type: Boolean
- - Example: `titleConvo: true`
+ > Chooses between "completion" or "functions" for title method.
-### **titleMethod**:
+ - Type: String (`"completion"` | `"functions"`)
+ - Example: `titleMethod: "completion"`
+ - **Note**: Defaults to "completion" if omitted.
- > Chooses between "completion" or "functions" for title method.
+### **titleModel**
- - Type: String (`"completion"` | `"functions"`)
- - Example: `titleMethod: "completion"`
- - **Note**: Defaults to "completion" if omitted.
+!!! tip "endpoints / custom / titleModel"
-### **titleModel**:
+ > Specifies the model to use for titles.
- > Specifies the model to use for titles.
+ - Type: String
+ - Example: `titleModel: "mistral-tiny"`
+ - **Note**: Defaults to "gpt-3.5-turbo" if omitted. May cause issues if "gpt-3.5-turbo" is not available.
+ - **Note**: You can also dynamically use the current conversation model by setting it to "current_model".
- - Type: String
- - Example: `titleModel: "mistral-tiny"`
- - **Note**: Defaults to "gpt-3.5-turbo" if omitted. May cause issues if "gpt-3.5-turbo" is not available.
- - **Note**: You can also dynamically use the current conversation model by setting it to "current_model".
+### **summarize**
-### **summarize**:
+!!! tip "endpoints / custom / summarize"
- > Enables summarization when set to `true`.
+ > Enables summarization when set to `true`.
- - Type: Boolean
- - Example: `summarize: false`
- - **Note**: This feature requires an OpenAI Functions compatible API
+ - Type: Boolean
+ - Example: `summarize: false`
+ - **Note**: This feature requires an OpenAI Functions compatible API
-### **summaryModel**:
+### **summaryModel**
- > Specifies the model to use if summarization is enabled.
+!!! tip "endpoints / custom / summaryModel"
- - Type: String
- - Example: `summaryModel: "mistral-tiny"`
- - **Note**: Defaults to "gpt-3.5-turbo" if omitted. May cause issues if "gpt-3.5-turbo" is not available.
+ > Specifies the model to use if summarization is enabled.
-### **forcePrompt**:
+ - Type: String
+ - Example: `summaryModel: "mistral-tiny"`
+ - **Note**: Defaults to "gpt-3.5-turbo" if omitted. May cause issues if "gpt-3.5-turbo" is not available.
- > If `true`, sends a `prompt` parameter instead of `messages`.
+### **forcePrompt**
- - Type: Boolean
- - Example: `forcePrompt: false`
- - **Note**: This combines all messages into a single text payload, [following OpenAI format](https://github.com/pvicente/openai-python/blob/main/chatml.md), and
+!!! tip "endpoints / custom / forcePrompt"
- uses the `/completions` endpoint of your baseURL rather than `/chat/completions`.
+ > If `true`, sends a `prompt` parameter instead of `messages`.
-### **modelDisplayLabel**:
+ - Type: Boolean
+ - Example: `forcePrompt: false`
+ - **Note**: Combines all messages into a single text payload or "prompt", [following OpenAI format](https://github.com/pvicente/openai-python/blob/main/chatml.md), which uses the `/completions` endpoint of your baseURL rather than `/chat/completions`.
- > The label displayed in messages next to the Icon for the current AI model.
+### **modelDisplayLabel**
- - Type: String
- - Example: `modelDisplayLabel: "Mistral"`
- - **Note**: The display order is:
- - 1. Custom name set via preset (if available)
- - 2. Label derived from the model name (if applicable)
- - 3. This value, `modelDisplayLabel`, is used if the above are not specified. Defaults to "AI".
+!!! tip "endpoints / custom / modelDisplayLabel"
-### **addParams**:
+ > The label displayed in messages next to the Icon for the current AI model.
- > Adds additional parameters to requests.
+ - Type: String
+ - Example: `modelDisplayLabel: "Mistral"`
+ - **Note**: The display order is:
+ - 1. Custom name set via preset (if available)
+ - 2. Label derived from the model name (if applicable)
+ - 3. This value, `modelDisplayLabel`, is used if the above are not specified. Defaults to "AI".
- - Type: Object/Dictionary
- - **Description**: Adds/Overrides parameters. Useful for specifying API-specific options.
- - **Example**:
-```yaml
- addParams:
- safe_prompt: true
-```
+### **addParams**
-### **dropParams**:
+!!! tip "endpoints / custom / addParams"
- > Removes [default parameters](#default-parameters) from requests.
+ > Adds additional parameters to requests.
- - Type: Array/List of Strings
- - **Description**: Excludes specified [default parameters](#default-parameters). Useful for APIs that do not accept or recognize certain parameters.
- - **Example**: `dropParams: ["stop", "user", "frequency_penalty", "presence_penalty"]`
- - **Note**: For a list of default parameters sent with every request, see the ["Default Parameters"](#default-parameters) Section below.
+ - Type: Object/Dictionary
+ - **Description**: Adds/Overrides parameters. Useful for specifying API-specific options.
+ - **Example**:
+ ```yaml
+ addParams:
+ safe_prompt: true
+ ```
-### **headers**:
+### **dropParams**
- > Adds additional headers to requests. Can reference an environment variable
+!!! tip "endpoints / custom / dropParams"
- - Type: Object/Dictionary
- - **Description**: The `headers` object specifies custom headers for requests. Useful for authentication and setting content types.
- - **Example**:
- - **Note**: Supports dynamic environment variable values, which use the format: `"${VARIABLE_NAME}"`
-```yaml
- headers:
- x-api-key: "${ENVIRONMENT_VARIABLE}"
- Content-Type: "application/json"
-```
+ > Removes [default parameters](#default-parameters) from requests.
-### Additional Notes
-- Ensure that all URLs and keys are correctly specified to avoid connectivity issues.
+ - Type: Array/List of Strings
+ - **Description**: Excludes specified [default parameters](#default-parameters). Useful for APIs that do not accept or recognize certain parameters.
+ - **Example**: `dropParams: ["stop", "user", "frequency_penalty", "presence_penalty"]`
+ - **Note**: For a list of default parameters sent with every request, see the ["Default Parameters"](#default-parameters) Section below.
-### Default Parameters
+### **headers**
-Custom endpoints share logic with the OpenAI endpoint, and thus have default parameters tailored to the OpenAI API.
+!!! tip "endpoints / custom / headers"
-```json
-{
- "model": "your-selected-model",
- "temperature": 1,
- "top_p": 1,
- "presence_penalty": 0,
- "frequency_penalty": 0,
- "user": "LibreChat_User_ID",
- "stream": true,
- "messages": [
- {
- "role": "user",
- "content": "hi how are you",
- },
- ],
-}
-```
-### Breakdown of Default Params
-- `model`: The selected model from list of models.
-- `temperature`: Defaults to `1` if not provided via preset,
-- `top_p`: Defaults to `1` if not provided via preset,
-- `presence_penalty`: Defaults to `0` if not provided via preset,
-- `frequency_penalty`: Defaults to `0` if not provided via preset,
-- `user`: A unique identifier representing your end-user, which can help OpenAI to [monitor and detect abuse](https://platform.openai.com/docs/api-reference/chat/create#chat-create-user).
-- `stream`: If set, partial message deltas will be sent, like in ChatGPT. Otherwise, generation will only be available when completed.
-- `messages`: [OpenAI format for messages](https://platform.openai.com/docs/api-reference/chat/create#chat-create-messages); the `name` field is added to messages with `system` and `assistant` roles when a custom name is specified via preset.
+ > Adds additional headers to requests. Can reference an environment variable
-**Note:** The `max_tokens` field is not sent to use the maximum amount of tokens available, which is default OpenAI API behavior. Some alternate APIs require this field, or it may default to a very low value and your responses may appear cut off; in this case, you should add it to `addParams` field as shown in the [Endpoint Object Structure](#endpoint-object-structure).
+ - Type: Object/Dictionary
+ - **Description**: The `headers` object specifies custom headers for requests. Useful for authentication and setting content types.
+ - **Example**:
+ - **Note**: Supports dynamic environment variable values, which use the format: `"${VARIABLE_NAME}"`
+ ```yaml
+ headers:
+ x-api-key: "${ENVIRONMENT_VARIABLE}"
+ Content-Type: "application/json"
+ ```
## Azure OpenAI Object Structure
@@ -785,221 +1355,308 @@ Integrating Azure OpenAI Service with your application allows you to seamlessly
### Example Configuration
-```yaml
-# Example Azure OpenAI Object Structure
-endpoints:
- azureOpenAI:
- titleModel: "gpt-4-turbo"
- plugins: true
- groups:
- - group: "my-westus" # arbitrary name
- apiKey: "${WESTUS_API_KEY}"
- instanceName: "actual-instance-name" # name of the resource group or instance
- version: "2023-12-01-preview"
- # baseURL: https://prod.example.com
- # additionalHeaders:
- # X-Custom-Header: value
- models:
- gpt-4-vision-preview:
- deploymentName: gpt-4-vision-preview
+??? tip "Click here to expand/collapse example"
+ ```yaml
+ # Example Azure OpenAI Object Structure
+ endpoints:
+ azureOpenAI:
+ titleModel: "gpt-4-turbo"
+ plugins: true
+ groups:
+ - group: "my-westus" # arbitrary name
+ apiKey: "${WESTUS_API_KEY}"
+ instanceName: "actual-instance-name" # name of the resource group or instance
+ version: "2023-12-01-preview"
+ # baseURL: https://prod.example.com
+ # additionalHeaders:
+ # X-Custom-Header: value
+ models:
+ gpt-4-vision-preview:
+ deploymentName: gpt-4-vision-preview
+ version: "2024-02-15-preview"
+ gpt-3.5-turbo:
+ deploymentName: gpt-35-turbo
+ gpt-3.5-turbo-1106:
+ deploymentName: gpt-35-turbo-1106
+ gpt-4:
+ deploymentName: gpt-4
+ gpt-4-1106-preview:
+ deploymentName: gpt-4-1106-preview
+ - group: "my-eastus"
+ apiKey: "${EASTUS_API_KEY}"
+ instanceName: "actual-eastus-instance-name"
+ deploymentName: gpt-4-turbo
version: "2024-02-15-preview"
- gpt-3.5-turbo:
- deploymentName: gpt-35-turbo
- gpt-3.5-turbo-1106:
- deploymentName: gpt-35-turbo-1106
- gpt-4:
- deploymentName: gpt-4
- gpt-4-1106-preview:
- deploymentName: gpt-4-1106-preview
- - group: "my-eastus"
- apiKey: "${EASTUS_API_KEY}"
- instanceName: "actual-eastus-instance-name"
- deploymentName: gpt-4-turbo
- version: "2024-02-15-preview"
- baseURL: "https://gateway.ai.cloudflare.com/v1/cloudflareId/azure/azure-openai/${INSTANCE_NAME}/${DEPLOYMENT_NAME}" # uses env variables
- additionalHeaders:
- X-Custom-Header: value
- models:
- gpt-4-turbo: true
-```
+ baseURL: "https://gateway.ai.cloudflare.com/v1/cloudflareId/azure/azure-openai/${INSTANCE_NAME}/${DEPLOYMENT_NAME}" # uses env variables
+ additionalHeaders:
+ X-Custom-Header: value
+ models:
+ gpt-4-turbo: true
+ ```
+
+### **plugins**
+
+!!! tip "endpoints / azureOpenAI / plugins"
+
+ > Enables or disables plugins for the Azure OpenAI endpoint.
+
+ - Type: Boolean
+ - **Example**: `plugins: true`
+ - **Description**: When set to `true`, activates plugins associated with this endpoint.
+ - **Note**: You can only use either the official OpenAI API or Azure OpenAI API for plugins, not both.
+
+### **assistants**
+
+!!! tip "endpoints / azureOpenAI / assistants"
+
+ > Enables or disables assistants for the Azure OpenAI endpoint.
+
+ - Type: Boolean
+ - **Example**: `assistants: true`
+ - **Description**: When set to `true`, activates assistants associated with this endpoint.
+ - **Note**: You can only use either the official OpenAI API or Azure OpenAI API for assistants, not both.
+
+### **groups**
+
+!!! tip "endpoints / azureOpenAI / groups"
+
+ > Configuration for groups of models by geographic location or purpose.
+
+ - Type: Array
+ - **Description**: Each item in the `groups` array configures a set of models under a certain grouping, often by geographic region or distinct configuration.
+ - **Example**: [See example above.](#example-configuration)
+
+### Group Object Structure
-### **groups**:
+Each item under `groups` is part of a list of records, each with the following fields:
-> Configuration for groups of models by geographic location or purpose.
+#### **group**
-- Type: Array
-- **Description**: Each item in the `groups` array configures a set of models under a certain grouping, often by geographic region or distinct configuration.
-- **Example**: See above.
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / group"
-### **plugins**:
+ > Identifier for a group of models.
-> Enables or disables plugins for the Azure OpenAI endpoint.
+ - Type: String
+ - **Required**
+ - **Example**: `"my-westus"`
-- Type: Boolean
-- **Example**: `plugins: true`
-- **Description**: When set to `true`, activates plugins associated with this endpoint.
+#### **apiKey**
-### Group Configuration Parameters
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / apiKey"
-#### **group**:
+ > The API key for accessing the Azure OpenAI Service.
- > Identifier for a group of models.
+ - Type: String
+ - **Required**
+ - **Example**: `"${WESTUS_API_KEY}"`
+ - **Note**: It's highly recommended to use a custom env. variable reference for this field, i.e. `${YOUR_VARIABLE}`
- - Type: String
- - **Required**
- - **Example**: `"my-westus"`
+#### **instanceName**
-#### **apiKey**:
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / instanceName"
- > The API key for accessing the Azure OpenAI Service.
+ > Name of the Azure instance.
- - Type: String
- - **Required**
- - **Example**: `"${WESTUS_API_KEY}"`
- - **Note**: It's highly recommended to use a custom env. variable reference for this field, i.e. `${YOUR_VARIABLE}`
+ - Type: String
+ - **Required**
+ - **Example**: `"my-westus"`
+ - **Note**: It's recommended to use a custom env. variable reference for this field, i.e. `${YOUR_VARIABLE}`
-#### **instanceName**:
+#### **version**
- > Name of the Azure instance.
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / version"
- - Type: String
- - **Required**
- - **Example**: `"my-westus"`
- - **Note**: It's recommended to use a custom env. variable reference for this field, i.e. `${YOUR_VARIABLE}`
+ > API version.
+ - Type: String
+ - **Optional**
+ - **Example**: `"2023-12-01-preview"`
+ - **Note**: It's recommended to use a custom env. variable reference for this field, i.e. `${YOUR_VARIABLE}`
-#### **version**:
+#### **baseURL**
- > API version.
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / baseURL"
- - Type: String
- - **Optional**
- - **Example**: `"2023-12-01-preview"`
- - **Note**: It's recommended to use a custom env. variable reference for this field, i.e. `${YOUR_VARIABLE}`
+ > The base URL for the Azure OpenAI Service.
-#### **baseURL**:
+ - Type: String
+ - **Optional**
+ - **Example**: `"https://prod.example.com"`
+ - **Note**: It's recommended to use a custom env. variable reference for this field, i.e. `${YOUR_VARIABLE}`
- > The base URL for the Azure OpenAI Service.
+#### **additionalHeaders**
- - Type: String
- - **Optional**
- - **Example**: `"https://prod.example.com"`
- - **Note**: It's recommended to use a custom env. variable reference for this field, i.e. `${YOUR_VARIABLE}`
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / additionalHeaders"
-#### **additionalHeaders**:
+ > Additional headers for API requests.
- > Additional headers for API requests.
+ - Type: Dictionary
+ - **Optional**
+ - **Example**:
+ ```yaml
+ additionalHeaders:
+ X-Custom-Header: ${YOUR_SECRET_CUSTOM_VARIABLE}
+ ```
+ - **Note**: It's recommended to use a custom env. variable reference for the values of field, as shown in the example.
+ - **Note**: `api-key` header value is sent on every request
- - Type: Dictionary
- - **Optional**
- - **Example**:
+#### **serverless**
+
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / serverless"
+
+ > Indicates the use of a serverless inference endpoint for Azure OpenAI chat completions.
+
+ - Type: Boolean
+ - **Optional**
+ - **Description**: When set to `true`, specifies that the group is configured to use serverless inference endpoints as an Azure "Models as a Service" model.
+ - **Example**: `serverless: true`
+ - **Note**: [More info here](./azure_openai.md#serverless-inference-endpoints)
+
+#### **addParams**
+
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / addParams"
+
+ > Adds additional parameters to requests.
+
+ - Type: Object/Dictionary
+ - **Description**: Adds/Overrides parameters. Useful for specifying API-specific options.
+ - **Example**:
```yaml
- additionalHeaders:
- X-Custom-Header: ${YOUR_SECRET_CUSTOM_VARIABLE}
+ addParams:
+ safe_prompt: true
```
- - **Note**: It's recommended to use a custom env. variable reference for the values of field, as shown in the example.
- - **Note**: `api-key` header value is sent on every request
-#### **serverless**:
+#### **dropParams**
- > Indicates the use of a serverless inference endpoint for Azure OpenAI chat completions.
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / apiKey"
- - Type: Boolean
- - **Optional**
- - **Description**: When set to `true`, specifies that the group is configured to use serverless inference endpoints as an Azure "Models as a Service" model.
- - **Example**: `serverless: true`
- - **Note**: [More info here](./azure_openai.md#serverless-inference-endpoints)
+ > Removes [default parameters](#default-parameters) from requests.
-#### **addParams**:
+ - Type: Array/List of Strings
+ - **Description**: Excludes specified [default parameters](#default-parameters). Useful for APIs that do not accept or recognize certain parameters.
+ - **Example**: `dropParams: ["stop", "user", "frequency_penalty", "presence_penalty"]`
+ - **Note**: For a list of default parameters sent with every request, see the ["Default Parameters"](#default-parameters) Section below.
- > Adds additional parameters to requests.
+#### **forcePrompt**
- - Type: Object/Dictionary
- - **Description**: Adds/Overrides parameters. Useful for specifying API-specific options.
- - **Example**:
-```yaml
- addParams:
- safe_prompt: true
-```
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / forcePrompt"
-#### **dropParams**:
+ > If `true`, sends a `prompt` parameter instead of `messages`.
- > Removes [default parameters](#default-parameters) from requests.
+ - Type: Boolean
+ - Example: `forcePrompt: false`
+ - **Note**: This combines all messages into a single text payload, [following OpenAI format](https://github.com/pvicente/openai-python/blob/main/chatml.md), and uses the `/completions` endpoint of your baseURL rather than `/chat/completions`.
- - Type: Array/List of Strings
- - **Description**: Excludes specified [default parameters](#default-parameters). Useful for APIs that do not accept or recognize certain parameters.
- - **Example**: `dropParams: ["stop", "user", "frequency_penalty", "presence_penalty"]`
- - **Note**: For a list of default parameters sent with every request, see the ["Default Parameters"](#default-parameters) Section below.
+#### **models**
-#### **forcePrompt**:
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / models"
- > If `true`, sends a `prompt` parameter instead of `messages`.
+ > Configuration for individual models within a group.
- - Type: Boolean
- - Example: `forcePrompt: false`
- - **Note**: This combines all messages into a single text payload, [following OpenAI format](https://github.com/pvicente/openai-python/blob/main/chatml.md), and
+ - **Description**: Configures settings for each model, including deployment name and version. Model configurations can adopt the group's deployment name and/or version when configured as a boolean (set to `true`) or an object for detailed settings of either of those fields.
+ - **Example**: See above example configuration.
- uses the `/completions` endpoint of your baseURL rather than `/chat/completions`.
+ Within each group, models are records, either set to true, or set with a specific `deploymentName` and/or `version` where the key MUST be the matching OpenAI model name; for example, if you intend to use gpt-4-vision, it must be configured like so:
-#### **models**:
+ ```yaml
+ models:
+ gpt-4-vision-preview: # matching OpenAI Model name
+ deploymentName: "arbitrary-deployment-name"
+ version: "2024-02-15-preview" # version can be any that supports vision
+ ```
-> Configuration for individual models within a group.
+### Model Config Structure
-- **Description**: Configures settings for each model, including deployment name and version. Model configurations can adopt the group's deployment name and/or version when configured as a boolean (set to `true`) or an object for detailed settings of either of those fields.
-- **Example**: See above example configuration.
+Each item under `models` is part of a list of records, either a boolean value or Object:
-Within each group, models are records, either set to true, or set with a specific `deploymentName` and/or `version` where the key MUST be the matching OpenAI model name; for example, if you intend to use gpt-4-vision, it must be configured like so:
+**When specifying a model as an object:**
-```yaml
-models:
- gpt-4-vision-preview: # matching OpenAI Model name
- deploymentName: "arbitrary-deployment-name"
- version: "2024-02-15-preview" # version can be any that supports vision
-```
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / models / {model_item=Object}"
+
+ An object allows for detailed configuration of the model, including its `deploymentName` and/or `version`. This mode is used for more granular control over the models, especially when working with multiple versions or deployments under one instance or resource group.
+
+ **Example**:
+ ```yaml
+ models:
+ gpt-4-vision-preview:
+ deploymentName: "gpt-4-vision-preview"
+ version: "2024-02-15-preview"
+ ```
-### Model Configuration Parameters
+ Notes:
-#### **deploymentName**:
+ - **Deployment Names** and **Versions** are critical for ensuring that the correct model is used.
+ - Double-check these values for accuracy to prevent unexpected behavior.
-> The name of the deployment for the model.
+#### **deploymentName**
-- Type: String
-- **Required**
-- **Example**: `"gpt-4-vision-preview"`
-- **Description**: Identifies the deployment of the model within Azure.
-- **Note**: This does not have to be the matching OpenAI model name as is convention, but must match the actual name of your deployment on Azure.
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / models / {model_item=Object} / deploymentName"
-#### **version**:
+ > The name of the deployment for the model.
-> Specifies the version of the model.
+ - Type: String
+ - **Required**
+ - **Example**: `"gpt-4-vision-preview"`
+ - **Description**: Identifies the deployment of the model within Azure.
+ - **Note**: This does not have to be the matching OpenAI model name as is convention, but must match the actual name of your deployment on Azure.
-- Type: String
-- **Required**
-- **Example**: `"2024-02-15-preview"`
-- **Description**: Defines the version of the model to be used.
+#### **version**
+
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / models / {model_item=Object} / version"
+
+ > Specifies the version of the model.
+
+ - Type: String
+ - **Required**
+ - **Example**: `"2024-02-15-preview"`
+ - **Description**: Defines the version of the model to be used.
**When specifying a model as a boolean (`true`):**
-When a model is enabled (`true`) without using an object, it uses the group's configuration values for deployment name and version.
+!!! tip "endpoints / azureOpenAI / groups / {group_item} / models / {model_item=true}"
-**Example**:
-```yaml
-models:
- gpt-4-turbo: true
-```
+ When a model is enabled (`true`) without using an object, it uses the group's configuration values for deployment name and version.
-**When specifying a model as an object:**
+ **Example**:
+ ```yaml
+ models:
+ gpt-4-turbo: true
+ ```
-An object allows for detailed configuration of the model, including its `deploymentName` and/or `version`. This mode is used for more granular control over the models, especially when working with multiple versions or deployments under one instance or resource group.
+### Default Parameters
+
+Custom endpoints share logic with the OpenAI endpoint, and thus have default parameters tailored to the OpenAI API.
-**Example**:
-```yaml
-models:
- gpt-4-vision-preview:
- deploymentName: "gpt-4-vision-preview"
- version: "2024-02-15-preview"
+```json
+{
+ "model": "your-selected-model",
+ "temperature": 1,
+ "top_p": 1,
+ "presence_penalty": 0,
+ "frequency_penalty": 0,
+ "user": "LibreChat_User_ID",
+ "stream": true,
+ "messages": [
+ {
+ "role": "user",
+ "content": "hi how are you",
+ },
+ ],
+}
```
+#### Breakdown
+- `model`: The selected model from list of models.
+- `temperature`: Defaults to `1` if not provided via preset,
+- `top_p`: Defaults to `1` if not provided via preset,
+- `presence_penalty`: Defaults to `0` if not provided via preset,
+- `frequency_penalty`: Defaults to `0` if not provided via preset,
+- `user`: A unique identifier representing your end-user, which can help OpenAI to [monitor and detect abuse](https://platform.openai.com/docs/api-reference/chat/create#chat-create-user).
+- `stream`: If set, partial message deltas will be sent, like in ChatGPT. Otherwise, generation will only be available when completed.
+- `messages`: [OpenAI format for messages](https://platform.openai.com/docs/api-reference/chat/create#chat-create-messages); the `name` field is added to messages with `system` and `assistant` roles when a custom name is specified via preset.
-### Notes:
-- **Deployment Names** and **Versions** are critical for ensuring that the correct model is used. Double-check these values for accuracy to prevent unexpected behavior.
+**Note:** The `max_tokens` field is not sent to use the maximum amount of tokens available, which is default OpenAI API behavior. Some alternate APIs require this field, or it may default to a very low value and your responses may appear cut off; in this case, you should add it to `addParams` field as shown in the [Endpoint Object Structure](#endpoint-object-structure).
+
+### Additional Notes
+
+- Ensure that all URLs and keys are correctly specified to avoid connectivity issues.
diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.ts
index 97a0e32a3e..0d30d23051 100644
--- a/packages/data-provider/src/config.ts
+++ b/packages/data-provider/src/config.ts
@@ -3,6 +3,7 @@ import { z } from 'zod';
import type { ZodError } from 'zod';
import { EModelEndpoint, eModelEndpointSchema } from './schemas';
import { fileConfigSchema } from './file-config';
+import { specsConfigSchema } from './models';
import { FileSources } from './types/files';
import { TModelsConfig } from './types';
@@ -27,6 +28,39 @@ export enum SettingsViews {
export const fileSourceSchema = z.nativeEnum(FileSources);
+// Helper type to extract the shape of the Zod object schema
+type SchemaShape<T> = T extends z.ZodObject<infer U> ? U : never;
+
+// Helper type to determine the default value or undefined based on whether the field has a default
+type DefaultValue<T> = T extends z.ZodDefault<z.ZodTypeAny>
+ ? ReturnType<T['_def']['defaultValue']>
+ : undefined;
+
+// Extract default values or undefined from the schema shape
+type ExtractDefaults<T> = {
+ [P in keyof T]: DefaultValue<T[P]>;
+};
+
+export type SchemaDefaults<T> = ExtractDefaults<SchemaShape<T>>;
+
+export type TConfigDefaults = SchemaDefaults<typeof configSchema>;
+
+export function getSchemaDefaults<Schema extends z.AnyZodObject>(
+ schema: Schema,
+): ExtractDefaults<SchemaShape<Schema>> {
+ const shape = schema.shape;
+ const entries = Object.entries(shape).map(([key, value]) => {
+ if (value instanceof z.ZodDefault) {
+ // Extract default value if it exists
+ return [key, value._def.defaultValue()];
+ }
+ return [key, undefined];
+ });
+
+ // Create the object with the right types
+ return Object.fromEntries(entries) as ExtractDefaults<SchemaShape<Schema>>;
+}
+
export const modelConfigSchema = z
.object({
deploymentName: z.string().optional(),
@@ -200,9 +234,10 @@ export enum EImageOutputType {
export const configSchema = z.object({
version: z.string(),
- cache: z.boolean().optional().default(true),
+ cache: z.boolean().default(true),
secureImageLinks: z.boolean().optional(),
- imageOutputType: z.nativeEnum(EImageOutputType).optional().default(EImageOutputType.PNG),
+ imageOutputType: z.nativeEnum(EImageOutputType).default(EImageOutputType.PNG),
+ filteredTools: z.array(z.string()).optional(),
interface: z
.object({
privacyPolicy: z
@@ -217,17 +252,29 @@ export const configSchema = z.object({
openNewTab: z.boolean().optional(),
})
.optional(),
+ endpointsMenu: z.boolean().optional(),
+ modelSelect: z.boolean().optional(),
+ parameters: z.boolean().optional(),
+ sidePanel: z.boolean().optional(),
+ presets: z.boolean().optional(),
})
- .optional(),
- fileStrategy: fileSourceSchema.optional(),
+ .default({
+ endpointsMenu: true,
+ modelSelect: true,
+ parameters: true,
+ sidePanel: true,
+ presets: true,
+ }),
+ fileStrategy: fileSourceSchema.default(FileSources.local),
registration: z
.object({
socialLogins: z.array(z.string()).optional(),
allowedDomains: z.array(z.string()).optional(),
})
- .optional(),
+ .default({ socialLogins: defaultSocialLogins }),
rateLimits: rateLimitSchema.optional(),
fileConfig: fileConfigSchema.optional(),
+ modelSpecs: specsConfigSchema.optional(),
endpoints: z
.object({
[EModelEndpoint.azureOpenAI]: azureEndpointSchema.optional(),
@@ -241,6 +288,8 @@ export const configSchema = z.object({
.optional(),
});
+export const getConfigDefaults = () => getSchemaDefaults(configSchema);
+
export type TCustomConfig = z.infer<typeof configSchema>;
export enum KnownEndpoints {
@@ -605,32 +654,39 @@ export enum SettingsTabValues {
ACCOUNT = 'account',
}
-/**
- * Enum for app-wide constants
- */
+/** Enum for app-wide constants */
export enum Constants {
- /**
- * Key for the app's version.
- */
+ /** Key for the app's version. */
VERSION = 'v0.7.1',
- /**
- * Key for the Custom Config's version (librechat.yaml).
- */
- CONFIG_VERSION = '1.0.7',
- /**
- * Standard value for the first message's `parentMessageId` value, to indicate no parent exists.
- */
+ /** Key for the Custom Config's version (librechat.yaml). */
+ CONFIG_VERSION = '1.0.8',
+ /** Standard value for the first message's `parentMessageId` value, to indicate no parent exists. */
NO_PARENT = '00000000-0000-0000-0000-000000000000',
- /**
- * Fixed, encoded domain length for Azure OpenAI Assistants Function name parsing.
- */
+ /** Fixed, encoded domain length for Azure OpenAI Assistants Function name parsing. */
ENCODED_DOMAIN_LENGTH = 10,
- /**
- * Identifier for using current_model in multi-model requests.
- */
+ /** Identifier for using current_model in multi-model requests. */
CURRENT_MODEL = 'current_model',
}
+export enum LocalStorageKeys {
+ /** Key for the admin defined App Title */
+ APP_TITLE = 'appTitle',
+ /** Key for the last conversation setup. */
+ LAST_CONVO_SETUP = 'lastConversationSetup',
+ /** Key for the last BingAI Settings */
+ LAST_BING = 'lastBingSettings',
+ /** Key for the last selected model. */
+ LAST_MODEL = 'lastSelectedModel',
+ /** Key for the last selected tools. */
+ LAST_TOOLS = 'lastSelectedTools',
+ /** Key for the last selected spec by name*/
+ LAST_SPEC = 'lastSelectedSpec',
+ /** Key for temporary files to delete */
+ FILES_TO_DELETE = 'filesToDelete',
+ /** Prefix key for the last selected assistant ID by index */
+ ASST_ID_PREFIX = 'assistant_id__',
+}
+
/**
* Enum for Cohere related constants
*/
@@ -656,37 +712,3 @@ export enum CohereConstants {
*/
TITLE_MESSAGE = 'TITLE:',
}
-
-export const defaultOrderQuery: {
- order: 'desc';
- limit: 100;
-} = {
- order: 'desc',
- limit: 100,
-};
-
-export enum AssistantStreamEvents {
- ThreadCreated = 'thread.created',
- ThreadRunCreated = 'thread.run.created',
- ThreadRunQueued = 'thread.run.queued',
- ThreadRunInProgress = 'thread.run.in_progress',
- ThreadRunRequiresAction = 'thread.run.requires_action',
- ThreadRunCompleted = 'thread.run.completed',
- ThreadRunFailed = 'thread.run.failed',
- ThreadRunCancelling = 'thread.run.cancelling',
- ThreadRunCancelled = 'thread.run.cancelled',
- ThreadRunExpired = 'thread.run.expired',
- ThreadRunStepCreated = 'thread.run.step.created',
- ThreadRunStepInProgress = 'thread.run.step.in_progress',
- ThreadRunStepCompleted = 'thread.run.step.completed',
- ThreadRunStepFailed = 'thread.run.step.failed',
- ThreadRunStepCancelled = 'thread.run.step.cancelled',
- ThreadRunStepExpired = 'thread.run.step.expired',
- ThreadRunStepDelta = 'thread.run.step.delta',
- ThreadMessageCreated = 'thread.message.created',
- ThreadMessageInProgress = 'thread.message.in_progress',
- ThreadMessageCompleted = 'thread.message.completed',
- ThreadMessageIncomplete = 'thread.message.incomplete',
- ThreadMessageDelta = 'thread.message.delta',
- ErrorEvent = 'error',
-}
diff --git a/packages/data-provider/src/index.ts b/packages/data-provider/src/index.ts
index 50b51bd547..c18a2ee98f 100644
--- a/packages/data-provider/src/index.ts
+++ b/packages/data-provider/src/index.ts
@@ -4,6 +4,8 @@ export * from './config';
export * from './file-config';
/* schema helpers */
export * from './parsers';
+/* custom/dynamic configurations */
+export * from './models';
export * from './generate';
/* types (exports schemas from `./types` as they contain needed in other defs) */
export * from './types';
diff --git a/packages/data-provider/src/models.ts b/packages/data-provider/src/models.ts
new file mode 100644
index 0000000000..c8650b0400
--- /dev/null
+++ b/packages/data-provider/src/models.ts
@@ -0,0 +1,43 @@
+import { z } from 'zod';
+import type { TPreset } from './schemas';
+import {
+ EModelEndpoint,
+ tPresetSchema,
+ eModelEndpointSchema,
+ AuthType,
+ authTypeSchema,
+} from './schemas';
+
+export type TModelSpec = {
+ name: string;
+ label: string;
+ preset: TPreset;
+ order?: number;
+ default?: boolean;
+ description?: string;
+ showIconInMenu?: boolean;
+ showIconInHeader?: boolean;
+ iconURL?: string | EModelEndpoint; // Allow using project-included icons
+ authType?: AuthType;
+};
+
+export const tModelSpecSchema = z.object({
+ name: z.string(),
+ label: z.string(),
+ preset: tPresetSchema,
+ order: z.number().optional(),
+ default: z.boolean().optional(),
+ description: z.string().optional(),
+ showIconInMenu: z.boolean().optional(),
+ showIconInHeader: z.boolean().optional(),
+ iconURL: z.union([z.string(), eModelEndpointSchema]).optional(),
+ authType: authTypeSchema.optional(),
+});
+
+export const specsConfigSchema = z.object({
+ enforce: z.boolean().default(false),
+ prioritize: z.boolean().default(true),
+ list: z.array(tModelSpecSchema).optional(),
+});
+
+export type TSpecsConfig = z.infer<typeof specsConfigSchema>;
diff --git a/packages/data-provider/src/parsers.ts b/packages/data-provider/src/parsers.ts
index 2f1ba02468..72f20a063a 100644
--- a/packages/data-provider/src/parsers.ts
+++ b/packages/data-provider/src/parsers.ts
@@ -15,6 +15,7 @@ import {
compactAnthropicSchema,
compactChatGPTSchema,
compactPluginsSchema,
+ compactAssistantSchema,
} from './schemas';
import { alternateName } from './config';
@@ -260,7 +261,7 @@ export const getResponseSender = (endpointOption: TEndpointOption): string => {
type CompactEndpointSchema =
| typeof compactOpenAISchema
- | typeof assistantSchema
+ | typeof compactAssistantSchema
| typeof compactGoogleSchema
| typeof bingAISchema
| typeof compactAnthropicSchema
@@ -271,7 +272,7 @@ const compactEndpointSchemas: Record<string, CompactEndpointSchema> = {
[EModelEndpoint.openAI]: compactOpenAISchema,
[EModelEndpoint.azureOpenAI]: compactOpenAISchema,
[EModelEndpoint.custom]: compactOpenAISchema,
- [EModelEndpoint.assistants]: assistantSchema,
+ [EModelEndpoint.assistants]: compactAssistantSchema,
[EModelEndpoint.google]: compactGoogleSchema,
/* BingAI needs all fields */
[EModelEndpoint.bingAI]: bingAISchema,
diff --git a/packages/data-provider/src/react-query/react-query-service.ts b/packages/data-provider/src/react-query/react-query-service.ts
index 9787d84408..bb898939ea 100644
--- a/packages/data-provider/src/react-query/react-query-service.ts
+++ b/packages/data-provider/src/react-query/react-query-service.ts
@@ -6,7 +6,8 @@ import {
UseMutationResult,
QueryObserverResult,
} from '@tanstack/react-query';
-import { defaultOrderQuery, initialModelsConfig } from '../config';
+import { defaultOrderQuery } from '../types/assistants';
+import { initialModelsConfig, LocalStorageKeys } from '../config';
import * as dataService from '../data-service';
import * as m from '../types/mutations';
import { QueryKeys } from '../keys';
@@ -289,10 +290,10 @@ export const useLoginUserMutation = (): UseMutationResult<
return useMutation((payload: t.TLoginUser) => dataService.login(payload), {
onMutate: () => {
queryClient.removeQueries();
- localStorage.removeItem('lastConversationSetup');
- localStorage.removeItem('lastSelectedModel');
- localStorage.removeItem('lastSelectedTools');
- localStorage.removeItem('filesToDelete');
+ localStorage.removeItem(LocalStorageKeys.LAST_CONVO_SETUP);
+ localStorage.removeItem(LocalStorageKeys.LAST_MODEL);
+ localStorage.removeItem(LocalStorageKeys.LAST_TOOLS);
+ localStorage.removeItem(LocalStorageKeys.FILES_TO_DELETE);
// localStorage.removeItem('lastAssistant');
},
});
@@ -368,14 +369,17 @@ export const useResetPasswordMutation = (): UseMutationResult<
return useMutation((payload: t.TResetPassword) => dataService.resetPassword(payload));
};
-export const useAvailablePluginsQuery = (): QueryObserverResult<s.TPlugin[]> => {
- return useQuery<s.TPlugin[]>(
+export const useAvailablePluginsQuery = <TData = s.TPlugin[]>(
+ config?: UseQueryOptions<s.TPlugin[], unknown, TData>,
+): QueryObserverResult<TData> => {
+ return useQuery<s.TPlugin[], unknown, TData>(
[QueryKeys.availablePlugins],
() => dataService.getAvailablePlugins(),
{
refetchOnWindowFocus: false,
refetchOnReconnect: false,
refetchOnMount: false,
+ ...config,
},
);
};
diff --git a/packages/data-provider/src/schemas.ts b/packages/data-provider/src/schemas.ts
index 4d9c793d36..7ca011404c 100644
--- a/packages/data-provider/src/schemas.ts
+++ b/packages/data-provider/src/schemas.ts
@@ -5,6 +5,14 @@ import type { TFile } from './types/files';
export const isUUID = z.string().uuid();
+export enum AuthType {
+ OVERRIDE_AUTH = 'override_auth',
+ USER_PROVIDED = 'user_provided',
+ SYSTEM_DEFINED = 'SYSTEM_DEFINED',
+}
+
+export const authTypeSchema = z.nativeEnum(AuthType);
+
export enum EModelEndpoint {
azureOpenAI = 'azureOpenAI',
openAI = 'openAI',
@@ -190,11 +198,37 @@ export const tExampleSchema = z.object({
export type TExample = z.infer<typeof tExampleSchema>;
+export enum EAgent {
+ functions = 'functions',
+ classic = 'classic',
+}
+
+export const agentOptionSettings = {
+ model: {
+ default: 'gpt-4-turbo',
+ },
+ temperature: {
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: 0,
+ },
+ agent: {
+ default: EAgent.functions,
+ options: [EAgent.functions, EAgent.classic],
+ },
+ skipCompletion: {
+ default: true,
+ },
+};
+
+export const eAgentOptionsSchema = z.nativeEnum(EAgent);
+
export const tAgentOptionsSchema = z.object({
- agent: z.string(),
- skipCompletion: z.boolean(),
+ agent: z.string().default(EAgent.functions),
+ skipCompletion: z.boolean().default(agentOptionSettings.skipCompletion.default),
model: z.string(),
- temperature: z.number(),
+ temperature: z.number().default(agentOptionSettings.temperature.default),
});
export const tMessageSchema = z.object({
@@ -228,6 +262,8 @@ export const tMessageSchema = z.object({
finish_reason: z.string().optional(),
/* assistant */
thread_id: z.string().optional(),
+ /* frontend components */
+ iconURL: z.string().optional(),
});
export type TMessage = z.input<typeof tMessageSchema> & {
@@ -246,7 +282,7 @@ export const tConversationSchema = z.object({
endpointType: eModelEndpointSchema.optional(),
suggestions: z.array(z.string()).optional(),
messages: z.array(z.string()).optional(),
- tools: z.array(tPluginSchema).optional(),
+ tools: z.union([z.array(tPluginSchema), z.array(z.string())]).optional(),
createdAt: z.string(),
updatedAt: z.string(),
systemMessage: z.string().nullable().optional(),
@@ -284,6 +320,10 @@ export const tConversationSchema = z.object({
/** Used to overwrite active conversation settings when saving a Preset */
presetOverride: z.record(z.unknown()).optional(),
stop: z.array(z.string()).optional(),
+ /* frontend components */
+ iconURL: z.string().optional(),
+ greeting: z.string().optional(),
+ spec: z.string().optional(),
});
export const tPresetSchema = tConversationSchema
@@ -329,6 +369,7 @@ export type TConversation = z.infer<typeof tConversationSchema> & {
export const openAISchema = tConversationSchema
.pick({
model: true,
+ modelLabel: true,
chatGptLabel: true,
promptPrefix: true,
temperature: true,
@@ -338,11 +379,14 @@ export const openAISchema = tConversationSchema
resendFiles: true,
imageDetail: true,
stop: true,
+ iconURL: true,
+ greeting: true,
+ spec: true,
})
.transform((obj) => ({
...obj,
model: obj.model ?? openAISettings.model.default,
- chatGptLabel: obj.chatGptLabel ?? null,
+ chatGptLabel: obj.modelLabel ?? obj.chatGptLabel ?? null,
promptPrefix: obj.promptPrefix ?? null,
temperature: obj.temperature ?? openAISettings.temperature.default,
top_p: obj.top_p ?? openAISettings.top_p.default,
@@ -352,6 +396,9 @@ export const openAISchema = tConversationSchema
typeof obj.resendFiles === 'boolean' ? obj.resendFiles : openAISettings.resendFiles.default,
imageDetail: obj.imageDetail ?? openAISettings.imageDetail.default,
stop: obj.stop ?? undefined,
+ iconURL: obj.iconURL ?? undefined,
+ greeting: obj.greeting ?? undefined,
+ spec: obj.spec ?? undefined,
}))
.catch(() => ({
model: openAISettings.model.default,
@@ -364,6 +411,9 @@ export const openAISchema = tConversationSchema
resendFiles: openAISettings.resendFiles.default,
imageDetail: openAISettings.imageDetail.default,
stop: undefined,
+ iconURL: undefined,
+ greeting: undefined,
+ spec: undefined,
}));
export const googleSchema = tConversationSchema
@@ -376,6 +426,9 @@ export const googleSchema = tConversationSchema
maxOutputTokens: true,
topP: true,
topK: true,
+ iconURL: true,
+ greeting: true,
+ spec: true,
})
.transform((obj) => {
const isGemini = obj?.model?.toLowerCase()?.includes('gemini');
@@ -400,6 +453,9 @@ export const googleSchema = tConversationSchema
maxOutputTokens,
topP: obj.topP ?? google.topP.default,
topK: obj.topK ?? google.topK.default,
+ iconURL: obj.iconURL ?? undefined,
+ greeting: obj.greeting ?? undefined,
+ spec: obj.spec ?? undefined,
};
})
.catch(() => ({
@@ -411,6 +467,9 @@ export const googleSchema = tConversationSchema
maxOutputTokens: google.maxOutputTokens.default,
topP: google.topP.default,
topK: google.topK.default,
+ iconURL: undefined,
+ greeting: undefined,
+ spec: undefined,
}));
export const bingAISchema = tConversationSchema
@@ -458,6 +517,9 @@ export const anthropicSchema = tConversationSchema
topP: true,
topK: true,
resendFiles: true,
+ iconURL: true,
+ greeting: true,
+ spec: true,
})
.transform((obj) => ({
...obj,
@@ -469,6 +531,9 @@ export const anthropicSchema = tConversationSchema
topP: obj.topP ?? 0.7,
topK: obj.topK ?? 5,
resendFiles: typeof obj.resendFiles === 'boolean' ? obj.resendFiles : true,
+ iconURL: obj.iconURL ?? undefined,
+ greeting: obj.greeting ?? undefined,
+ spec: obj.spec ?? undefined,
}))
.catch(() => ({
model: 'claude-1',
@@ -479,6 +544,9 @@ export const anthropicSchema = tConversationSchema
topP: 0.7,
topK: 5,
resendFiles: true,
+ iconURL: undefined,
+ greeting: undefined,
+ spec: undefined,
}));
export const chatGPTBrowserSchema = tConversationSchema
@@ -496,6 +564,7 @@ export const chatGPTBrowserSchema = tConversationSchema
export const gptPluginsSchema = tConversationSchema
.pick({
model: true,
+ modelLabel: true,
chatGptLabel: true,
promptPrefix: true,
temperature: true,
@@ -504,11 +573,14 @@ export const gptPluginsSchema = tConversationSchema
frequency_penalty: true,
tools: true,
agentOptions: true,
+ iconURL: true,
+ greeting: true,
+ spec: true,
})
.transform((obj) => ({
...obj,
model: obj.model ?? 'gpt-3.5-turbo',
- chatGptLabel: obj.chatGptLabel ?? null,
+ chatGptLabel: obj.modelLabel ?? obj.chatGptLabel ?? null,
promptPrefix: obj.promptPrefix ?? null,
temperature: obj.temperature ?? 0.8,
top_p: obj.top_p ?? 1,
@@ -516,11 +588,14 @@ export const gptPluginsSchema = tConversationSchema
frequency_penalty: obj.frequency_penalty ?? 0,
tools: obj.tools ?? [],
agentOptions: obj.agentOptions ?? {
- agent: 'functions',
+ agent: EAgent.functions,
skipCompletion: true,
model: 'gpt-3.5-turbo',
temperature: 0,
},
+ iconURL: obj.iconURL ?? undefined,
+ greeting: obj.greeting ?? undefined,
+ spec: obj.spec ?? undefined,
}))
.catch(() => ({
model: 'gpt-3.5-turbo',
@@ -532,11 +607,14 @@ export const gptPluginsSchema = tConversationSchema
frequency_penalty: 0,
tools: [],
agentOptions: {
- agent: 'functions',
+ agent: EAgent.functions,
skipCompletion: true,
model: 'gpt-3.5-turbo',
temperature: 0,
},
+ iconURL: undefined,
+ greeting: undefined,
+ spec: undefined,
}));
export function removeNullishValues<T extends object>(obj: T): T {
@@ -557,7 +635,41 @@ export const assistantSchema = tConversationSchema
assistant_id: true,
instructions: true,
promptPrefix: true,
+ iconURL: true,
+ greeting: true,
+ spec: true,
+ })
+ .transform((obj) => ({
+ ...obj,
+ model: obj.model ?? openAISettings.model.default,
+ assistant_id: obj.assistant_id ?? undefined,
+ instructions: obj.instructions ?? undefined,
+ promptPrefix: obj.promptPrefix ?? null,
+ iconURL: obj.iconURL ?? undefined,
+ greeting: obj.greeting ?? undefined,
+ spec: obj.spec ?? undefined,
+ }))
+ .catch(() => ({
+ model: openAISettings.model.default,
+ assistant_id: undefined,
+ instructions: undefined,
+ promptPrefix: null,
+ iconURL: undefined,
+ greeting: undefined,
+ spec: undefined,
+ }));
+
+export const compactAssistantSchema = tConversationSchema
+ .pick({
+ model: true,
+ assistant_id: true,
+ instructions: true,
+ promptPrefix: true,
+ iconURL: true,
+ greeting: true,
+ spec: true,
})
+ // will change after adding temperature
.transform(removeNullishValues)
.catch(() => ({}));
@@ -573,6 +685,9 @@ export const compactOpenAISchema = tConversationSchema
resendFiles: true,
imageDetail: true,
stop: true,
+ iconURL: true,
+ greeting: true,
+ spec: true,
})
.transform((obj: Partial<TConversation>) => {
const newObj: Partial<TConversation> = { ...obj };
@@ -609,6 +724,9 @@ export const compactGoogleSchema = tConversationSchema
maxOutputTokens: true,
topP: true,
topK: true,
+ iconURL: true,
+ greeting: true,
+ spec: true,
})
.transform((obj) => {
const newObj: Partial<TConversation> = { ...obj };
@@ -639,6 +757,9 @@ export const compactAnthropicSchema = tConversationSchema
topP: true,
topK: true,
resendFiles: true,
+ iconURL: true,
+ greeting: true,
+ spec: true,
})
.transform((obj) => {
const newObj: Partial<TConversation> = { ...obj };
@@ -683,6 +804,9 @@ export const compactPluginsSchema = tConversationSchema
frequency_penalty: true,
tools: true,
agentOptions: true,
+ iconURL: true,
+ greeting: true,
+ spec: true,
})
.transform((obj) => {
const newObj: Partial<TConversation> = { ...obj };
@@ -710,7 +834,7 @@ export const compactPluginsSchema = tConversationSchema
if (
newObj.agentOptions &&
- newObj.agentOptions.agent === 'functions' &&
+ newObj.agentOptions.agent === EAgent.functions &&
newObj.agentOptions.skipCompletion === true &&
newObj.agentOptions.model === 'gpt-3.5-turbo' &&
newObj.agentOptions.temperature === 0
diff --git a/packages/data-provider/src/types.ts b/packages/data-provider/src/types.ts
index bb0c4d4a31..a7b2196bf4 100644
--- a/packages/data-provider/src/types.ts
+++ b/packages/data-provider/src/types.ts
@@ -1,6 +1,6 @@
import OpenAI from 'openai';
import type { TResPlugin, TMessage, TConversation, EModelEndpoint, ImageDetail } from './schemas';
-
+import type { TSpecsConfig } from './models';
export type TOpenAIMessage = OpenAI.Chat.ChatCompletionMessageParam;
export type TOpenAIFunction = OpenAI.Chat.ChatCompletionCreateParams.Function;
export type TOpenAIFunctionCall = OpenAI.Chat.ChatCompletionCreateParams.FunctionCallOption;
@@ -204,6 +204,11 @@ export type TInterfaceConfig = {
externalUrl?: string;
openNewTab?: boolean;
};
+ endpointsMenu: boolean;
+ modelSelect: boolean;
+ parameters: boolean;
+ sidePanel: boolean;
+ presets: boolean;
};
export type TStartupConfig = {
@@ -226,6 +231,7 @@ export type TStartupConfig = {
showBirthdayIcon: boolean;
helpAndFaqURL: string;
customFooter?: string;
+ modelSpecs?: TSpecsConfig;
};
export type TRefreshTokenResponse = {
diff --git a/packages/data-provider/src/types/assistants.ts b/packages/data-provider/src/types/assistants.ts
index 79fda6e6a9..76017f4413 100644
--- a/packages/data-provider/src/types/assistants.ts
+++ b/packages/data-provider/src/types/assistants.ts
@@ -339,3 +339,37 @@ export enum FilePurpose {
Assistants = 'assistants',
AssistantsOutput = 'assistants_output',
}
+
+export const defaultOrderQuery: {
+ order: 'desc';
+ limit: 100;
+} = {
+ order: 'desc',
+ limit: 100,
+};
+
+export enum AssistantStreamEvents {
+ ThreadCreated = 'thread.created',
+ ThreadRunCreated = 'thread.run.created',
+ ThreadRunQueued = 'thread.run.queued',
+ ThreadRunInProgress = 'thread.run.in_progress',
+ ThreadRunRequiresAction = 'thread.run.requires_action',
+ ThreadRunCompleted = 'thread.run.completed',
+ ThreadRunFailed = 'thread.run.failed',
+ ThreadRunCancelling = 'thread.run.cancelling',
+ ThreadRunCancelled = 'thread.run.cancelled',
+ ThreadRunExpired = 'thread.run.expired',
+ ThreadRunStepCreated = 'thread.run.step.created',
+ ThreadRunStepInProgress = 'thread.run.step.in_progress',
+ ThreadRunStepCompleted = 'thread.run.step.completed',
+ ThreadRunStepFailed = 'thread.run.step.failed',
+ ThreadRunStepCancelled = 'thread.run.step.cancelled',
+ ThreadRunStepExpired = 'thread.run.step.expired',
+ ThreadRunStepDelta = 'thread.run.step.delta',
+ ThreadMessageCreated = 'thread.message.created',
+ ThreadMessageInProgress = 'thread.message.in_progress',
+ ThreadMessageCompleted = 'thread.message.completed',
+ ThreadMessageIncomplete = 'thread.message.incomplete',
+ ThreadMessageDelta = 'thread.message.delta',
+ ErrorEvent = 'error',
+}