interstellar_ai/app/components/Models.tsx

175 lines
5.1 KiB
TypeScript
Raw Normal View History

"use client";
import React, { useState, useEffect } from 'react';
2024-09-18 10:03:36 +02:00
2024-10-10 09:18:12 +02:00
// Define the types for ModelType and ModelListType
type ModelType = {
model_type: string;
Math: string;
Code: string;
Language: string;
Weather: string;
};
type ModelListType = {
[key: string]: ModelType;
};
// Define the AI models list
const modelList: ModelListType = {
2024-09-30 10:43:22 +02:00
'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-10-10 09:18:12 +02:00
},
2024-09-26 12:31:56 +02:00
};
2024-10-10 09:18:12 +02:00
// AI Functions list
const aiFunctions = ['Math', 'Code', 'Language', 'Weather'] as const;
type AIFunction = typeof aiFunctions[number]; // Restrict to these exact function names
2024-10-02 09:04:24 +02:00
const ModelSection: React.FC = () => {
2024-10-10 09:18:12 +02:00
const [selectedModelDropdown, setSelectedModelDropdown] = useState<string>(() => localStorage.getItem("selectedModelDropdown") || "Offline Fast");
const [activeSelectedAIFunction, setActiveSelectedAIFunction] = useState<AIFunction>(() => (localStorage.getItem("activeSelectedAIFunction") as AIFunction) || "Code");
const [selectedModel, setSelectedModel] = useState<string>("");
const [selectedModelType, setSelectedModelType] = useState<string>("");
2024-10-03 13:33:07 +02:00
2024-10-10 09:18:12 +02:00
// Update the model and type when the dropdown or function changes
2024-09-26 12:31:56 +02:00
useEffect(() => {
2024-10-10 09:18:12 +02:00
const newSelectedModel = modelList[selectedModelDropdown]?.[activeSelectedAIFunction] || "";
const newModelType = modelList[selectedModelDropdown]?.model_type || "";
2024-09-26 09:29:04 +02:00
2024-10-10 09:18:12 +02:00
setSelectedModel(newSelectedModel);
setSelectedModelType(newModelType);
localStorage.setItem("model", newSelectedModel);
localStorage.setItem("type", newModelType);
}, [selectedModelDropdown, activeSelectedAIFunction]);
2024-10-03 16:15:15 +02:00
const handleModelChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
const newModel = event.target.value;
setSelectedModelDropdown(newModel);
2024-10-10 09:18:12 +02:00
localStorage.setItem('selectedModelDropdown', newModel);
2024-10-03 16:15:15 +02:00
};
2024-09-26 09:29:04 +02:00
2024-10-10 09:18:12 +02:00
const modelClicked = (functionName: AIFunction) => {
setActiveSelectedAIFunction(functionName);
localStorage.setItem('activeSelectedAIFunction', functionName);
};
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
<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-10-10 09:18:12 +02:00
{Object.keys(modelList).map((model) => (
2024-09-27 09:54:38 +02:00
<option key={model} value={model}>
{model}
</option>
))}
</select>
</div>
2024-10-10 09:18:12 +02:00
2024-09-27 09:54:38 +02:00
<div className="grid">
2024-10-10 09:18:12 +02:00
{aiFunctions.map((functionName) => (
<button
key={functionName}
className={`${functionName.toLowerCase()}-model model-box ${activeSelectedAIFunction === functionName ? 'selected' : ''}`}
onClick={() => modelClicked(functionName)}
>
<div className="overlay">
<h3>{functionName}</h3>
</div>
</button>
))}
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;