LibreChat/client/src/utils/getIcon.jsx

102 lines
3.1 KiB
React
Raw Normal View History

2023-03-31 01:41:41 +08:00
import { clsx } from 'clsx';
import React from 'react';
import { twMerge } from 'tailwind-merge';
import GPTIcon from '../components/svg/GPTIcon';
import BingIcon from '../components/svg/BingIcon';
import { useAuthContext } from '~/hooks/AuthContext';
2023-03-31 01:41:41 +08:00
const getIcon = (props) => {
2023-03-31 01:41:41 +08:00
// { size = 30, isCreatedByUser, model, chatGptLabel, error, ...props }
const { size = 30, isCreatedByUser, button, model } = props;
const { user, logout } = useAuthContext();
2023-03-31 01:41:41 +08:00
if (isCreatedByUser)
return (
<div
title={user.name}
2023-03-31 01:41:41 +08:00
style={{
width: size,
height: size
}}
className={`relative flex items-center justify-center` + props?.className}
2023-03-31 01:41:41 +08:00
>
<img
className="rounded-sm"
src={
user?.avatar ||
`https://api.dicebear.com/6.x/initials/svg?seed=${user?.name}&fontFamily=Verdana&fontSize=36`
}
alt="avatar"
/>
2023-03-31 01:41:41 +08:00
</div>
);
else if (!isCreatedByUser) {
const { endpoint, error } = props;
2023-03-31 03:22:57 +08:00
let icon, bg, name;
2023-03-31 01:41:41 +08:00
if (endpoint === 'azureOpenAI') {
const { chatGptLabel } = props;
icon = <GPTIcon size={size * 0.7} />;
bg = 'linear-gradient(0.375turn, #61bde2, #4389d0)';
name = chatGptLabel || 'ChatGPT';
} else if (endpoint === 'openAI') {
const { chatGptLabel } = props;
icon = <GPTIcon size={size * 0.7} />;
bg =
model && model.toLowerCase().startsWith('gpt-4')
? '#AB68FF'
: chatGptLabel
? `rgba(16, 163, 127, ${button ? 0.75 : 1})`
: `rgba(16, 163, 127, ${button ? 0.75 : 1})`;
2023-03-31 01:41:41 +08:00
name = chatGptLabel || 'ChatGPT';
Feat: PaLM 2 (#262) * feat(api): add googleapis package to package.json feat(api): add reqDemo.js file to make a request to Google Cloud AI Platform API to get a response from a chatbot model. * feat: add PaLM2 support * feat(conversationPreset.js): add support for topP and topK for google endpoint feat(askGoogle.js): add support for topP and topK for google endpoint feat(ask/index.js): add google endpoint feat(endpoints.js): add google endpoint feat(MessageHeader.jsx): add support for modelLabel for google endpoint feat(PresetItem.jsx): add support for modelLabel for google endpoint feat(HoverButtons.jsx): add support for google endpoint feat(createPayload.ts): add google endpoint feat(types.ts): add google endpoint feat(store/endpoints.js): add google endpoint feat(cleanupPreset.js): add support for topP and topK for google endpoint feat(getDefaultConversation.js): add support for topP and topK for google endpoint feat(handleSubmit.js): add support for topP and topK for google endpoint * fix: messages payload * refactor(GoogleClient.js): set maxContextTokens based on isTextModel value feat(GoogleClient.js): add delay option to TextStream constructor feat(getIcon.jsx): add support for google endpoint and PaLM2 model label * feat: palm frontend changes * feat(askGoogle.js): set default example to empty input and output feat(Examples.jsx): add ability to add and remove examples refactor(Settings.jsx): remove examples from props and setOption function style(GoogleOptions): remove unnecessary whitespace after Settings2 import feat(GoogleOptions): add addExample and removeExample functions to manage examples fix(cleanupPreset): set default example to [{ input: '', output: ''}] fix(getDefaultConversation): set default example to [{ input: '', output: ''}] fix(handleSubmit): set default example to [{ input: '', output: ''}] * style(client): adjust height of settings and examples components to 350px fix(client): fix path to palm.png image in getIcon.jsx file * style(EndpointOptionsPopover.jsx, Examples.jsx, Settings.jsx): improve button styles and update input placeholders * feat (palm): finalize examples on the frontend * feat(GoogleClient.js): filter out empty examples in options feat(GoogleClient.js): add support for promptPrefix in buildPayload method feat(GoogleClient.js): add support for examples in buildPayload method feat(conversationPreset.js): add maxOutputTokens field to conversation preset schema feat(presetSchema.js): add examples field to preset schema feat(askGoogle.js): add support for examples and promptPrefix in endpointOption feat(EditPresetDialog.jsx): add Examples component for Google endpoint feat(EditPresetDialog.jsx): add button to show/hide Examples component feat(EditPresetDialog.jsx): add functionality to add, remove, and edit examples in Examples component feat(EndpointOptionsDialog.jsx): change endpoint name to PaLM for Google endpoint feat(Settings.jsx): add maxHeight prop to limit height of Settings component in EditPresetDialog and EndpointOptionsDialog fix(Settings.jsx): add examples prop to ChatGPTBrowser component fix(EndpointItem.jsx): add alternate name for google endpoint fix(MessageHeader.jsx): change title for google endpoint to PaLM feat(endpoints.js): add google endpoint to endpointsConfig fix(cleanupPreset.js): add missing comma in examples array * chore: change endpoint order * feat(PaLM 2): complete for testing * fix(PaLM): handle blocked messages
2023-05-13 16:29:06 -04:00
} else if (endpoint === 'google') {
const { modelLabel } = props;
icon = <img src="/assets/palm.png" />;
Feat: PaLM 2 (#262) * feat(api): add googleapis package to package.json feat(api): add reqDemo.js file to make a request to Google Cloud AI Platform API to get a response from a chatbot model. * feat: add PaLM2 support * feat(conversationPreset.js): add support for topP and topK for google endpoint feat(askGoogle.js): add support for topP and topK for google endpoint feat(ask/index.js): add google endpoint feat(endpoints.js): add google endpoint feat(MessageHeader.jsx): add support for modelLabel for google endpoint feat(PresetItem.jsx): add support for modelLabel for google endpoint feat(HoverButtons.jsx): add support for google endpoint feat(createPayload.ts): add google endpoint feat(types.ts): add google endpoint feat(store/endpoints.js): add google endpoint feat(cleanupPreset.js): add support for topP and topK for google endpoint feat(getDefaultConversation.js): add support for topP and topK for google endpoint feat(handleSubmit.js): add support for topP and topK for google endpoint * fix: messages payload * refactor(GoogleClient.js): set maxContextTokens based on isTextModel value feat(GoogleClient.js): add delay option to TextStream constructor feat(getIcon.jsx): add support for google endpoint and PaLM2 model label * feat: palm frontend changes * feat(askGoogle.js): set default example to empty input and output feat(Examples.jsx): add ability to add and remove examples refactor(Settings.jsx): remove examples from props and setOption function style(GoogleOptions): remove unnecessary whitespace after Settings2 import feat(GoogleOptions): add addExample and removeExample functions to manage examples fix(cleanupPreset): set default example to [{ input: '', output: ''}] fix(getDefaultConversation): set default example to [{ input: '', output: ''}] fix(handleSubmit): set default example to [{ input: '', output: ''}] * style(client): adjust height of settings and examples components to 350px fix(client): fix path to palm.png image in getIcon.jsx file * style(EndpointOptionsPopover.jsx, Examples.jsx, Settings.jsx): improve button styles and update input placeholders * feat (palm): finalize examples on the frontend * feat(GoogleClient.js): filter out empty examples in options feat(GoogleClient.js): add support for promptPrefix in buildPayload method feat(GoogleClient.js): add support for examples in buildPayload method feat(conversationPreset.js): add maxOutputTokens field to conversation preset schema feat(presetSchema.js): add examples field to preset schema feat(askGoogle.js): add support for examples and promptPrefix in endpointOption feat(EditPresetDialog.jsx): add Examples component for Google endpoint feat(EditPresetDialog.jsx): add button to show/hide Examples component feat(EditPresetDialog.jsx): add functionality to add, remove, and edit examples in Examples component feat(EndpointOptionsDialog.jsx): change endpoint name to PaLM for Google endpoint feat(Settings.jsx): add maxHeight prop to limit height of Settings component in EditPresetDialog and EndpointOptionsDialog fix(Settings.jsx): add examples prop to ChatGPTBrowser component fix(EndpointItem.jsx): add alternate name for google endpoint fix(MessageHeader.jsx): change title for google endpoint to PaLM feat(endpoints.js): add google endpoint to endpointsConfig fix(cleanupPreset.js): add missing comma in examples array * chore: change endpoint order * feat(PaLM 2): complete for testing * fix(PaLM): handle blocked messages
2023-05-13 16:29:06 -04:00
name = modelLabel || 'PaLM2';
2023-03-31 01:41:41 +08:00
} else if (endpoint === 'bingAI') {
const { jailbreak } = props;
icon = <BingIcon size={size * 0.7} />;
bg = jailbreak ? `radial-gradient(circle at 90% 110%, #F0F0FA, #D0E0F9)` : `transparent`;
name = jailbreak ? 'Sydney' : 'BingAI';
} else if (endpoint === 'chatGPTBrowser') {
icon = <GPTIcon size={size * 0.7} />;
bg =
model && model.toLowerCase().startsWith('gpt-4')
? '#AB68FF'
: `rgba(0, 163, 255, ${button ? 0.75 : 1})`;
2023-03-31 01:41:41 +08:00
name = 'ChatGPT';
} else if (endpoint === null) {
icon = <GPTIcon size={size * 0.7} />;
bg = `grey`;
name = 'N/A';
2023-03-31 03:22:57 +08:00
} else {
icon = <GPTIcon size={size * 0.7} />;
bg = `grey`;
name = 'UNKNOWN';
2023-03-31 01:41:41 +08:00
}
return (
<div
title={name}
style={{
background: bg || 'transparent',
width: size,
height: size
}}
className={
`relative flex items-center justify-center rounded-sm text-white ` + props?.className
}
2023-03-31 01:41:41 +08:00
>
{icon}
{error && (
<span className="absolute right-0 top-[20px] -mr-2 flex h-4 w-4 items-center justify-center rounded-full border border-white bg-red-500 text-[10px] text-white">
!
</span>
)}
</div>
);
}
};
export default getIcon;