2024-05-24 13:58:14 +00:00
|
|
|
import { cn } from '@/lib/utils';
|
2024-10-11 05:05:33 +00:00
|
|
|
import {
|
|
|
|
Dialog,
|
|
|
|
DialogPanel,
|
|
|
|
DialogTitle,
|
|
|
|
Transition,
|
|
|
|
TransitionChild,
|
|
|
|
} from '@headlessui/react';
|
2024-04-23 11:22:41 +00:00
|
|
|
import { CloudUpload, RefreshCcw, RefreshCw } from 'lucide-react';
|
2024-05-24 13:58:14 +00:00
|
|
|
import React, {
|
|
|
|
Fragment,
|
|
|
|
useEffect,
|
|
|
|
useState,
|
|
|
|
type SelectHTMLAttributes,
|
|
|
|
} from 'react';
|
2024-06-02 06:49:53 +00:00
|
|
|
import ThemeSwitcher from './theme/Switcher';
|
2024-05-24 13:58:14 +00:00
|
|
|
|
|
|
|
interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}
|
|
|
|
|
2024-05-30 16:08:37 +00:00
|
|
|
const Input = ({ className, ...restProps }: InputProps) => {
|
2024-05-24 13:58:14 +00:00
|
|
|
return (
|
|
|
|
<input
|
|
|
|
{...restProps}
|
|
|
|
className={cn(
|
2024-05-29 04:10:24 +00:00
|
|
|
'bg-light-secondary dark:bg-dark-secondary px-3 py-2 flex items-center overflow-hidden border border-light-200 dark:border-dark-200 dark:text-white rounded-lg text-sm',
|
2024-05-24 13:58:14 +00:00
|
|
|
className,
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
2024-05-30 16:08:37 +00:00
|
|
|
};
|
2024-05-24 13:58:14 +00:00
|
|
|
|
|
|
|
interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> {
|
|
|
|
options: { value: string; label: string; disabled?: boolean }[];
|
|
|
|
}
|
|
|
|
|
2024-06-02 06:49:53 +00:00
|
|
|
export const Select = ({ className, options, ...restProps }: SelectProps) => {
|
2024-05-24 13:58:14 +00:00
|
|
|
return (
|
|
|
|
<select
|
|
|
|
{...restProps}
|
|
|
|
className={cn(
|
2024-05-29 04:10:24 +00:00
|
|
|
'bg-light-secondary dark:bg-dark-secondary px-3 py-2 flex items-center overflow-hidden border border-light-200 dark:border-dark-200 dark:text-white rounded-lg text-sm',
|
2024-05-24 13:58:14 +00:00
|
|
|
className,
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{options.map(({ label, value, disabled }) => {
|
|
|
|
return (
|
|
|
|
<option key={value} value={value} disabled={disabled}>
|
|
|
|
{label}
|
|
|
|
</option>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</select>
|
|
|
|
);
|
2024-05-30 16:08:37 +00:00
|
|
|
};
|
2024-04-23 11:22:41 +00:00
|
|
|
|
|
|
|
interface SettingsType {
|
2024-05-04 05:21:06 +00:00
|
|
|
chatModelProviders: {
|
2024-09-24 17:04:43 +00:00
|
|
|
[key: string]: [Record<string, any>];
|
2024-05-04 05:21:06 +00:00
|
|
|
};
|
|
|
|
embeddingModelProviders: {
|
2024-09-24 17:04:43 +00:00
|
|
|
[key: string]: [Record<string, any>];
|
2024-04-23 11:22:41 +00:00
|
|
|
};
|
2024-05-02 09:34:33 +00:00
|
|
|
openaiApiKey: string;
|
2024-05-01 14:13:06 +00:00
|
|
|
groqApiKey: string;
|
2024-07-15 15:50:16 +00:00
|
|
|
anthropicApiKey: string;
|
2024-11-28 15:17:18 +00:00
|
|
|
geminiApiKey: string;
|
2024-04-23 11:22:41 +00:00
|
|
|
ollamaApiUrl: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SettingsDialog = ({
|
|
|
|
isOpen,
|
|
|
|
setIsOpen,
|
|
|
|
}: {
|
|
|
|
isOpen: boolean;
|
|
|
|
setIsOpen: (isOpen: boolean) => void;
|
|
|
|
}) => {
|
|
|
|
const [config, setConfig] = useState<SettingsType | null>(null);
|
2024-09-24 17:04:43 +00:00
|
|
|
const [chatModels, setChatModels] = useState<Record<string, any>>({});
|
|
|
|
const [embeddingModels, setEmbeddingModels] = useState<Record<string, any>>(
|
|
|
|
{},
|
|
|
|
);
|
2024-05-02 06:44:26 +00:00
|
|
|
const [selectedChatModelProvider, setSelectedChatModelProvider] = useState<
|
|
|
|
string | null
|
|
|
|
>(null);
|
|
|
|
const [selectedChatModel, setSelectedChatModel] = useState<string | null>(
|
|
|
|
null,
|
|
|
|
);
|
2024-05-04 05:21:06 +00:00
|
|
|
const [selectedEmbeddingModelProvider, setSelectedEmbeddingModelProvider] =
|
|
|
|
useState<string | null>(null);
|
|
|
|
const [selectedEmbeddingModel, setSelectedEmbeddingModel] = useState<
|
|
|
|
string | null
|
|
|
|
>(null);
|
2024-05-06 14:30:56 +00:00
|
|
|
const [customOpenAIApiKey, setCustomOpenAIApiKey] = useState<string>('');
|
|
|
|
const [customOpenAIBaseURL, setCustomOpenAIBaseURL] = useState<string>('');
|
2024-04-23 11:22:41 +00:00
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
const [isUpdating, setIsUpdating] = useState(false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (isOpen) {
|
|
|
|
const fetchConfig = async () => {
|
|
|
|
setIsLoading(true);
|
2024-05-04 09:31:53 +00:00
|
|
|
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/config`, {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
});
|
2024-05-06 14:30:56 +00:00
|
|
|
|
|
|
|
const data = (await res.json()) as SettingsType;
|
2024-04-23 11:22:41 +00:00
|
|
|
setConfig(data);
|
2024-05-06 14:30:56 +00:00
|
|
|
|
|
|
|
const chatModelProvidersKeys = Object.keys(
|
|
|
|
data.chatModelProviders || {},
|
|
|
|
);
|
|
|
|
const embeddingModelProvidersKeys = Object.keys(
|
|
|
|
data.embeddingModelProviders || {},
|
2024-05-06 07:04:59 +00:00
|
|
|
);
|
2024-05-06 14:30:56 +00:00
|
|
|
|
|
|
|
const defaultChatModelProvider =
|
|
|
|
chatModelProvidersKeys.length > 0 ? chatModelProvidersKeys[0] : '';
|
|
|
|
const defaultEmbeddingModelProvider =
|
|
|
|
embeddingModelProvidersKeys.length > 0
|
|
|
|
? embeddingModelProvidersKeys[0]
|
|
|
|
: '';
|
|
|
|
|
|
|
|
const chatModelProvider =
|
|
|
|
localStorage.getItem('chatModelProvider') ||
|
|
|
|
defaultChatModelProvider ||
|
|
|
|
'';
|
|
|
|
const chatModel =
|
|
|
|
localStorage.getItem('chatModel') ||
|
|
|
|
(data.chatModelProviders &&
|
2024-10-18 11:37:09 +00:00
|
|
|
data.chatModelProviders[chatModelProvider]?.length > 0
|
|
|
|
? data.chatModelProviders[chatModelProvider][0].name
|
|
|
|
: undefined) ||
|
2024-05-06 14:30:56 +00:00
|
|
|
'';
|
|
|
|
const embeddingModelProvider =
|
|
|
|
localStorage.getItem('embeddingModelProvider') ||
|
|
|
|
defaultEmbeddingModelProvider ||
|
|
|
|
'';
|
|
|
|
const embeddingModel =
|
|
|
|
localStorage.getItem('embeddingModel') ||
|
|
|
|
(data.embeddingModelProviders &&
|
2024-09-24 17:04:43 +00:00
|
|
|
data.embeddingModelProviders[embeddingModelProvider]?.[0].name) ||
|
2024-05-06 14:30:56 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
setSelectedChatModelProvider(chatModelProvider);
|
|
|
|
setSelectedChatModel(chatModel);
|
|
|
|
setSelectedEmbeddingModelProvider(embeddingModelProvider);
|
|
|
|
setSelectedEmbeddingModel(embeddingModel);
|
|
|
|
setCustomOpenAIApiKey(localStorage.getItem('openAIApiKey') || '');
|
2024-05-09 07:53:57 +00:00
|
|
|
setCustomOpenAIBaseURL(localStorage.getItem('openAIBaseURL') || '');
|
2024-09-24 17:04:43 +00:00
|
|
|
setChatModels(data.chatModelProviders || {});
|
|
|
|
setEmbeddingModels(data.embeddingModelProviders || {});
|
2024-04-23 11:22:41 +00:00
|
|
|
setIsLoading(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
fetchConfig();
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [isOpen]);
|
|
|
|
|
|
|
|
const handleSubmit = async () => {
|
|
|
|
setIsUpdating(true);
|
2024-07-18 19:54:02 +00:00
|
|
|
|
2024-04-23 11:22:41 +00:00
|
|
|
try {
|
2024-07-18 19:54:02 +00:00
|
|
|
await fetch(`${process.env.NEXT_PUBLIC_API_URL}/settings`, {
|
2024-04-23 11:22:41 +00:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
2024-07-18 19:54:02 +00:00
|
|
|
body: JSON.stringify({
|
|
|
|
chatModelProvider: selectedChatModelProvider,
|
|
|
|
chatModel: selectedChatModel,
|
|
|
|
embeddingModelProvider: selectedEmbeddingModelProvider,
|
|
|
|
embeddingModel: selectedEmbeddingModel,
|
|
|
|
openAIApiKey: customOpenAIApiKey,
|
|
|
|
openAIBaseURL: customOpenAIBaseURL,
|
|
|
|
}),
|
2024-04-23 11:22:41 +00:00
|
|
|
});
|
2024-07-18 19:54:02 +00:00
|
|
|
|
|
|
|
// Still keep localStorage for quick access on the client-side
|
2024-05-02 06:44:26 +00:00
|
|
|
localStorage.setItem('chatModelProvider', selectedChatModelProvider!);
|
|
|
|
localStorage.setItem('chatModel', selectedChatModel!);
|
2024-07-18 19:54:02 +00:00
|
|
|
localStorage.setItem('embeddingModelProvider', selectedEmbeddingModelProvider!);
|
2024-05-04 05:21:06 +00:00
|
|
|
localStorage.setItem('embeddingModel', selectedEmbeddingModel!);
|
|
|
|
localStorage.setItem('openAIApiKey', customOpenAIApiKey!);
|
|
|
|
localStorage.setItem('openAIBaseURL', customOpenAIBaseURL!);
|
2024-04-23 11:22:41 +00:00
|
|
|
} catch (err) {
|
2024-07-18 19:54:02 +00:00
|
|
|
console.error(err);
|
2024-04-23 11:22:41 +00:00
|
|
|
} finally {
|
|
|
|
setIsUpdating(false);
|
|
|
|
setIsOpen(false);
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Transition appear show={isOpen} as={Fragment}>
|
|
|
|
<Dialog
|
|
|
|
as="div"
|
|
|
|
className="relative z-50"
|
|
|
|
onClose={() => setIsOpen(false)}
|
|
|
|
>
|
2024-10-11 05:05:33 +00:00
|
|
|
<TransitionChild
|
2024-04-23 11:22:41 +00:00
|
|
|
as={Fragment}
|
|
|
|
enter="ease-out duration-300"
|
|
|
|
enterFrom="opacity-0"
|
|
|
|
enterTo="opacity-100"
|
|
|
|
leave="ease-in duration-200"
|
|
|
|
leaveFrom="opacity-100"
|
|
|
|
leaveTo="opacity-0"
|
|
|
|
>
|
2024-05-24 12:29:49 +00:00
|
|
|
<div className="fixed inset-0 bg-white/50 dark:bg-black/50" />
|
2024-10-11 05:05:33 +00:00
|
|
|
</TransitionChild>
|
2024-04-23 11:22:41 +00:00
|
|
|
<div className="fixed inset-0 overflow-y-auto">
|
|
|
|
<div className="flex min-h-full items-center justify-center p-4 text-center">
|
2024-10-11 05:05:33 +00:00
|
|
|
<TransitionChild
|
2024-04-23 11:22:41 +00:00
|
|
|
as={Fragment}
|
|
|
|
enter="ease-out duration-200"
|
|
|
|
enterFrom="opacity-0 scale-95"
|
|
|
|
enterTo="opacity-100 scale-100"
|
|
|
|
leave="ease-in duration-100"
|
|
|
|
leaveFrom="opacity-100 scale-200"
|
|
|
|
leaveTo="opacity-0 scale-95"
|
|
|
|
>
|
2024-10-11 05:05:33 +00:00
|
|
|
<DialogPanel className="w-full max-w-md transform rounded-2xl bg-light-secondary dark:bg-dark-secondary border border-light-200 dark:border-dark-200 p-6 text-left align-middle shadow-xl transition-all">
|
|
|
|
<DialogTitle className="text-xl font-medium leading-6 dark:text-white">
|
2024-04-23 11:22:41 +00:00
|
|
|
Settings
|
2024-10-11 05:05:33 +00:00
|
|
|
</DialogTitle>
|
2024-04-23 11:22:41 +00:00
|
|
|
{config && !isLoading && (
|
2024-04-23 12:24:08 +00:00
|
|
|
<div className="flex flex-col space-y-4 mt-6">
|
2024-06-02 06:49:53 +00:00
|
|
|
<div className="flex flex-col space-y-1">
|
|
|
|
<p className="text-black/70 dark:text-white/70 text-sm">
|
|
|
|
Theme
|
|
|
|
</p>
|
|
|
|
<ThemeSwitcher />
|
|
|
|
</div>
|
2024-05-04 05:21:06 +00:00
|
|
|
{config.chatModelProviders && (
|
2024-04-23 11:22:41 +00:00
|
|
|
<div className="flex flex-col space-y-1">
|
2024-05-24 12:29:49 +00:00
|
|
|
<p className="text-black/70 dark:text-white/70 text-sm">
|
2024-04-23 11:36:44 +00:00
|
|
|
Chat model Provider
|
|
|
|
</p>
|
2024-05-24 13:58:14 +00:00
|
|
|
<Select
|
2024-05-06 22:35:39 +00:00
|
|
|
value={selectedChatModelProvider ?? undefined}
|
2024-05-02 06:44:26 +00:00
|
|
|
onChange={(e) => {
|
|
|
|
setSelectedChatModelProvider(e.target.value);
|
2024-07-25 15:04:49 +00:00
|
|
|
if (e.target.value === 'custom_openai') {
|
|
|
|
setSelectedChatModel('');
|
|
|
|
} else {
|
|
|
|
setSelectedChatModel(
|
2024-09-24 17:04:43 +00:00
|
|
|
config.chatModelProviders[e.target.value][0]
|
|
|
|
.name,
|
2024-07-25 15:04:49 +00:00
|
|
|
);
|
|
|
|
}
|
2024-05-02 06:44:26 +00:00
|
|
|
}}
|
2024-05-24 13:58:14 +00:00
|
|
|
options={Object.keys(config.chatModelProviders).map(
|
|
|
|
(provider) => ({
|
|
|
|
value: provider,
|
|
|
|
label:
|
|
|
|
provider.charAt(0).toUpperCase() +
|
|
|
|
provider.slice(1),
|
|
|
|
}),
|
2024-05-04 05:21:06 +00:00
|
|
|
)}
|
2024-05-24 13:58:14 +00:00
|
|
|
/>
|
2024-04-23 11:22:41 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2024-05-04 05:21:06 +00:00
|
|
|
{selectedChatModelProvider &&
|
|
|
|
selectedChatModelProvider != 'custom_openai' && (
|
|
|
|
<div className="flex flex-col space-y-1">
|
2024-05-24 12:29:49 +00:00
|
|
|
<p className="text-black/70 dark:text-white/70 text-sm">
|
|
|
|
Chat Model
|
|
|
|
</p>
|
2024-05-24 13:58:14 +00:00
|
|
|
<Select
|
2024-05-06 22:35:39 +00:00
|
|
|
value={selectedChatModel ?? undefined}
|
2024-05-04 05:21:06 +00:00
|
|
|
onChange={(e) =>
|
|
|
|
setSelectedChatModel(e.target.value)
|
|
|
|
}
|
2024-05-24 13:58:14 +00:00
|
|
|
options={(() => {
|
|
|
|
const chatModelProvider =
|
2024-05-04 05:21:06 +00:00
|
|
|
config.chatModelProviders[
|
|
|
|
selectedChatModelProvider
|
2024-05-24 13:58:14 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
return chatModelProvider
|
|
|
|
? chatModelProvider.length > 0
|
|
|
|
? chatModelProvider.map((model) => ({
|
2024-09-24 17:04:43 +00:00
|
|
|
value: model.name,
|
|
|
|
label: model.displayName,
|
2024-05-24 13:58:14 +00:00
|
|
|
}))
|
|
|
|
: [
|
|
|
|
{
|
|
|
|
value: '',
|
|
|
|
label: 'No models available',
|
|
|
|
disabled: true,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
: [
|
|
|
|
{
|
|
|
|
value: '',
|
|
|
|
label:
|
|
|
|
'Invalid provider, please check backend logs',
|
|
|
|
disabled: true,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
})()}
|
|
|
|
/>
|
2024-05-04 05:21:06 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{selectedChatModelProvider &&
|
|
|
|
selectedChatModelProvider === 'custom_openai' && (
|
|
|
|
<>
|
|
|
|
<div className="flex flex-col space-y-1">
|
2024-05-24 12:29:49 +00:00
|
|
|
<p className="text-black/70 dark:text-white/70 text-sm">
|
|
|
|
Model name
|
|
|
|
</p>
|
2024-05-24 13:58:14 +00:00
|
|
|
<Input
|
2024-05-04 05:21:06 +00:00
|
|
|
type="text"
|
|
|
|
placeholder="Model name"
|
|
|
|
defaultValue={selectedChatModel!}
|
|
|
|
onChange={(e) =>
|
|
|
|
setSelectedChatModel(e.target.value)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-col space-y-1">
|
2024-05-24 12:29:49 +00:00
|
|
|
<p className="text-black/70 dark:text-white/70 text-sm">
|
2024-05-06 14:30:56 +00:00
|
|
|
Custom OpenAI API Key
|
2024-05-04 05:21:06 +00:00
|
|
|
</p>
|
2024-05-24 13:58:14 +00:00
|
|
|
<Input
|
2024-05-04 05:21:06 +00:00
|
|
|
type="text"
|
|
|
|
placeholder="Custom OpenAI API Key"
|
|
|
|
defaultValue={customOpenAIApiKey!}
|
|
|
|
onChange={(e) =>
|
|
|
|
setCustomOpenAIApiKey(e.target.value)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-col space-y-1">
|
2024-05-24 12:29:49 +00:00
|
|
|
<p className="text-black/70 dark:text-white/70 text-sm">
|
2024-05-04 05:21:06 +00:00
|
|
|
Custom OpenAI Base URL
|
|
|
|
</p>
|
2024-05-24 13:58:14 +00:00
|
|
|
<Input
|
2024-05-04 05:21:06 +00:00
|
|
|
type="text"
|
|
|
|
placeholder="Custom OpenAI Base URL"
|
|
|
|
defaultValue={customOpenAIBaseURL!}
|
|
|
|
onChange={(e) =>
|
|
|
|
setCustomOpenAIBaseURL(e.target.value)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{/* Embedding models */}
|
2024-05-04 09:31:53 +00:00
|
|
|
{config.embeddingModelProviders && (
|
2024-05-04 05:21:06 +00:00
|
|
|
<div className="flex flex-col space-y-1">
|
2024-05-24 12:29:49 +00:00
|
|
|
<p className="text-black/70 dark:text-white/70 text-sm">
|
2024-05-04 05:21:06 +00:00
|
|
|
Embedding model Provider
|
|
|
|
</p>
|
2024-05-24 13:58:14 +00:00
|
|
|
<Select
|
2024-05-06 22:35:39 +00:00
|
|
|
value={selectedEmbeddingModelProvider ?? undefined}
|
2024-05-04 05:21:06 +00:00
|
|
|
onChange={(e) => {
|
|
|
|
setSelectedEmbeddingModelProvider(e.target.value);
|
|
|
|
setSelectedEmbeddingModel(
|
2024-09-24 17:04:43 +00:00
|
|
|
config.embeddingModelProviders[e.target.value][0]
|
|
|
|
.name,
|
2024-05-04 05:21:06 +00:00
|
|
|
);
|
|
|
|
}}
|
2024-05-24 13:58:14 +00:00
|
|
|
options={Object.keys(
|
|
|
|
config.embeddingModelProviders,
|
|
|
|
).map((provider) => ({
|
|
|
|
label:
|
|
|
|
provider.charAt(0).toUpperCase() +
|
|
|
|
provider.slice(1),
|
|
|
|
value: provider,
|
|
|
|
}))}
|
|
|
|
/>
|
2024-05-04 05:21:06 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{selectedEmbeddingModelProvider && (
|
|
|
|
<div className="flex flex-col space-y-1">
|
2024-05-24 12:29:49 +00:00
|
|
|
<p className="text-black/70 dark:text-white/70 text-sm">
|
|
|
|
Embedding Model
|
|
|
|
</p>
|
2024-05-24 13:58:14 +00:00
|
|
|
<Select
|
2024-05-06 22:35:39 +00:00
|
|
|
value={selectedEmbeddingModel ?? undefined}
|
2024-05-04 05:21:06 +00:00
|
|
|
onChange={(e) =>
|
|
|
|
setSelectedEmbeddingModel(e.target.value)
|
|
|
|
}
|
2024-05-24 13:58:14 +00:00
|
|
|
options={(() => {
|
|
|
|
const embeddingModelProvider =
|
2024-05-04 05:21:06 +00:00
|
|
|
config.embeddingModelProviders[
|
|
|
|
selectedEmbeddingModelProvider
|
2024-05-24 13:58:14 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
return embeddingModelProvider
|
|
|
|
? embeddingModelProvider.length > 0
|
|
|
|
? embeddingModelProvider.map((model) => ({
|
2024-09-24 17:04:43 +00:00
|
|
|
label: model.displayName,
|
|
|
|
value: model.name,
|
2024-05-24 13:58:14 +00:00
|
|
|
}))
|
|
|
|
: [
|
|
|
|
{
|
|
|
|
label: 'No embedding models available',
|
|
|
|
value: '',
|
|
|
|
disabled: true,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
: [
|
|
|
|
{
|
|
|
|
label:
|
|
|
|
'Invalid provider, please check backend logs',
|
|
|
|
value: '',
|
|
|
|
disabled: true,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
})()}
|
|
|
|
/>
|
2024-04-23 11:22:41 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2024-04-23 11:36:44 +00:00
|
|
|
<div className="flex flex-col space-y-1">
|
2024-05-24 12:29:49 +00:00
|
|
|
<p className="text-black/70 dark:text-white/70 text-sm">
|
|
|
|
OpenAI API Key
|
|
|
|
</p>
|
2024-05-24 13:58:14 +00:00
|
|
|
<Input
|
2024-04-23 11:36:44 +00:00
|
|
|
type="text"
|
2024-04-24 04:36:56 +00:00
|
|
|
placeholder="OpenAI API Key"
|
2024-05-02 09:34:33 +00:00
|
|
|
defaultValue={config.openaiApiKey}
|
2024-04-23 11:36:44 +00:00
|
|
|
onChange={(e) =>
|
|
|
|
setConfig({
|
|
|
|
...config,
|
2024-05-02 09:34:33 +00:00
|
|
|
openaiApiKey: e.target.value,
|
2024-04-23 11:36:44 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-col space-y-1">
|
2024-05-24 12:29:49 +00:00
|
|
|
<p className="text-black/70 dark:text-white/70 text-sm">
|
|
|
|
Ollama API URL
|
|
|
|
</p>
|
2024-05-24 13:58:14 +00:00
|
|
|
<Input
|
2024-04-23 11:36:44 +00:00
|
|
|
type="text"
|
2024-04-24 04:36:56 +00:00
|
|
|
placeholder="Ollama API URL"
|
2024-04-23 11:36:44 +00:00
|
|
|
defaultValue={config.ollamaApiUrl}
|
|
|
|
onChange={(e) =>
|
|
|
|
setConfig({
|
|
|
|
...config,
|
|
|
|
ollamaApiUrl: e.target.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-05-01 14:13:06 +00:00
|
|
|
<div className="flex flex-col space-y-1">
|
2024-05-24 12:29:49 +00:00
|
|
|
<p className="text-black/70 dark:text-white/70 text-sm">
|
|
|
|
GROQ API Key
|
|
|
|
</p>
|
2024-05-24 13:58:14 +00:00
|
|
|
<Input
|
2024-05-01 14:13:06 +00:00
|
|
|
type="text"
|
|
|
|
placeholder="GROQ API Key"
|
|
|
|
defaultValue={config.groqApiKey}
|
|
|
|
onChange={(e) =>
|
|
|
|
setConfig({
|
|
|
|
...config,
|
|
|
|
groqApiKey: e.target.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-07-15 15:50:16 +00:00
|
|
|
<div className="flex flex-col space-y-1">
|
|
|
|
<p className="text-black/70 dark:text-white/70 text-sm">
|
|
|
|
Anthropic API Key
|
|
|
|
</p>
|
|
|
|
<Input
|
|
|
|
type="text"
|
|
|
|
placeholder="Anthropic API key"
|
|
|
|
defaultValue={config.anthropicApiKey}
|
|
|
|
onChange={(e) =>
|
|
|
|
setConfig({
|
|
|
|
...config,
|
|
|
|
anthropicApiKey: e.target.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-11-28 15:17:18 +00:00
|
|
|
<div className="flex flex-col space-y-1">
|
|
|
|
<p className="text-black/70 dark:text-white/70 text-sm">
|
|
|
|
Gemini API Key
|
|
|
|
</p>
|
|
|
|
<Input
|
|
|
|
type="text"
|
|
|
|
placeholder="Gemini API key"
|
|
|
|
defaultValue={config.geminiApiKey}
|
|
|
|
onChange={(e) =>
|
|
|
|
setConfig({
|
|
|
|
...config,
|
|
|
|
geminiApiKey: e.target.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-04-23 11:22:41 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{isLoading && (
|
2024-05-24 12:29:49 +00:00
|
|
|
<div className="w-full flex items-center justify-center mt-6 text-black/70 dark:text-white/70 py-6">
|
2024-04-23 11:22:41 +00:00
|
|
|
<RefreshCcw className="animate-spin" />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div className="w-full mt-6 space-y-2">
|
2024-05-24 12:29:49 +00:00
|
|
|
<p className="text-xs text-black/50 dark:text-white/50">
|
2024-04-23 11:22:41 +00:00
|
|
|
We'll refresh the page after updating the settings.
|
|
|
|
</p>
|
|
|
|
<button
|
|
|
|
onClick={handleSubmit}
|
|
|
|
className="bg-[#24A0ED] flex flex-row items-center space-x-2 text-white disabled:text-white/50 hover:bg-opacity-85 transition duration-100 disabled:bg-[#ececec21] rounded-full px-4 py-2"
|
|
|
|
disabled={isLoading || isUpdating}
|
|
|
|
>
|
|
|
|
{isUpdating ? (
|
2024-04-23 11:36:44 +00:00
|
|
|
<RefreshCw size={20} className="animate-spin" />
|
2024-04-23 11:22:41 +00:00
|
|
|
) : (
|
2024-04-23 11:36:44 +00:00
|
|
|
<CloudUpload size={20} />
|
2024-04-23 11:22:41 +00:00
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
</div>
|
2024-10-11 05:05:33 +00:00
|
|
|
</DialogPanel>
|
|
|
|
</TransitionChild>
|
2024-04-23 11:22:41 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Dialog>
|
|
|
|
</Transition>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SettingsDialog;
|