import { useState, useEffect } from "react"; import System from "@/models/system"; export default function OpenAiOptions({ settings }) { const [inputValue, setInputValue] = useState(settings?.OpenAiKey); const [openAIKey, setOpenAIKey] = useState(settings?.OpenAiKey); return (
setInputValue(e.target.value)} onBlur={() => setOpenAIKey(inputValue)} />
{!settings?.credentialsOnly && ( )}
); } function OpenAIModelSelection({ apiKey, settings }) { const [groupedModels, setGroupedModels] = useState({}); const [loading, setLoading] = useState(true); useEffect(() => { async function findCustomModels() { setLoading(true); const { models } = await System.customModels( "openai", typeof apiKey === "boolean" ? null : apiKey ); if (models?.length > 0) { const modelsByOrganization = models.reduce((acc, model) => { acc[model.organization] = acc[model.organization] || []; acc[model.organization].push(model); return acc; }, {}); setGroupedModels(modelsByOrganization); } setLoading(false); } findCustomModels(); }, [apiKey]); if (loading) { return (
); } return (
); }