Spaces:
Build error
Build error
File size: 5,764 Bytes
60e402b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | 'use client';
import { useState } from 'react';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { Badge } from '@/components/ui/badge';
import { Settings, Cpu, Zap, Brain } from 'lucide-react';
interface ModelSelectorProps {
selectedModel: string;
onModelChange: (model: string) => void;
models: string[];
}
const modelIcons: Record<string, React.ReactNode> = {
'deepseek-ai': <Brain className="w-3 h-3" />,
'Qwen': <Cpu className="w-3 h-3" />,
'moonshotai': <Zap className="w-3 h-3" />,
'zai-org': <Settings className="w-3 h-3" />,
'MiniMaxAI': <Brain className="w-3 h-3" />,
'meta-llama': <Cpu className="w-3 h-3" />,
'google': <Brain className="w-3 h-3" />,
};
const getProviderFromModel = (modelName: string): string => {
if (modelName.includes('deepseek-ai') || modelName.includes('Qwen') ||
modelName.includes('moonshotai') || modelName.includes('zai-org') ||
modelName.includes('MiniMaxAI') || modelName.includes('meta-llama') ||
modelName.includes('google')) {
return 'Hugging Face';
}
return 'Unknown';
};
const getModelCategory = (modelName: string): string => {
if (modelName.includes('DeepSeek')) return 'Reasoning';
if (modelName.includes('Coder')) return 'Code';
if (modelName.includes('VL')) return 'Vision';
if (modelName.includes('Kimi') && modelName.includes('Thinking')) return 'Reasoning';
if (modelName.includes('Kimi')) return 'General';
if (modelName.includes('GLM')) return 'General';
return 'Language';
};
const getDisplayName = (modelName: string): string => {
const parts = modelName.split('/');
const model = parts[1] || modelName;
// Clean up model names for better display
const cleanName = model
.replace('-0324', '')
.replace('-0528', '')
.replace('-0905', '')
.replace('-Instruct', '')
.replace('-A22B', '')
.replace('-A35B', '')
.replace('-VL-7B', '')
.replace('-Exp', '')
.replace('-Distill-', '-')
.replace('-Terminus', '')
.replace('DeepSeek-V3-0324', 'DeepSeek V3')
.replace('DeepSeek-R1-0528', 'DeepSeek R1')
.replace('DeepSeek-V3.1', 'DeepSeek V3.1')
.replace('DeepSeek-V3.1-Terminus', 'DeepSeek V3.1 Terminus')
.replace('DeepSeek-V3.2-Exp', 'DeepSeek V3.2 Exp')
.replace('Qwen3-Coder-480B-A35B-Instruct', 'Qwen3 Coder 480B')
.replace('Qwen2.5-VL-7B-Instruct', 'Qwen2.5 VL 7B')
.replace('Kimi-K2-Instruct', 'Kimi K2')
.replace('Kimi-K2-Instruct-0905', 'Kimi K2 0905')
.replace('Kimi-K2-Thinking', 'Kimi K2 Thinking')
.replace('GLM-4.6', 'GLM-4.6')
.replace('MiniMax-M2', 'MiniMax M2')
.replace('Llama-3.1-8B-Instruct', 'Llama 3.1 8B')
.replace('Llama-3.1-70B-Instruct', 'Llama 3.1 70B')
.replace('Llama-3.3-70B-Instruct', 'Llama 3.3 70B')
.replace('Llama-4-Scout-17B-16E-Instruct', 'Llama 4 Scout 17B')
.replace('gemma-3-27b-it', 'Gemma 3 27B');
return cleanName;
};
export function ModelSelector({ selectedModel, onModelChange, models }: ModelSelectorProps) {
const [open, setOpen] = useState(false);
const getIconForModel = (modelName: string) => {
for (const [key, icon] of Object.entries(modelIcons)) {
if (modelName.includes(key)) {
return icon;
}
}
return <Brain className="w-3 h-3" />;
};
const groupModelsByProvider = () => {
const groups: Record<string, string[]> = {};
models.forEach(model => {
const provider = getProviderFromModel(model);
if (!groups[provider]) {
groups[provider] = [];
}
groups[provider].push(model);
});
return groups;
};
const groupedModels = groupModelsByProvider();
return (
<Select
value={selectedModel}
onValueChange={onModelChange}
onOpenChange={setOpen}
>
<SelectTrigger className="w-[280px]">
<div className="flex items-center gap-2 truncate">
{getIconForModel(selectedModel)}
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<span className="font-medium truncate">
{getDisplayName(selectedModel)}
</span>
<Badge variant="outline" className="text-xs">
{getModelCategory(selectedModel)}
</Badge>
</div>
<div className="text-xs text-muted-foreground truncate">
{getProviderFromModel(selectedModel)}
</div>
</div>
</div>
</SelectTrigger>
<SelectContent>
{Object.entries(groupedModels).map(([provider, providerModels]) => (
<div key={provider}>
<div className="px-2 py-1.5 text-xs font-semibold text-muted-foreground border-b">
{provider}
</div>
{providerModels.map((model) => (
<SelectItem key={model} value={model}>
<div className="flex items-center gap-2 w-full">
{getIconForModel(model)}
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<span className="font-medium truncate">
{getDisplayName(model)}
</span>
<Badge variant="outline" className="text-xs flex-shrink-0">
{getModelCategory(model)}
</Badge>
</div>
<div className="text-xs text-muted-foreground truncate">
{model}
</div>
</div>
</div>
</SelectItem>
))}
</div>
))}
</SelectContent>
</Select>
);
} |