"use client" import { useState, useEffect } from "react" import { getAvailableModels } from "../lib/api" interface Model { id: string name: string description?: string } export default function ModelSelector({ models, onAdd, onRemove, }: { models: string[] onAdd: (id: string) => void onRemove: (id: string) => void }) { const [allModels, setAllModels] = useState([]) const [loading, setLoading] = useState(true) const full = models.length >= 6 useEffect(() => { async function fetchModels() { try { const data = await getAvailableModels() // Use unified model list (no backend categorization) // Support multiple backend response formats (new unified `models` or legacy grouped keys) if (data.models && Array.isArray(data.models)) { setAllModels(data.models) } else { const groq = data.groq_models || data.groqModels || data.groq || [] const hf = data.hf_spaces_models || data.hf_spaces || data.hf_models || data.hfModels || [] const merged: Model[] = [] if (Array.isArray(groq)) { for (const g of groq) merged.push({ id: g.id, name: g.name || g.id, description: g.description || g.backend || '' }) } if (Array.isArray(hf)) { for (const h of hf) merged.push({ id: h.id, name: h.name || h.id, description: h.description || h.space_url || '' }) } if (merged.length > 0) setAllModels(merged) else setAllModels([]) } } catch (err) { console.error("Failed to fetch models:", err) // Fallback to default models setAllModels([ { id: "mixtral-8x7b-32768", name: "Mixtral 8x7B", description: "High-performance model" }, { id: "llama2-70b-4096", name: "Llama 2 70B", description: "Large instruction-tuned model" }, { id: "mistralai/Mistral-7B-Instruct-v0.2", name: "Mistral 7B", description: "Fast 7B model" }, { id: "NousResearch/Nous-Hermes-2-Mistral-7B-DPO", name: "Nous Hermes 2", description: "High-quality model" }, ]) } finally { setLoading(false) } } fetchModels() }, []) if (loading) { return (
Loading models...
) } return (

Select Survivors ({models.length}/6)

{allModels.map((m) => { const isSelected = models.includes(m.id) return ( ) })}
{models.length > 0 && (
{models.map(id => { const model = allModels.find(m => m.id === id) return (
{model?.name || id.split("/").pop()}
) })}
)}
) }