From 705aa158b740467121a2c27125e8f6646e05068c Mon Sep 17 00:00:00 2001 From: timothycarambat Date: Thu, 16 Nov 2023 15:31:43 -0800 Subject: [PATCH] move embedding options to their own component --- .../AzureAiOptions/index.jsx | 53 +++++ .../LocalAiOptions/index.jsx | 105 ++++++++++ .../OpenAiOptions/index.jsx | 34 ++++ .../EmbeddingPreference/index.jsx | 192 +----------------- .../Steps/EmbeddingSelection/index.jsx | 190 +---------------- 5 files changed, 204 insertions(+), 370 deletions(-) create mode 100644 frontend/src/components/EmbeddingSelection/AzureAiOptions/index.jsx create mode 100644 frontend/src/components/EmbeddingSelection/LocalAiOptions/index.jsx create mode 100644 frontend/src/components/EmbeddingSelection/OpenAiOptions/index.jsx diff --git a/frontend/src/components/EmbeddingSelection/AzureAiOptions/index.jsx b/frontend/src/components/EmbeddingSelection/AzureAiOptions/index.jsx new file mode 100644 index 00000000000..e7767900aec --- /dev/null +++ b/frontend/src/components/EmbeddingSelection/AzureAiOptions/index.jsx @@ -0,0 +1,53 @@ +export default function AzureAiOptions({ settings }) { + return ( + <> +
+ + +
+ +
+ + +
+ +
+ + +
+ + ); +} diff --git a/frontend/src/components/EmbeddingSelection/LocalAiOptions/index.jsx b/frontend/src/components/EmbeddingSelection/LocalAiOptions/index.jsx new file mode 100644 index 00000000000..109da0e4f92 --- /dev/null +++ b/frontend/src/components/EmbeddingSelection/LocalAiOptions/index.jsx @@ -0,0 +1,105 @@ +import { useEffect, useState } from "react"; +import System from "../../../models/system"; + +export default function LocalAiOptions({ settings }) { + const [basePathValue, setBasePathValue] = useState( + settings?.EmbeddingBasePath + ); + const [basePath, setBasePath] = useState(settings?.EmbeddingBasePath); + function updateBasePath() { + setBasePath(basePathValue); + } + + return ( + <> +
+ + setBasePathValue(e.target.value)} + onBlur={updateBasePath} + required={true} + autoComplete="off" + spellCheck={false} + /> +
+ + + ); +} + +function LocalAIModelSelection({ settings, basePath = 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", null, basePath); + setCustomModels(models || []); + setLoading(false); + } + findCustomModels(); + }, [basePath]); + + if (loading || customModels.length == 0) { + return ( +
+ + +
+ ); + } + + return ( +
+ + +
+ ); +} diff --git a/frontend/src/components/EmbeddingSelection/OpenAiOptions/index.jsx b/frontend/src/components/EmbeddingSelection/OpenAiOptions/index.jsx new file mode 100644 index 00000000000..f38f7c445ee --- /dev/null +++ b/frontend/src/components/EmbeddingSelection/OpenAiOptions/index.jsx @@ -0,0 +1,34 @@ +export default function OpenAiOptions({ settings }) { + return ( + <> +
+ + +
+
+ + +
+ + ); +} diff --git a/frontend/src/pages/GeneralSettings/EmbeddingPreference/index.jsx b/frontend/src/pages/GeneralSettings/EmbeddingPreference/index.jsx index cc272edb3ac..9a53ac8269f 100644 --- a/frontend/src/pages/GeneralSettings/EmbeddingPreference/index.jsx +++ b/frontend/src/pages/GeneralSettings/EmbeddingPreference/index.jsx @@ -11,6 +11,9 @@ import LocalAiLogo from "../../../media/llmprovider/localai.png"; import PreLoader from "../../../components/Preloader"; import LLMProviderOption from "../../../components/LLMSelection/LLMProviderOption"; import ChangeWarningModal from "../../../components/ChangeWarning"; +import OpenAiOptions from "../../../components/EmbeddingSelection/OpenAiOptions"; +import AzureAiOptions from "../../../components/EmbeddingSelection/AzureAiOptions"; +import LocalAiOptions from "../../../components/EmbeddingSelection/LocalAiOptions"; export default function GeneralEmbeddingPreference() { const [saving, setSaving] = useState(false); @@ -19,8 +22,6 @@ export default function GeneralEmbeddingPreference() { const [embeddingChoice, setEmbeddingChoice] = useState("openai"); const [settings, setSettings] = useState(null); const [loading, setLoading] = useState(true); - const [basePathValue, setBasePathValue] = useState(""); - const [basePath, setBasePath] = useState(""); const handleSubmit = async (e) => { e.preventDefault(); @@ -60,17 +61,11 @@ export default function GeneralEmbeddingPreference() { setHasChanges(true); }; - function updateBasePath() { - setBasePath(basePathValue); - } - useEffect(() => { async function fetchKeys() { const _settings = await System.keys(); setSettings(_settings); setEmbeddingChoice(_settings?.EmbeddingEngine || "openai"); - setBasePath(_settings?.EmbeddingBasePath || ""); - setBasePathValue(_settings?.EmbeddingBasePath || ""); setHasEmbeddings(_settings?.HasExistingEmbeddings || false); setLoading(false); } @@ -173,118 +168,13 @@ export default function GeneralEmbeddingPreference() {
{embeddingChoice === "openai" && ( - <> -
- - -
-
- - -
- + )} - {embeddingChoice === "azure" && ( - <> -
- - -
- -
- - -
- -
- - -
- + )} - {embeddingChoice === "localai" && ( - <> -
- - setBasePathValue(e.target.value)} - onBlur={updateBasePath} - required={true} - autoComplete="off" - spellCheck={false} - /> -
- - + )}
@@ -295,73 +185,3 @@ export default function GeneralEmbeddingPreference() { ); } - -function LocalAIModelSelection({ settings, basePath = 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", null, basePath); - setCustomModels(models || []); - setLoading(false); - } - findCustomModels(); - }, [basePath]); - - if (loading || customModels.length == 0) { - return ( -
- - -
- ); - } - - return ( -
- - -
- ); -} diff --git a/frontend/src/pages/OnboardingFlow/OnboardingModal/Steps/EmbeddingSelection/index.jsx b/frontend/src/pages/OnboardingFlow/OnboardingModal/Steps/EmbeddingSelection/index.jsx index da90cc4f2f1..d2edef60644 100644 --- a/frontend/src/pages/OnboardingFlow/OnboardingModal/Steps/EmbeddingSelection/index.jsx +++ b/frontend/src/pages/OnboardingFlow/OnboardingModal/Steps/EmbeddingSelection/index.jsx @@ -5,28 +5,23 @@ import LocalAiLogo from "../../../../../media/llmprovider/localai.png"; import System from "../../../../../models/system"; import PreLoader from "../../../../../components/Preloader"; import LLMProviderOption from "../../../../../components/LLMSelection/LLMProviderOption"; +import OpenAiOptions from "../../../../../components/EmbeddingSelection/OpenAiOptions"; +import AzureAiOptions from "../../../../../components/EmbeddingSelection/AzureAiOptions"; +import LocalAiOptions from "../../../../../components/EmbeddingSelection/LocalAiOptions"; function EmbeddingSelection({ nextStep, prevStep, currentStep }) { const [embeddingChoice, setEmbeddingChoice] = useState("openai"); const [settings, setSettings] = useState(null); const [loading, setLoading] = useState(true); - const [basePathValue, setBasePathValue] = useState(""); - const [basePath, setBasePath] = useState(""); - const updateChoice = (selection) => { setEmbeddingChoice(selection); }; - function updateBasePath() { - setBasePath(basePathValue); - } - useEffect(() => { async function fetchKeys() { const _settings = await System.keys(); setSettings(_settings); setEmbeddingChoice(_settings?.EmbeddingEngine || "openai"); - setBasePathValue(_settings?.EmbeddingBasePath || ""); setLoading(false); } fetchKeys(); @@ -97,116 +92,13 @@ function EmbeddingSelection({ nextStep, prevStep, currentStep }) {
{embeddingChoice === "openai" && ( - <> -
- - -
-
- - -
- + )} - {embeddingChoice === "azure" && ( - <> -
- - -
- -
- - -
- -
- - -
- + )} - {embeddingChoice === "localai" && ( - <> -
- - setBasePathValue(e.target.value)} - onBlur={updateBasePath} - required={true} - autoComplete="off" - spellCheck={false} - /> -
- - + )}
@@ -230,74 +122,4 @@ function EmbeddingSelection({ nextStep, prevStep, currentStep }) { ); } -function LocalAIModelSelection({ settings, basePath = 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", null, basePath); - setCustomModels(models || []); - setLoading(false); - } - findCustomModels(); - }, [basePath]); - - if (loading || customModels.length == 0) { - return ( -
- - -
- ); - } - - return ( -
- - -
- ); -} - export default memo(EmbeddingSelection);