Merge branch 'revert'

This commit is contained in:
Patrick_Pluto 2024-10-03 16:58:52 +02:00
commit 51899a554e
2 changed files with 215 additions and 139 deletions

View file

@ -135,8 +135,36 @@ const modelList = {
Image: 'pixtral-12b-2409' Image: 'pixtral-12b-2409'
} }
} }
// Define the keys of modelList
type ModelKeys = keyof typeof modelList;
// Define the available selectedAIFunction options
const modelDropdown = {
offlineNonFoss: ['Offline Fast', 'Offline Slow'],
offlineFoss: ['Offline Fast (FOSS)', 'Offline Slow (FOSS)'],
onlineNonFoss: [
'Online Cheap (OpenAI)',
'Online Expensive (OpenAI)',
'Online Cheap (Anthropic)',
'Online Expensive (Anthropic)',
'Online Cheap (Google)',
'Online Expensive (Google)',
'Online (La Plateforme)'
],
onlineFoss: ['Online (FOSS) (La Plateforme)'],
};
const selectedAIFunction = [
'Code',
'Math',
'Language',
'Character',
'Finance',
'Weather',
'Time',
'Image',
'Custom1',
'Custom2'
]
const ModelSection: React.FC = () => { const ModelSection: React.FC = () => {
// Initialize state with value from localStorage or default to '' // Initialize state with value from localStorage or default to ''
@ -144,6 +172,7 @@ const ModelSection: React.FC = () => {
const [radioSelection, setRadioSelection] = useState<string | null>(""); const [radioSelection, setRadioSelection] = useState<string | null>("");
const [activeSelectedAIFunction, setActiveSelectedAIFunction] = useState(''); const [activeSelectedAIFunction, setActiveSelectedAIFunction] = useState('');
const [currentSelectedAIFunction, setCurrentSelectedAIFunction] = useState<string | null>(""); const [currentSelectedAIFunction, setCurrentSelectedAIFunction] = useState<string | null>("");
const [isOpenSourceMode, setIsOpenSourceMode] = useState(localStorage.getItem('openSourceMode') || "false")
useEffect(() => { useEffect(() => {
// Load initial values from localStorage // Load initial values from localStorage
@ -189,9 +218,60 @@ const ModelSection: React.FC = () => {
localStorage.setItem('type', modelType); localStorage.setItem('type', modelType);
}; };
const isOfflineModel = (model: string) => { // Determine the filtered models based on current radioSelection
return modelList[model as ModelKeys].model_type === 'local'; const filteredModels = (() => {
}; let models = [];
switch (radioSelection) {
case 'Offline':
models = [
...modelDropdown.onlineNonFoss,
...modelDropdown.onlineFoss,
];
if (isOpenSourceMode == "true") {
models = [
...modelDropdown.onlineFoss,
];
} // Show only offline models without FOSS
break;
case 'Online':
models = [
...modelDropdown.offlineNonFoss,
...modelDropdown.offlineFoss,
];
if (isOpenSourceMode == "true") {
models = [
...modelDropdown.offlineFoss,
];
} // Show only online models without FOSS
break;
case 'None':
models = [
...modelDropdown.offlineNonFoss,
...modelDropdown.offlineFoss,
...modelDropdown.onlineNonFoss,
...modelDropdown.onlineFoss,
];
if (isOpenSourceMode == "true") {
models = [
...modelDropdown.offlineFoss,
...modelDropdown.onlineFoss,
];
} // Show all models if nothing matches
break;
default:
models = [
...modelDropdown.offlineNonFoss,
...modelDropdown.offlineFoss,
...modelDropdown.onlineNonFoss,
...modelDropdown.onlineFoss,
]; // Show all models if nothing matches
break;
}
return Array.from(new Set(models)); // Remove duplicates using Set
})();
const isOfflineModel = (model: string) =>
modelDropdown.offlineNonFoss.includes(model) || modelDropdown.offlineFoss.includes(model);
const modelClicked = (model: string) => { const modelClicked = (model: string) => {
const selectedAIFunction = currentSelectedAIFunction as keyof typeof modelList; const selectedAIFunction = currentSelectedAIFunction as keyof typeof modelList;

View file

@ -112,7 +112,6 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
const [closeButtonHoverColor, setCloseButtonHoverColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--close-button-hover-color').trim()); const [closeButtonHoverColor, setCloseButtonHoverColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--close-button-hover-color').trim());
const [applyButtonColor, setApplyButtonColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--apply-button-color').trim()); const [applyButtonColor, setApplyButtonColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--apply-button-color').trim());
const [applyButtonHoverColor, setApplyButtonHoverColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--apply-button-hover-color').trim()); const [applyButtonHoverColor, setApplyButtonHoverColor] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--apply-button-hover-color').trim());
// Per default a purple color gradient // Per default a purple color gradient
const [primaryColor, setPrimaryColor] = useState(localStorage.getItem("primaryColor") || "#dc8add"); const [primaryColor, setPrimaryColor] = useState(localStorage.getItem("primaryColor") || "#dc8add");
const [secondaryColor, setSecondaryColor] = useState(localStorage.getItem("secondaryColor") || "#c061cb"); const [secondaryColor, setSecondaryColor] = useState(localStorage.getItem("secondaryColor") || "#c061cb");
@ -128,7 +127,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
const [openai, setOpenai] = useState(localStorage.getItem('openai') || ""); const [openai, setOpenai] = useState(localStorage.getItem('openai') || "");
const [anthropic, setAnthropic] = useState(localStorage.getItem('anthropic') || ""); const [anthropic, setAnthropic] = useState(localStorage.getItem('anthropic') || "");
const [google, setGoogle] = useState(localStorage.getItem('google') || ""); const [google, setGoogle] = useState(localStorage.getItem('google') || "");
const [myBoolean, setMyBoolean] =useState<boolean | any>(() => getItemFromLocalStorage('myBoolean')); const [myBoolean, setMyBoolean] = useState<boolean | any>(() => getItemFromLocalStorage('myBoolean'));
const settings = { const settings = {
userPreferences: { userPreferences: {
@ -224,7 +223,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
{ name: "Apply Button Color", value: applyButtonColor, setValue: setApplyButtonColor, cssVariable: "--apply-button-color" }, { name: "Apply Button Color", value: applyButtonColor, setValue: setApplyButtonColor, cssVariable: "--apply-button-color" },
{ name: "Apply Button Hover Color", value: applyButtonHoverColor, setValue: setApplyButtonHoverColor, cssVariable: "--apply-button-hover-color" }, { name: "Apply Button Hover Color", value: applyButtonHoverColor, setValue: setApplyButtonHoverColor, cssVariable: "--apply-button-hover-color" },
{ name: "Burger Menu Background Color", value: burgerMenuBackgroundColor, setValue: setBurgerMenuBackgroundColor, cssVariable: "--burger-menu-background-color" }, { name: "Burger Menu Background Color", value: burgerMenuBackgroundColor, setValue: setBurgerMenuBackgroundColor, cssVariable: "--burger-menu-background-color" },
]; ];
const timeZoneOptions = [ const timeZoneOptions = [
@ -338,15 +337,13 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
useEffect(() => { useEffect(() => {
const savedOption = localStorage.getItem('radioSelection'); const savedOption = localStorage.getItem('radioSelection');
if (savedOption) { if (savedOption) {
handleRadioChange(savedOption); // Set saved selection savedOption.replace(" (FOSS)", "");
setSelectedOption(savedOption); // Set saved selection
} }
}, []); }, []);
const handleRadioChange = (newValue: string) => { const handleRadioChange = (newValue: string) => {
setSelectedOption(newValue); // Update the state with the selected option setSelectedOption(newValue); // Update the state with the selected option
if (openSourceMode) {
newValue += " (FOSS)"
}
localStorage.setItem('radioSelection', newValue); // Save the selection for persistence localStorage.setItem('radioSelection', newValue); // Save the selection for persistence
}; };
@ -479,85 +476,85 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
); );
case 'theme': case 'theme':
return ( return (
<div className="settings-section"> <div className="settings-section">
<h2>Theme Settings</h2> <h2>Theme Settings</h2>
<ThemeDropdown <ThemeDropdown
selectedTheme={selectedTheme} selectedTheme={selectedTheme}
setSelectedTheme={setSelectedTheme} setSelectedTheme={setSelectedTheme}
/>
{selectedTheme === 'BASIC-CUSTOM' && (
<>
<h3>Basic Colors</h3>
{/* Basic Color Inputs using ColorSetting Component */}
<ColorSetting
name="Primary Color"
value={primaryColor}
setValue={setPrimaryColor}
cssVariable=""
/>
<ColorSetting
name="Secondary Color"
value={secondaryColor}
setValue={setSecondaryColor}
cssVariable=""
/>
<ColorSetting
name="Accent Color"
value={accentColor}
setValue={setAccentColor}
cssVariable=""
/>
<ColorSetting
name="Background Color"
value={basicBackgroundColor}
setValue={setBasicBackgroundColor}
cssVariable=""
/>
<ColorSetting
name="Text Color"
value={basicTextColor}
setValue={setBasicTextColor}
cssVariable=""
/>
</>
)}
{selectedTheme === 'CUSTOM' && (
<>
<h3>Additional Settings</h3>
{/* Additional Font Size Setting */}
<FontSizeSetting
fontSize={fontSize}
setFontSize={setFontSize}
/> />
{selectedTheme === 'BASIC-CUSTOM' && ( {colorSettings.map((setting) => (
<> <ColorSetting
<h3>Basic Colors</h3> key={setting.cssVariable}
{/* Basic Color Inputs using ColorSetting Component */} name={setting.name}
<ColorSetting value={setting.value}
name="Primary Color" setValue={setting.setValue}
value={primaryColor} cssVariable={setting.cssVariable}
setValue={setPrimaryColor} />
cssVariable="" ))}
/>
<ColorSetting
name="Secondary Color"
value={secondaryColor}
setValue={setSecondaryColor}
cssVariable=""
/>
<ColorSetting
name="Accent Color"
value={accentColor}
setValue={setAccentColor}
cssVariable=""
/>
<ColorSetting
name="Background Color"
value={basicBackgroundColor}
setValue={setBasicBackgroundColor}
cssVariable=""
/>
<ColorSetting
name="Text Color"
value={basicTextColor}
setValue={setBasicTextColor}
cssVariable=""
/>
</>
)}
{selectedTheme === 'CUSTOM' && ( <DropdownSetting
<> label="Font Family"
<h3>Additional Settings</h3> value={fontFamily}
{/* Additional Font Size Setting */} setValue={(newFont) => {
<FontSizeSetting setFontFamily(newFont);
fontSize={fontSize} document.documentElement.style.setProperty('--font-family', newFont);
setFontSize={setFontSize} }}
/> options={fontOptions}
/>
{colorSettings.map((setting) => ( </>
<ColorSetting )}
key={setting.cssVariable} </div>
name={setting.name} );
value={setting.value}
setValue={setting.setValue}
cssVariable={setting.cssVariable}
/>
))}
<DropdownSetting
label="Font Family"
value={fontFamily}
setValue={(newFont) => {
setFontFamily(newFont);
document.documentElement.style.setProperty('--font-family', newFont);
}}
options={fontOptions}
/>
</>
)}
</div>
);
case 'foss': case 'foss':
return ( return (
@ -580,14 +577,13 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
label="New Name" label="New Name"
value={newName} value={newName}
setValue={setNewName} setValue={setNewName}
type="text"
placeholder={localStorage.getItem("accountName") || "Current Name"} // Show current name or a default placeholder={localStorage.getItem("accountName") || "Current Name"} // Show current name or a default
/> />
<TextSettings <TextSettings
label="New Email" label="New Email"
value={newEmail} value={newEmail}
setValue={setNewEmail} setValue={setNewEmail}
type="email" type="email" // Input type is email
placeholder={localStorage.getItem("accountEmail") || "Current Email"} // Show current email or a default placeholder={localStorage.getItem("accountEmail") || "Current Email"} // Show current email or a default
/> />
<TextSettings <TextSettings
@ -652,24 +648,24 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
case 'im/export': case 'im/export':
return ( return (
<div className="settings-section"> <div className="settings-section">
<h2>Import & Export</h2> <h2>Import & Export</h2>
<div className="settings-option"> <div className="settings-option">
<h3>Export the settings</h3> <h3>Export the settings</h3>
<button onClick={handleExport} className="export-button"> <button onClick={handleExport} className="export-button">
Export Settings Export Settings
</button> </button>
</div>
<div className="settings-option">
<h3>Import the settings</h3>
<input
type="file"
onChange={handleImport}
accept=".json"
className="import-file"
/>
</div>
</div> </div>
<div className="settings-option"> );
<h3>Import the settings</h3>
<input
type="file"
onChange={handleImport}
accept=".json"
className="import-file"
/>
</div>
</div>
);
default: default:
return null; return null;
} }
@ -703,36 +699,36 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
}; };
return ( return (
<div className="popup-overlay"> <div className="popup-overlay">
<div className="settings-content"> <div className="settings-content">
<div className="settings-container"> <div className="settings-container">
<div className="sidebar"> <div className="sidebar">
<ul> <ul>
<li onClick={() => setActiveSection('general')}>General</li> <li onClick={() => setActiveSection('general')}>General</li>
<li onClick={() => setActiveSection('privacy')}>Privacy</li> <li onClick={() => setActiveSection('privacy')}>Privacy</li>
<li onClick={() => setActiveSection('theme')}>Theme</li> <li onClick={() => setActiveSection('theme')}>Theme</li>
<li onClick={() => setActiveSection('foss')}>FOSS</li> <li onClick={() => setActiveSection('foss')}>FOSS</li>
<li onClick={() => setActiveSection('account')}>Account</li> <li onClick={() => setActiveSection('account')}>Account</li>
<li onClick={() => setActiveSection('api')}>API Keys</li> <li onClick={() => setActiveSection('api')}>API Keys</li>
<li onClick={() => setActiveSection('im/export')}>Import/Export</li> <li onClick={() => setActiveSection('im/export')}>Import/Export</li>
</ul> </ul>
</div> </div>
<div className="settings-main"> <div className="settings-main">
<h2>Settings for {accountName}</h2> <h2>Settings for {accountName}</h2>
{renderSettingsContent()} {renderSettingsContent()}
<button className="close-popup" onClick={closeSettings}>Close</button> <button className="close-popup" onClick={closeSettings}>Close</button>
<button className="apply" onClick={async () => { <button className="apply" onClick={async () => {
getAllLocalStorageItems(); getAllLocalStorageItems();
closeSettings(); closeSettings();
await changeData(localStorage.getItem('accountName') ?? "hello", localStorage.getItem('accountPassword') ?? "hello", settings) // ???? await changeData(localStorage.getItem('accountName') ?? "hello", localStorage.getItem('accountPassword') ?? "hello", settings) // ????
window.location.reload(); window.location.reload();
}}> }}>
Apply Apply
</button> </button>
</div>
</div> </div>
</div> </div>
</div> </div>
</div>
); );
}; };