import React, { useEffect, useState } from "react"; import { Info, CaretDown, CaretUp } from "@phosphor-icons/react"; import paths from "@/utils/paths"; import System from "@/models/system"; import PreLoader from "@/components/Preloader"; import { LOCALAI_COMMON_URLS } from "@/utils/constants"; import useProviderEndpointAutoDiscovery from "@/hooks/useProviderEndpointAutoDiscovery"; export default function LocalAiOptions({ settings, showAlert = false }) { const { autoDetecting: loading, basePath, basePathValue, showAdvancedControls, setShowAdvancedControls, handleAutoDetectClick, } = useProviderEndpointAutoDiscovery({ provider: "localai", initialBasePath: settings?.LocalAiBasePath, ENDPOINTS: LOCALAI_COMMON_URLS, }); const [apiKeyValue, setApiKeyValue] = useState(settings?.LocalAiApiKey); const [apiKey, setApiKey] = useState(settings?.LocalAiApiKey); return (
{showAlert && (

LocalAI as your LLM requires you to set an embedding service to use.

Manage embedding →
)}
{!settings?.credentialsOnly && ( <>
e.target.blur()} defaultValue={settings?.LocalAiTokenLimit} required={true} autoComplete="off" />
)}
setApiKeyValue(e.target.value)} onBlur={() => setApiKey(apiKeyValue)} />
); } function LocalAIModelSelection({ settings, basePath = null, apiKey = null }) { const [customModels, setCustomModels] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { async function findCustomModels() { if (!basePath || !basePath.includes("/v1")) { setCustomModels([]); setLoading(false); return; } setLoading(true); const { models } = await System.customModels( "localai", typeof apiKey === "boolean" ? null : apiKey, basePath ); setCustomModels(models || []); setLoading(false); } findCustomModels(); }, [basePath, apiKey]); if (loading || customModels.length == 0) { return (
); } return (
); }