From 0c3de9b6b24f4feebb1cced44479ce53a839903d Mon Sep 17 00:00:00 2001 From: deep1401 <gandhi0869@gmail.com> Date: Tue, 25 Feb 2025 10:01:04 -0800 Subject: [PATCH] Fixing all broken things to work with WandB and Model Providers both --- .../Experiment/DynamicPluginForm.tsx | 32 ++-------- .../components/TransformerLabSettings.tsx | 59 ++++--------------- 2 files changed, 17 insertions(+), 74 deletions(-) diff --git a/src/renderer/components/Experiment/DynamicPluginForm.tsx b/src/renderer/components/Experiment/DynamicPluginForm.tsx index 16329ba6..bf43e7c4 100644 --- a/src/renderer/components/Experiment/DynamicPluginForm.tsx +++ b/src/renderer/components/Experiment/DynamicPluginForm.tsx @@ -425,39 +425,19 @@ function ModelProviderWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F {label: 'Local', value: 'Local'} ] -// const rawDisabledEnvValues = (() => { -// if (disabledEnvValues) { -// return safeJSONParse(disabledEnvValues); -// } -// // Fallback to the uiSchema value if provided. -// return safeJSONParse(uiSchema?.["ui:options"]?.disabledEnvValues); -// })(); +// Keys here are the words in lower case with which the model names start and values are the ENV variables associated to those models const disabledEnvMap = { "claude": "ANTHROPIC_API_KEY", "openai": "OPENAI_API_KEY", "custom": "CUSTOM_API_KEY", } -const configKeysInOrder = ["ANTHROPIC_API_KEY", "OPENAI_API", "CUSTOM_API_KEY"]; - -// Build a mapping and an ordered array of config keys. -// let disabledEnvMap: Record<string, string> = {}; -// const configKeysInOrder: string[] = []; -// if (rawDisabledEnvValues && Array.isArray(rawDisabledEnvValues) && rawDisabledEnvValues.length > 0) { -// rawDisabledEnvValues.forEach((tuple: any) => { -// if (Array.isArray(tuple) && tuple.length >= 2) { -// const envKey = tuple[0].toLowerCase(); -// const configKey = tuple[1]; -// disabledEnvMap[envKey] = configKey; -// configKeysInOrder.push(configKey); -// } -// }); -// } +const configKeysInOrder = disabledEnvMap ? Object.values(disabledEnvMap) : []; - // Determine default value. - const defaultValue = _multiple ? [] : ''; - // Use the provided value or fallback to default. - const currentValue = value !== undefined ? value : defaultValue; +// Determine default value. +const defaultValue = _multiple ? [] : ''; +// Use the provided value or fallback to default. +const currentValue = value !== undefined ? value : defaultValue; // For each config key (in order received), call useSWR. const configResults = configKeysInOrder.map((key) => diff --git a/src/renderer/components/TransformerLabSettings.tsx b/src/renderer/components/TransformerLabSettings.tsx index c0ce65e9..b5ff54b4 100644 --- a/src/renderer/components/TransformerLabSettings.tsx +++ b/src/renderer/components/TransformerLabSettings.tsx @@ -54,6 +54,13 @@ export default function TransformerLabSettings() { mutate: canLogInToHuggingFaceMutate, } = useSWR(chatAPI.Endpoints.Models.HuggingFaceLogin(), fetcher); + const { + data: wandbLoginStatus, + error: wandbLoginStatusError, + isLoading: wandbLoginStatusIsLoading, + mutate: wandbLoginMutate, + } = useSWR(chatAPI.Endpoints.Models.testWandbLogin(), fetcher); + if (showProvidersPage) { return ( <AIProvidersSettings @@ -63,12 +70,8 @@ export default function TransformerLabSettings() { /> ); } - const { - data: wandbLoginStatus, - error: wandbLoginStatusError, - isLoading: wandbLoginStatusIsLoading, - mutate: wandbLoginMutate, - } = useSWR(chatAPI.Endpoints.Models.testWandbLogin(), fetcher); + + return ( <> @@ -139,7 +142,7 @@ export default function TransformerLabSettings() { </FormControl> </> )} - {/* {wandbLoginStatus?.message === 'OK' ? ( + {wandbLoginStatus?.message === 'OK' ? ( <Alert color="success">Login to Weights & Biases Successful</Alert> ) : ( <FormControl sx={{ maxWidth: '500px', mt: 2 }}> @@ -157,7 +160,7 @@ export default function TransformerLabSettings() { Save </Button> </FormControl> - )} */} + )} <Divider sx={{ mt: 2, mb: 2 }} /> <Typography level="title-lg" marginBottom={2}> Providers & Models: @@ -166,47 +169,7 @@ export default function TransformerLabSettings() { <Button variant="soft" onClick={() => setShowProvidersPage(true)}> AI Providers and Models </Button> - {/* <Divider sx={{ mt: 2, mb: 2 }} /> - )}{' '} - <FormControl sx={{ maxWidth: '500px', mt: 2 }}> - <FormLabel>OpenAI API Key</FormLabel> - <Input name="openaiKey" type="password" /> - <Button - onClick={async () => { - const token = document.getElementsByName('openaiKey')[0].value; - await fetch(chatAPI.Endpoints.Config.Set('OPENAI_API_KEY', token)); - await fetch(chatAPI.Endpoints.Models.SetOpenAIKey()); - const response = await fetch(chatAPI.Endpoints.Models.CheckOpenAIAPIKey()); - const result = await response.json(); - if (result.message === 'OK') { - alert('Successfully set OpenAI API Key'); - } - }} - sx={{ marginTop: 1, width: '100px', alignSelf: 'flex-end' }} - > - Save - </Button> - </FormControl> - <FormControl sx={{ maxWidth: '500px', mt: 2 }}> - <FormLabel>Anthropic API Key</FormLabel> - <Input name="anthropicKey" type="password" /> - <Button - onClick={async () => { - const token = document.getElementsByName('anthropicKey')[0].value; - await fetch(chatAPI.Endpoints.Config.Set('ANTHROPIC_API_KEY', token)); - await fetch(chatAPI.Endpoints.Models.SetAnthropicKey()); - const response = await fetch(chatAPI.Endpoints.Models.CheckAnthropicAPIKey()); - const result = await response.json(); - if (result.message === 'OK') { - alert('Successfully set Anthropic API Key'); - } - }} - sx={{ marginTop: 1, width: '100px', alignSelf: 'flex-end' }} - > - Save - </Button> - </FormControl> */} <Divider sx={{ mt: 2, mb: 2 }} /> <Typography level="title-lg" marginBottom={2}> Application: -- GitLab