2024-10-03 17:36:09 +02:00
|
|
|
"use client";
|
|
|
|
import React, { useState, useEffect } from 'react';
|
2024-09-18 10:03:36 +02:00
|
|
|
|
2024-10-03 17:36:09 +02:00
|
|
|
// Define all models that should be available.
|
2024-09-30 10:43:22 +02:00
|
|
|
const modelList = {
|
|
|
|
'Offline Fast': {
|
2024-10-03 14:03:28 +02:00
|
|
|
model_type: 'local',
|
|
|
|
Math: 'qwen2-math:1.5b',
|
|
|
|
Code: 'starcoder2',
|
|
|
|
Language: 'llama3.2',
|
|
|
|
Weather: 'llama3.2',
|
2024-09-30 10:43:22 +02:00
|
|
|
},
|
|
|
|
'Offline Slow': {
|
2024-10-03 14:03:28 +02:00
|
|
|
model_type: 'local',
|
|
|
|
Math: 'wizard-math',
|
|
|
|
Code: 'starcoder2:7b',
|
|
|
|
Language: 'llama3.1',
|
|
|
|
Weather: 'llama3.1',
|
2024-09-30 10:43:22 +02:00
|
|
|
},
|
|
|
|
'Offline Fast (FOSS)': {
|
2024-10-03 14:03:28 +02:00
|
|
|
model_type: 'local',
|
|
|
|
Math: 'qwen2-math:1.5b',
|
|
|
|
Code: 'qwen2.5-coder:1.5b',
|
|
|
|
Language: 'phi3.5',
|
|
|
|
Weather: 'phi3.5',
|
2024-09-30 10:43:22 +02:00
|
|
|
},
|
|
|
|
'Offline Slow (FOSS)': {
|
2024-10-03 14:03:28 +02:00
|
|
|
model_type: 'local',
|
|
|
|
Math: 'mathstral',
|
|
|
|
Code: 'qwen2.5-coder',
|
|
|
|
Language: 'qwen2.5',
|
|
|
|
Weather: 'qwen2.5',
|
2024-09-30 10:43:22 +02:00
|
|
|
},
|
|
|
|
'Online Cheap (OpenAI)': {
|
2024-10-03 14:03:28 +02:00
|
|
|
model_type: 'openai',
|
|
|
|
Math: 'gpt-4o-mini',
|
|
|
|
Code: 'gpt-4o-mini',
|
|
|
|
Language: 'gpt-4o-mini',
|
|
|
|
Weather: 'gpt-4o-mini',
|
2024-09-30 10:43:22 +02:00
|
|
|
},
|
|
|
|
'Online Expensive (OpenAI)': {
|
2024-10-03 14:03:28 +02:00
|
|
|
model_type: 'openai',
|
|
|
|
Math: 'gpt-4o',
|
|
|
|
Code: 'gpt-4o',
|
|
|
|
Language: 'gpt-4o',
|
|
|
|
Weather: 'gpt-4o',
|
2024-09-30 10:43:22 +02:00
|
|
|
},
|
|
|
|
'Online Cheap (Anthropic)': {
|
2024-10-03 14:03:28 +02:00
|
|
|
model_type: 'anthropic',
|
|
|
|
Math: 'claude-3-haiku',
|
|
|
|
Code: 'claude-3-haiku',
|
|
|
|
Language: 'claude-3-haiku',
|
|
|
|
Weather: 'claude-3-haiku',
|
2024-09-30 10:43:22 +02:00
|
|
|
},
|
|
|
|
'Online Expensive (Anthropic)': {
|
2024-10-03 14:03:28 +02:00
|
|
|
model_type: 'anthropic',
|
|
|
|
Math: 'claude-3-5-sonnet',
|
|
|
|
Code: 'claude-3-5-sonnet',
|
|
|
|
Language: 'claude-3-5-sonnet',
|
|
|
|
Weather: 'claude-3-5-sonnet',
|
2024-09-30 10:43:22 +02:00
|
|
|
},
|
|
|
|
'Online Cheap (Google)': {
|
2024-10-03 14:03:28 +02:00
|
|
|
model_type: 'google',
|
|
|
|
Math: 'gemini-1.5-flash-latest',
|
|
|
|
Code: 'gemini-1.5-flash-latest',
|
|
|
|
Language: 'gemini-1.5-flash-latest',
|
|
|
|
Weather: 'gemini-1.5-flash-latest',
|
2024-09-30 10:43:22 +02:00
|
|
|
},
|
|
|
|
'Online Expensive (Google)': {
|
2024-10-03 14:03:28 +02:00
|
|
|
model_type: 'google',
|
|
|
|
Math: 'gemini-1.5-pro-latest',
|
|
|
|
Code: 'gemini-1.5-pro-latest',
|
|
|
|
Language: 'gemini-1.5-pro-latest',
|
|
|
|
Weather: 'gemini-1.5-pro-latest',
|
2024-09-30 10:43:22 +02:00
|
|
|
},
|
|
|
|
'Online (La Plateforme)': {
|
2024-10-03 14:03:28 +02:00
|
|
|
model_type: 'mistral',
|
|
|
|
Math: 'open-mistral-nemo',
|
|
|
|
Code: 'codestral-latest',
|
|
|
|
Language: 'mistral-small-latest',
|
|
|
|
Weather: 'mistral-small-latest',
|
2024-09-30 10:43:22 +02:00
|
|
|
},
|
|
|
|
'Online (FOSS) (La Plateforme)': {
|
2024-10-03 14:03:28 +02:00
|
|
|
model_type: 'mistral',
|
|
|
|
Math: 'open-mistral-nemo',
|
|
|
|
Code: 'open-codestral-mamba',
|
|
|
|
Language: 'open-mistral-nemo',
|
|
|
|
Weather: 'open-mistral-nemo',
|
2024-09-30 10:43:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-03 16:57:24 +02:00
|
|
|
|
2024-10-02 09:04:24 +02:00
|
|
|
// Define the available selectedAIFunction options
|
2024-09-26 12:31:56 +02:00
|
|
|
const modelDropdown = {
|
2024-10-02 09:04:24 +02:00
|
|
|
offlineNonFoss: ['Offline Fast', 'Offline Slow'],
|
2024-09-27 14:56:46 +02:00
|
|
|
offlineFoss: ['Offline Fast (FOSS)', 'Offline Slow (FOSS)'],
|
2024-10-02 09:04:24 +02:00
|
|
|
onlineNonFoss: [
|
2024-09-26 12:31:56 +02:00
|
|
|
'Online Cheap (OpenAI)',
|
|
|
|
'Online Expensive (OpenAI)',
|
|
|
|
'Online Cheap (Anthropic)',
|
|
|
|
'Online Expensive (Anthropic)',
|
|
|
|
'Online Cheap (Google)',
|
|
|
|
'Online Expensive (Google)',
|
2024-09-30 10:43:22 +02:00
|
|
|
'Online (La Plateforme)'
|
2024-09-26 12:31:56 +02:00
|
|
|
],
|
2024-09-27 14:56:46 +02:00
|
|
|
onlineFoss: ['Online (FOSS) (La Plateforme)'],
|
2024-09-26 12:31:56 +02:00
|
|
|
};
|
|
|
|
|
2024-10-02 09:04:24 +02:00
|
|
|
const selectedAIFunction = [
|
2024-10-03 13:33:07 +02:00
|
|
|
'Code',
|
|
|
|
'Math',
|
|
|
|
'Language',
|
2024-10-08 14:20:27 +02:00
|
|
|
'Weather'
|
2024-10-01 16:53:59 +02:00
|
|
|
]
|
|
|
|
|
2024-10-02 09:04:24 +02:00
|
|
|
const ModelSection: React.FC = () => {
|
2024-09-26 12:31:56 +02:00
|
|
|
// Initialize state with value from localStorage or default to ''
|
2024-10-03 17:36:09 +02:00
|
|
|
const [selectedModelDropdown, setSelectedModelDropdown] = useState('');
|
|
|
|
const [radioSelection, setRadioSelection] = useState<string | null>("")
|
2024-10-02 09:04:24 +02:00
|
|
|
const [activeSelectedAIFunction, setActiveSelectedAIFunction] = useState('');
|
|
|
|
const [currentSelectedAIFunction, setCurrentSelectedAIFunction] = useState<string | null>("");
|
2024-10-07 11:16:51 +02:00
|
|
|
const [isOpenSourceMode, setIsOpenSourceMode] = useState<string|null>("false")
|
2024-10-03 13:33:07 +02:00
|
|
|
|
2024-09-26 12:31:56 +02:00
|
|
|
useEffect(() => {
|
2024-10-07 11:16:51 +02:00
|
|
|
if (typeof localStorage !== 'undefined') {
|
|
|
|
|
|
|
|
setIsOpenSourceMode(localStorage.getItem("openSourceMode"))
|
|
|
|
const temp = localStorage.getItem("activeSelectedAIFunction") || ""
|
|
|
|
setActiveSelectedAIFunction(temp)
|
|
|
|
if (!localStorage.getItem('selectedModelDropdown')) {
|
|
|
|
localStorage.setItem("selectedModelDropdown", "Offline Fast")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!localStorage.getItem("activeSelectedAIFunction")) {
|
|
|
|
setActiveSelectedAIFunction('Code')
|
|
|
|
localStorage.setItem('activeSelectedAIFunction', 'Code')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!localStorage.getItem("model")) {
|
|
|
|
localStorage.setItem("model", 'starcoder2')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!localStorage.getItem("radioSelection")) {
|
|
|
|
localStorage.setItem("radioSelection", 'None')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!localStorage.getItem("type")) {
|
|
|
|
localStorage.setItem("type", 'local')
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleStorageChange = () => {
|
|
|
|
setSelectedModelDropdown(localStorage.getItem('selectedModelDropdown') || '');
|
|
|
|
};
|
|
|
|
|
|
|
|
// Update immediately when localStorage changes
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
window.addEventListener('storage', handleStorageChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
setRadioSelection(localStorage.getItem('radioSelection') || '');
|
2024-10-03 17:36:09 +02:00
|
|
|
setSelectedModelDropdown(localStorage.getItem('selectedModelDropdown') || '');
|
2024-10-07 11:16:51 +02:00
|
|
|
// Cleanup listener on component unmount
|
|
|
|
return () => {
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
window.removeEventListener('storage', handleStorageChange);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2024-10-03 17:36:09 +02:00
|
|
|
}, []); // Dependency array can remain empty if you only want this to run on mount
|
2024-09-26 09:29:04 +02:00
|
|
|
|
2024-10-03 17:36:09 +02:00
|
|
|
useEffect(() => {
|
2024-10-07 11:16:51 +02:00
|
|
|
if (typeof localStorage !== 'undefined') {
|
|
|
|
const storedActiveSelectedAIFunction = localStorage.getItem("activeSelectedAIFunction") || "";
|
|
|
|
if (storedActiveSelectedAIFunction !== currentSelectedAIFunction) {
|
|
|
|
setCurrentSelectedAIFunction(storedActiveSelectedAIFunction);
|
|
|
|
}
|
2024-10-03 17:36:09 +02:00
|
|
|
}
|
|
|
|
}, [activeSelectedAIFunction]);
|
2024-10-03 16:15:15 +02:00
|
|
|
|
2024-10-03 17:36:09 +02:00
|
|
|
const handleModelChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
|
|
|
|
const newModel = event.target.value;
|
|
|
|
setSelectedModelDropdown(newModel);
|
2024-10-07 11:16:51 +02:00
|
|
|
if (typeof localStorage !== 'undefined') {
|
|
|
|
localStorage.setItem('selectedModelDropdown', newModel); // Update localStorage directly
|
|
|
|
const model = localStorage.getItem('activeSelectedAIFunction') || "Code"
|
|
|
|
modelClicked(model)
|
|
|
|
}
|
2024-10-03 16:15:15 +02:00
|
|
|
};
|
2024-09-26 09:29:04 +02:00
|
|
|
|
2024-09-26 12:31:56 +02:00
|
|
|
// Determine the filtered models based on current radioSelection
|
2024-09-26 09:45:31 +02:00
|
|
|
const filteredModels = (() => {
|
2024-09-27 09:54:38 +02:00
|
|
|
let models = [];
|
2024-09-26 12:31:56 +02:00
|
|
|
switch (radioSelection) {
|
2024-09-26 09:45:31 +02:00
|
|
|
case 'Offline':
|
2024-09-27 14:56:46 +02:00
|
|
|
models = [
|
2024-10-02 09:04:24 +02:00
|
|
|
...modelDropdown.onlineNonFoss,
|
2024-09-27 14:56:46 +02:00
|
|
|
...modelDropdown.onlineFoss,
|
2024-10-03 16:57:24 +02:00
|
|
|
];
|
|
|
|
if (isOpenSourceMode == "true") {
|
|
|
|
models = [
|
|
|
|
...modelDropdown.onlineFoss,
|
|
|
|
];
|
|
|
|
} // Show only offline models without FOSS
|
2024-09-27 09:54:38 +02:00
|
|
|
break;
|
2024-09-27 14:56:46 +02:00
|
|
|
case 'Online':
|
|
|
|
models = [
|
2024-10-02 09:04:24 +02:00
|
|
|
...modelDropdown.offlineNonFoss,
|
2024-09-27 14:56:46 +02:00
|
|
|
...modelDropdown.offlineFoss,
|
2024-10-03 16:57:24 +02:00
|
|
|
];
|
|
|
|
if (isOpenSourceMode == "true") {
|
|
|
|
models = [
|
|
|
|
...modelDropdown.offlineFoss,
|
|
|
|
];
|
|
|
|
} // Show only online models without FOSS
|
2024-09-27 14:56:46 +02:00
|
|
|
break;
|
|
|
|
case 'None':
|
|
|
|
models = [
|
2024-10-02 09:04:24 +02:00
|
|
|
...modelDropdown.offlineNonFoss,
|
2024-09-27 14:56:46 +02:00
|
|
|
...modelDropdown.offlineFoss,
|
2024-10-02 09:04:24 +02:00
|
|
|
...modelDropdown.onlineNonFoss,
|
2024-09-27 14:56:46 +02:00
|
|
|
...modelDropdown.onlineFoss,
|
2024-10-03 16:57:24 +02:00
|
|
|
];
|
|
|
|
if (isOpenSourceMode == "true") {
|
|
|
|
models = [
|
|
|
|
...modelDropdown.offlineFoss,
|
|
|
|
...modelDropdown.onlineFoss,
|
|
|
|
];
|
|
|
|
} // Show all models if nothing matches
|
2024-09-27 09:54:38 +02:00
|
|
|
break;
|
2024-09-26 09:45:31 +02:00
|
|
|
default:
|
2024-09-27 14:56:46 +02:00
|
|
|
models = [
|
2024-10-02 09:04:24 +02:00
|
|
|
...modelDropdown.offlineNonFoss,
|
2024-09-27 14:56:46 +02:00
|
|
|
...modelDropdown.offlineFoss,
|
2024-10-02 09:04:24 +02:00
|
|
|
...modelDropdown.onlineNonFoss,
|
2024-09-27 14:56:46 +02:00
|
|
|
...modelDropdown.onlineFoss,
|
|
|
|
]; // Show all models if nothing matches
|
2024-09-27 09:54:38 +02:00
|
|
|
break;
|
2024-09-26 09:45:31 +02:00
|
|
|
}
|
2024-09-27 09:54:38 +02:00
|
|
|
return Array.from(new Set(models)); // Remove duplicates using Set
|
2024-09-26 09:45:31 +02:00
|
|
|
})();
|
2024-09-26 09:29:04 +02:00
|
|
|
|
2024-09-27 14:56:46 +02:00
|
|
|
const isOfflineModel = (model: string) =>
|
2024-10-02 09:04:24 +02:00
|
|
|
modelDropdown.offlineNonFoss.includes(model) || modelDropdown.offlineFoss.includes(model);
|
2024-09-26 12:31:56 +02:00
|
|
|
|
2024-09-30 10:43:22 +02:00
|
|
|
const modelClicked = (model: string) => {
|
2024-10-07 11:16:51 +02:00
|
|
|
if (typeof localStorage !== 'undefined') {
|
|
|
|
localStorage.setItem('activeSelectedAIFunction', model)
|
|
|
|
setActiveSelectedAIFunction(model)
|
|
|
|
const modelDropdown = localStorage.getItem('selectedModelDropdown') || 'Offline Fast'
|
|
|
|
const selectedAIFunction = modelDropdown as keyof typeof modelList;
|
|
|
|
localStorage.setItem("model", modelList[selectedAIFunction][model as keyof typeof modelList[typeof selectedAIFunction]])
|
|
|
|
localStorage.setItem("type", modelList[selectedAIFunction]['model_type' as keyof typeof modelList[typeof selectedAIFunction]])
|
|
|
|
}
|
2024-10-03 17:36:09 +02:00
|
|
|
}
|
2024-09-30 10:43:22 +02:00
|
|
|
|
2024-09-26 09:45:31 +02:00
|
|
|
return (
|
|
|
|
<div className="model-background">
|
2024-09-27 09:54:38 +02:00
|
|
|
<div className="models">
|
|
|
|
<div className="title">
|
|
|
|
<h3>Different AI Models</h3>
|
|
|
|
</div>
|
2024-09-26 09:29:04 +02:00
|
|
|
|
2024-09-27 09:54:38 +02:00
|
|
|
{/* Model Selection Dropdown */}
|
|
|
|
<div className="model-dropdown">
|
|
|
|
<label htmlFor="model-select">Select AI Model:</label>
|
2024-10-02 09:04:24 +02:00
|
|
|
<select id="model-select" value={selectedModelDropdown} onChange={handleModelChange}>
|
2024-09-27 09:54:38 +02:00
|
|
|
{filteredModels.map((model) => (
|
|
|
|
<option key={model} value={model}>
|
|
|
|
{model}
|
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
</div>
|
2024-09-26 09:45:31 +02:00
|
|
|
|
2024-09-27 09:54:38 +02:00
|
|
|
{/* Model Grid with Cards */}
|
|
|
|
<div className="grid">
|
2024-10-03 17:36:09 +02:00
|
|
|
{selectedAIFunction.map(
|
|
|
|
(displayedCategory) => (
|
2024-10-01 16:53:59 +02:00
|
|
|
<button
|
|
|
|
key={displayedCategory}
|
2024-10-03 13:33:07 +02:00
|
|
|
className={`${displayedCategory.toLowerCase()}-model model-box ${currentSelectedAIFunction === displayedCategory ? 'selected' : ''}`}
|
2024-10-01 16:53:59 +02:00
|
|
|
onClick={() => modelClicked(displayedCategory)}
|
|
|
|
>
|
2024-09-27 14:56:46 +02:00
|
|
|
<div className="overlay">
|
2024-10-01 16:53:59 +02:00
|
|
|
<h3>{displayedCategory}</h3>
|
2024-10-02 09:04:24 +02:00
|
|
|
{isOfflineModel(selectedModelDropdown) && <img src="/img/nowifi.svg" alt="No Wi-Fi" />}
|
2024-09-27 14:56:46 +02:00
|
|
|
</div>
|
|
|
|
</button>
|
2024-10-03 17:36:09 +02:00
|
|
|
)
|
|
|
|
)}
|
2024-09-27 09:54:38 +02:00
|
|
|
</div>
|
2024-09-18 10:03:36 +02:00
|
|
|
</div>
|
2024-09-26 09:45:31 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2024-09-18 10:03:36 +02:00
|
|
|
|
2024-10-02 09:04:24 +02:00
|
|
|
export default ModelSection;
|