| 10 | } |
| 11 | |
| 12 | export function ModelSelect({ value, onChange, type, className, placeholder }: Props) { |
| 13 | const [models, setModels] = useState<string[]>([]); |
| 14 | const [loading, setLoading] = useState(true); |
| 15 | const [error, setError] = useState<string | null>(null); |
| 16 | |
| 17 | useEffect(() => { |
| 18 | let mounted = true; |
| 19 | chatAPI |
| 20 | .getModels() |
| 21 | .then((res: ModelsResponse) => { |
| 22 | if (!mounted) return; |
| 23 | const list = type === 'generation' ? res.generation_models : res.embedding_models; |
| 24 | setModels(list); |
| 25 | // Auto-select default qwen3:0.6b if available and not chosen yet |
| 26 | if(!value && list.includes('qwen3:0.6b')){ |
| 27 | onChange('qwen3:0.6b'); |
| 28 | } |
| 29 | setLoading(false); |
| 30 | }) |
| 31 | .catch((e) => { |
| 32 | if (!mounted) return; |
| 33 | setError(String(e)); |
| 34 | setLoading(false); |
| 35 | }); |
| 36 | return () => { |
| 37 | mounted = false; |
| 38 | }; |
| 39 | }, [type]); |
| 40 | |
| 41 | if (loading) { |
| 42 | return ( |
| 43 | <select className={className} disabled> |
| 44 | <option>Loading…</option> |
| 45 | </select> |
| 46 | ); |
| 47 | } |
| 48 | if (error || models.length === 0) { |
| 49 | return ( |
| 50 | <select className={className} disabled> |
| 51 | <option>No models</option> |
| 52 | </select> |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | return ( |
| 57 | <select |
| 58 | className={`w-full px-3 py-2 bg-gray-700 border border-gray-600 rounded-lg text-white text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent ${className || ''}`} |
| 59 | value={value || ''} |
| 60 | onChange={(e) => onChange(e.target.value)} |
| 61 | > |
| 62 | <option value="" disabled> |
| 63 | {placeholder || `Select ${type === 'generation' ? 'LLM' : 'embed model'}`} |
| 64 | </option> |
| 65 | {models.map((m) => ( |
| 66 | <option key={m} value={m}> |
| 67 | {m} |
| 68 | </option> |
| 69 | ))} |