mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-22 10:16:13 +01:00
🐛 fix: Resolve 'Icon is Not a Function' Error in PresetItems (#5260)
* refactor: improve typing * fix: "TypeError: Icon is not a function" with proper use of Functional Component and Improved Typing
This commit is contained in:
parent
0855677a36
commit
24beda3d69
6 changed files with 57 additions and 49 deletions
|
|
@ -7,7 +7,7 @@ import {
|
|||
isAssistantsEndpoint,
|
||||
} from 'librechat-data-provider';
|
||||
import type * as t from 'librechat-data-provider';
|
||||
import type { LocalizeFunction } from '~/common';
|
||||
import type { LocalizeFunction, IconsRecord } from '~/common';
|
||||
|
||||
export const getEntityName = ({
|
||||
name = '',
|
||||
|
|
@ -222,7 +222,7 @@ export function getIconKey({
|
|||
endpointsConfig?: t.TEndpointsConfig;
|
||||
endpointType?: string | null;
|
||||
endpointIconURL?: string;
|
||||
}) {
|
||||
}): keyof IconsRecord {
|
||||
const endpointType = _eType ?? getEndpointField(endpointsConfig, endpoint, 'type') ?? '';
|
||||
const endpointIconURL = iconURL ?? getEndpointField(endpointsConfig, endpoint, 'iconURL') ?? '';
|
||||
if (endpointIconURL && EModelEndpoint[endpointIconURL] != null) {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,6 @@
|
|||
import type { TPreset, TPlugin } from 'librechat-data-provider';
|
||||
import { EModelEndpoint } from 'librechat-data-provider';
|
||||
|
||||
export const getPresetIcon = (preset: TPreset, Icon) => {
|
||||
return Icon({
|
||||
size: 20,
|
||||
endpoint: preset?.endpoint,
|
||||
model: preset?.model,
|
||||
error: false,
|
||||
className: 'icon-md',
|
||||
isCreatedByUser: false,
|
||||
});
|
||||
};
|
||||
|
||||
type TEndpoints = Array<string | EModelEndpoint>;
|
||||
|
||||
export const getPresetTitle = (preset: TPreset, mention?: boolean) => {
|
||||
|
|
@ -27,7 +16,7 @@ export const getPresetTitle = (preset: TPreset, mention?: boolean) => {
|
|||
toneStyle,
|
||||
} = preset;
|
||||
let title = '';
|
||||
let modelInfo = model || '';
|
||||
let modelInfo = model ?? '';
|
||||
let label = '';
|
||||
|
||||
const usesChatGPTLabel: TEndpoints = [
|
||||
|
|
@ -37,24 +26,31 @@ export const getPresetTitle = (preset: TPreset, mention?: boolean) => {
|
|||
];
|
||||
const usesModelLabel: TEndpoints = [EModelEndpoint.google, EModelEndpoint.anthropic];
|
||||
|
||||
if (endpoint && usesChatGPTLabel.includes(endpoint)) {
|
||||
label = chatGptLabel || '';
|
||||
} else if (endpoint && usesModelLabel.includes(endpoint)) {
|
||||
label = modelLabel || '';
|
||||
if (endpoint != null && endpoint && usesChatGPTLabel.includes(endpoint)) {
|
||||
label = chatGptLabel ?? '';
|
||||
} else if (endpoint != null && endpoint && usesModelLabel.includes(endpoint)) {
|
||||
label = modelLabel ?? '';
|
||||
} else if (endpoint === EModelEndpoint.bingAI) {
|
||||
modelInfo = jailbreak ? 'Sydney' : modelInfo;
|
||||
label = toneStyle ? `: ${toneStyle}` : '';
|
||||
modelInfo = jailbreak === true ? 'Sydney' : modelInfo;
|
||||
label = toneStyle != null && toneStyle ? `: ${toneStyle}` : '';
|
||||
}
|
||||
|
||||
if (label && presetTitle && label.toLowerCase().includes(presetTitle.toLowerCase())) {
|
||||
if (
|
||||
label &&
|
||||
presetTitle != null &&
|
||||
presetTitle &&
|
||||
label.toLowerCase().includes(presetTitle.toLowerCase())
|
||||
) {
|
||||
title = label + ': ';
|
||||
label = '';
|
||||
} else if (presetTitle && presetTitle.trim() !== 'New Chat') {
|
||||
} else if (presetTitle != null && presetTitle && presetTitle.trim() !== 'New Chat') {
|
||||
title = presetTitle + ': ';
|
||||
}
|
||||
|
||||
if (mention) {
|
||||
return `${modelInfo}${label ? ` | ${label}` : ''}${promptPrefix ? ` | ${promptPrefix}` : ''}${
|
||||
if (mention === true) {
|
||||
return `${modelInfo}${label ? ` | ${label}` : ''}${
|
||||
promptPrefix != null && promptPrefix ? ` | ${promptPrefix}` : ''
|
||||
}${
|
||||
tools
|
||||
? ` | ${tools
|
||||
.map((tool: TPlugin | string) => {
|
||||
|
|
@ -74,7 +70,7 @@ export const getPresetTitle = (preset: TPreset, mention?: boolean) => {
|
|||
/** Remove unavailable tools from the preset */
|
||||
export const removeUnavailableTools = (
|
||||
preset: TPreset,
|
||||
availableTools: Record<string, TPlugin>,
|
||||
availableTools: Record<string, TPlugin | undefined>,
|
||||
) => {
|
||||
const newPreset = { ...preset };
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue