import { Button, Input } from "@mui/joy"; import { useEffect, useState } from "react"; import { toast } from "react-hot-toast"; import * as api from "@/helpers/api"; import { useGlobalStore } from "@/store/module"; import { useTranslate } from "@/utils/i18n"; import LearnMore from "../LearnMore"; import "@/less/settings/system-section.less"; interface OpenAIConfig { key: string; host: string; } const OpenAISection = () => { const t = useTranslate(); const globalStore = useGlobalStore(); const [openAIConfig, setOpenAIConfig] = useState({ key: "", host: "", }); useEffect(() => { globalStore.fetchSystemStatus(); }, []); useEffect(() => { api.getSystemSetting().then(({ data: systemSettings }) => { const openAIConfigSetting = systemSettings.find((setting) => setting.name === "openai-config"); if (openAIConfigSetting) { setOpenAIConfig(JSON.parse(openAIConfigSetting.value)); } }); }, []); const handleOpenAIConfigKeyChanged = (value: string) => { setOpenAIConfig({ ...openAIConfig, key: value, }); }; const handleOpenAIConfigHostChanged = (value: string) => { setOpenAIConfig({ ...openAIConfig, host: value, }); }; const handleSaveOpenAIConfig = async () => { try { await api.upsertSystemSetting({ name: "openai-config", value: JSON.stringify(openAIConfig), }); } catch (error) { console.error(error); return; } toast.success("OpenAI Config updated"); }; return (

{t("setting.openai")}

{t("setting.system-section.openai-api-key")}
handleOpenAIConfigKeyChanged(event.target.value)} />
{t("setting.system-section.openai-api-host")}
handleOpenAIConfigHostChanged(event.target.value)} />
); }; export default OpenAISection;