This commit is contained in:
sageTheDM 2024-09-26 09:45:31 +02:00
parent a05b9d6a5f
commit ddaf7638ac

View file

@ -1,11 +1,14 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
// Define the available model options // Define the available model options
const modelOptions = [ const offlineModels = [
'Offline Fast', 'Offline Fast',
'Offline Fast (FOSS)', 'Offline Fast (FOSS)',
'Offline Slow', 'Offline Slow',
'Offline Slow (FOSS)', 'Offline Slow (FOSS)',
];
const onlineModels = [
'Online (La Plateforme)', 'Online (La Plateforme)',
'Online (FOSS) (La Plateforme)', 'Online (FOSS) (La Plateforme)',
'Online Cheap (OpenAI)', 'Online Cheap (OpenAI)',
@ -14,50 +17,47 @@
'Online Expensive (Anthropic)', 'Online Expensive (Anthropic)',
'Online Cheap (Google)', 'Online Cheap (Google)',
'Online Expensive (Google)', 'Online Expensive (Google)',
]; ];
// Define the properties passed to the Models component const fossModels = [
interface ModelsProps { 'Offline Fast (FOSS)',
'Offline Slow (FOSS)',
'Online (FOSS) (La Plateforme)',
];
// Define the properties passed to the Models component
interface ModelsProps {
selectedOption: string; // Privacy setting: "Offline", "AI Online", "None" selectedOption: string; // Privacy setting: "Offline", "AI Online", "None"
} }
const Models: React.FC<ModelsProps> = ({ selectedOption }) => { const Models: React.FC<ModelsProps> = ({ selectedOption }) => {
// State for the selected model, default is loaded from localStorage or defaults to 'Offline Fast'
const [selectedModel, setSelectedModel] = useState<string>(() => { const [selectedModel, setSelectedModel] = useState<string>(() => {
return localStorage.getItem('selectedModel') || 'Offline Fast'; return localStorage.getItem('selectedModel') || 'Offline Fast';
}); });
// Handle changes in the selected model from the dropdown
const handleModelChange = (event: React.ChangeEvent<HTMLSelectElement>) => { const handleModelChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
const newModel = event.target.value; const newModel = event.target.value;
setSelectedModel(newModel); setSelectedModel(newModel);
}; };
// Utility function to check if a model is an offline model const isOfflineModel = (model: string) => offlineModels.includes(model);
const isOfflineModel = (model: string) => { const isOnlineModel = (model: string) => onlineModels.includes(model);
return model.includes('Offline'); const isFossModel = (model: string) => fossModels.includes(model);
};
// Utility function to check if a model is an online model
const isOnlineModel = (model: string) => {
return model.includes('Online');
};
// Save selected model to localStorage whenever it changes
useEffect(() => { useEffect(() => {
localStorage.setItem('selectedModel', selectedModel); localStorage.setItem('selectedModel', selectedModel);
}, [selectedModel]); }, [selectedModel]);
// Filter models based on the selected privacy option (Offline, AI Online, None) const filteredModels = (() => {
const filteredModels = modelOptions.filter((model) => { switch (selectedOption) {
if (selectedOption === 'Offline') { case 'Offline':
return !isOnlineModel(model); // Hide online models return offlineModels; // Show only offline models
} else if (selectedOption === 'AI Online') { case 'AI Online':
return !isOfflineModel(model); // Hide offline models return onlineModels; // Show only online models
} else { default:
return true; // Show all models for "None" return [...offlineModels, ...onlineModels]; // Show all models
} }
}); })();
return ( return (
<div className="model-background"> <div className="model-background">
@ -144,6 +144,6 @@
</div> </div>
</div> </div>
); );
}; };
export default Models; export default Models;