implemented getting key from env
This commit is contained in:
parent
ac15e36733
commit
1034fa2635
2 changed files with 40 additions and 22 deletions
|
|
@ -90,7 +90,6 @@ export const useGetOllamaModelsQuery = (
|
||||||
queryKey: ["models", "ollama", params],
|
queryKey: ["models", "ollama", params],
|
||||||
queryFn: getOllamaModels,
|
queryFn: getOllamaModels,
|
||||||
retry: 2,
|
retry: 2,
|
||||||
enabled: !!params?.endpoint, // Only run if endpoint is provided
|
|
||||||
staleTime: 0, // Always fetch fresh data
|
staleTime: 0, // Always fetch fresh data
|
||||||
gcTime: 0, // Don't cache results
|
gcTime: 0, // Don't cache results
|
||||||
...options,
|
...options,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { LabelInput } from "@/components/label-input";
|
import { LabelInput } from "@/components/label-input";
|
||||||
|
import { LabelWrapper } from "@/components/label-wrapper";
|
||||||
import OpenAILogo from "@/components/logo/openai-logo";
|
import OpenAILogo from "@/components/logo/openai-logo";
|
||||||
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { useDebouncedValue } from "@/lib/debounce";
|
import { useDebouncedValue } from "@/lib/debounce";
|
||||||
import type { OnboardingVariables } from "../../api/mutations/useOnboardingMutation";
|
import type { OnboardingVariables } from "../../api/mutations/useOnboardingMutation";
|
||||||
import { useGetOpenAIModelsQuery } from "../../api/queries/useGetModelsQuery";
|
import { useGetOpenAIModelsQuery } from "../../api/queries/useGetModelsQuery";
|
||||||
|
|
@ -18,6 +20,7 @@ export function OpenAIOnboarding({
|
||||||
setSampleDataset: (dataset: boolean) => void;
|
setSampleDataset: (dataset: boolean) => void;
|
||||||
}) {
|
}) {
|
||||||
const [apiKey, setApiKey] = useState("");
|
const [apiKey, setApiKey] = useState("");
|
||||||
|
const [getFromEnv, setGetFromEnv] = useState(true);
|
||||||
const debouncedApiKey = useDebouncedValue(apiKey, 500);
|
const debouncedApiKey = useDebouncedValue(apiKey, 500);
|
||||||
|
|
||||||
// Fetch models from API when API key is provided
|
// Fetch models from API when API key is provided
|
||||||
|
|
@ -26,7 +29,12 @@ export function OpenAIOnboarding({
|
||||||
isLoading: isLoadingModels,
|
isLoading: isLoadingModels,
|
||||||
error: modelsError,
|
error: modelsError,
|
||||||
} = useGetOpenAIModelsQuery(
|
} = useGetOpenAIModelsQuery(
|
||||||
debouncedApiKey ? { apiKey: debouncedApiKey } : undefined,
|
getFromEnv
|
||||||
|
? { apiKey: "" }
|
||||||
|
: debouncedApiKey
|
||||||
|
? { apiKey: debouncedApiKey }
|
||||||
|
: undefined,
|
||||||
|
{ enabled: debouncedApiKey !== "" || getFromEnv },
|
||||||
);
|
);
|
||||||
// Use custom hook for model selection logic
|
// Use custom hook for model selection logic
|
||||||
const {
|
const {
|
||||||
|
|
@ -53,6 +61,15 @@ export function OpenAIOnboarding({
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<div className="space-y-5">
|
||||||
|
<LabelWrapper
|
||||||
|
label="Get API key from environment variable"
|
||||||
|
id="get-api-key"
|
||||||
|
flex
|
||||||
|
>
|
||||||
|
<Switch checked={getFromEnv} onCheckedChange={setGetFromEnv} />
|
||||||
|
</LabelWrapper>
|
||||||
|
{!getFromEnv && (
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<LabelInput
|
<LabelInput
|
||||||
label="OpenAI API key"
|
label="OpenAI API key"
|
||||||
|
|
@ -75,6 +92,8 @@ export function OpenAIOnboarding({
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<AdvancedOnboarding
|
<AdvancedOnboarding
|
||||||
icon={<OpenAILogo className="w-4 h-4" />}
|
icon={<OpenAILogo className="w-4 h-4" />}
|
||||||
languageModels={languageModels}
|
languageModels={languageModels}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue