From b1b33240011ddd1326d286f41930ff1dae375191 Mon Sep 17 00:00:00 2001 From: shatfield4 Date: Fri, 9 Aug 2024 17:18:01 -0700 Subject: [PATCH 1/2] implement auto url detection for localai --- .../LocalAiOptions/index.jsx | 102 ++++++++++++----- .../LLMSelection/LocalAiOptions/index.jsx | 104 +++++++++++++----- frontend/src/utils/constants.js | 7 ++ 3 files changed, 156 insertions(+), 57 deletions(-) diff --git a/frontend/src/components/EmbeddingSelection/LocalAiOptions/index.jsx b/frontend/src/components/EmbeddingSelection/LocalAiOptions/index.jsx index d75da68b8c0..988eebac4f4 100644 --- a/frontend/src/components/EmbeddingSelection/LocalAiOptions/index.jsx +++ b/frontend/src/components/EmbeddingSelection/LocalAiOptions/index.jsx @@ -1,41 +1,36 @@ import React, { useEffect, useState } from "react"; +import { CaretDown, CaretUp } from "@phosphor-icons/react"; 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 }) { - const [basePathValue, setBasePathValue] = useState( - settings?.EmbeddingBasePath - ); - const [basePath, setBasePath] = useState(settings?.EmbeddingBasePath); + const { + autoDetecting: loading, + basePath, + basePathValue, + showAdvancedControls, + setShowAdvancedControls, + handleAutoDetectClick, + } = useProviderEndpointAutoDiscovery({ + provider: "localai", + initialBasePath: settings?.EmbeddingBasePath, + ENDPOINTS: LOCALAI_COMMON_URLS, + }); const [apiKeyValue, setApiKeyValue] = useState(settings?.LocalAiApiKey); const [apiKey, setApiKey] = useState(settings?.LocalAiApiKey); return (
-
- - setBasePathValue(e.target.value)} - onBlur={() => setBasePath(basePathValue)} - required={true} - autoComplete="off" - spellCheck={false} - /> -
-
-
-
-
+
+
+ +
+
); } @@ -102,7 +148,7 @@ function LocalAIModelSelection({ settings, apiKey = null, basePath = null }) { if (loading || customModels.length == 0) { return (
-