mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-06 02:28:51 +01:00
* chore: remove all bing code * chore: remove bing code and auto-focus effects * chore: add back escapeRegExp helper function for regex special character handling * chore: remove deprecated fields from settings and conversation schema * fix: ensure default endpoint is set correctly in conversation setup * feat: add disableFocus option to newConversation for improved search behavior
92 lines
2.3 KiB
TypeScript
92 lines
2.3 KiB
TypeScript
import type { TPreset, TPlugin } from 'librechat-data-provider';
|
|
import { EModelEndpoint } from 'librechat-data-provider';
|
|
|
|
type TEndpoints = Array<string | EModelEndpoint>;
|
|
|
|
export const getPresetTitle = (preset: TPreset, mention?: boolean) => {
|
|
const {
|
|
endpoint,
|
|
title: presetTitle,
|
|
model,
|
|
tools,
|
|
promptPrefix,
|
|
chatGptLabel,
|
|
modelLabel,
|
|
} = preset;
|
|
const modelInfo = model ?? '';
|
|
let title = '';
|
|
let label = '';
|
|
|
|
const usesChatGPTLabel: TEndpoints = [
|
|
EModelEndpoint.azureOpenAI,
|
|
EModelEndpoint.openAI,
|
|
EModelEndpoint.custom,
|
|
];
|
|
const usesModelLabel: TEndpoints = [EModelEndpoint.google, EModelEndpoint.anthropic];
|
|
|
|
if (endpoint != null && endpoint && usesChatGPTLabel.includes(endpoint)) {
|
|
label = chatGptLabel ?? '';
|
|
} else if (endpoint != null && endpoint && usesModelLabel.includes(endpoint)) {
|
|
label = modelLabel ?? '';
|
|
}
|
|
if (
|
|
label &&
|
|
presetTitle != null &&
|
|
presetTitle &&
|
|
label.toLowerCase().includes(presetTitle.toLowerCase())
|
|
) {
|
|
title = label + ': ';
|
|
label = '';
|
|
} else if (presetTitle != null && presetTitle && presetTitle.trim() !== 'New Chat') {
|
|
title = presetTitle + ': ';
|
|
}
|
|
|
|
if (mention === true) {
|
|
return `${modelInfo}${label ? ` | ${label}` : ''}${
|
|
promptPrefix != null && promptPrefix ? ` | ${promptPrefix}` : ''
|
|
}${
|
|
tools
|
|
? ` | ${tools
|
|
.map((tool: TPlugin | string) => {
|
|
if (typeof tool === 'string') {
|
|
return tool;
|
|
}
|
|
return tool.pluginKey;
|
|
})
|
|
.join(', ')}`
|
|
: ''
|
|
}`;
|
|
}
|
|
|
|
return `${title}${modelInfo}${label ? ` (${label})` : ''}`.trim();
|
|
};
|
|
|
|
/** Remove unavailable tools from the preset */
|
|
export const removeUnavailableTools = (
|
|
preset: TPreset,
|
|
availableTools: Record<string, TPlugin | undefined>,
|
|
) => {
|
|
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;
|
|
};
|