"use client" import { useState, useEffect } from "react" import { getAvailableModels } from "../lib/api" interface Model { id: string name: string backend?: string tag?: 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() // Combine Groq and HF Spaces models const combined: Model[] = [ ...(data.groq_models || []).map((m: any) => ({ id: m.id, name: m.name, backend: "groq", tag: "groq" })), ...(data.hf_spaces_models || []).map((m: any) => ({ id: m.id, name: m.name, backend: "hf", tag: "hf-spaces" })) ] setAllModels(combined) } catch (err) { console.error("Failed to fetch models:", err) // Fallback to default Groq models setAllModels([ { id: "llama-3.1-8b-instant", name: "Llama 3.1 8B", backend: "groq", tag: "groq" }, { id: "llama-3.1-70b-versatile", name: "Llama 3.1 70B", backend: "groq", tag: "groq" }, { id: "mixtral-8x7b-32768", name: "Mixtral 8x7B", backend: "groq", tag: "groq" }, { id: "gemma-7b-it", name: "Gemma 7B", backend: "groq", tag: "groq" }, ]) } finally { setLoading(false) } } fetchModels() }, []) if (loading) { return (
Loading models...
) } // Group models by backend const groqModels = allModels.filter(m => m.backend === "groq") const hfModels = allModels.filter(m => m.backend === "hf") return (

Select Survivors ({models.length}/6)

{/* Groq Models */} {groqModels.length > 0 && (

Groq API

{groqModels.map((m) => { const isSelected = models.includes(m.id) return ( ) })}
)} {/* HF Spaces Models */} {hfModels.length > 0 && (

HuggingFace Spaces

{hfModels.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}
) })}
)}
) }