chore: remove openai setting section (#2084)

pull/2085/head
boojack 2 years ago committed by GitHub
parent 238f896907
commit 218159bf83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -40,8 +40,6 @@ const (
SystemSettingTelegramBotTokenName SystemSettingName = "telegram-bot-token"
// SystemSettingMemoDisplayWithUpdatedTsName is the name of memo display with updated ts.
SystemSettingMemoDisplayWithUpdatedTsName SystemSettingName = "memo-display-with-updated-ts"
// SystemSettingOpenAIConfigName is the name of OpenAI config.
SystemSettingOpenAIConfigName SystemSettingName = "openai-config"
// SystemSettingAutoBackupIntervalName is the name of auto backup interval as seconds.
SystemSettingAutoBackupIntervalName SystemSettingName = "auto-backup-interval"
)
@ -73,11 +71,6 @@ type SystemSetting struct {
Description string `json:"description"`
}
type OpenAIConfig struct {
Key string `json:"key"`
Host string `json:"host"`
}
type UpsertSystemSettingRequest struct {
Name SystemSettingName `json:"name"`
Value string `json:"value"`
@ -144,11 +137,6 @@ func (upsert UpsertSystemSettingRequest) Validate() error {
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
return fmt.Errorf(systemSettingUnmarshalError, settingName)
}
case SystemSettingOpenAIConfigName:
value := OpenAIConfig{}
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
return fmt.Errorf(systemSettingUnmarshalError, settingName)
}
case SystemSettingAutoBackupIntervalName:
var value int
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {

@ -73,11 +73,6 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
}))
e.Use(middleware.TimeoutWithConfig(middleware.TimeoutConfig{
Skipper: func(c echo.Context) bool {
// this is a hack to skip timeout for openai chat streaming
// because streaming require to flush response. But the timeout middleware will break it.
return c.Request().URL.Path == "/api/v1/openai/chat-streaming"
},
ErrorMessage: "Request timeout",
Timeout: 30 * time.Second,
}))

@ -1,102 +0,0 @@
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<OpenAIConfig>({
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 (
<div className="section-container system-section-container">
<p className="title-text">{t("setting.openai")}</p>
<div className="form-label">
<div className="flex flex-row items-center">
<span className="text-sm mr-1">{t("setting.system-section.openai-api-key")}</span>
<LearnMore title={t("setting.system-section.openai-api-key-description")} url="https://platform.openai.com/account/api-keys" />
</div>
</div>
<Input
className="w-full"
sx={{
fontFamily: "monospace",
fontSize: "14px",
}}
placeholder={t("setting.system-section.openai-api-key-placeholder")}
value={openAIConfig.key}
onChange={(event) => handleOpenAIConfigKeyChanged(event.target.value)}
/>
<div className="form-label mt-2">
<span className="normal-text">{t("setting.system-section.openai-api-host")}</span>
</div>
<Input
className="w-full"
sx={{
fontFamily: "monospace",
fontSize: "14px",
}}
placeholder={t("setting.system-section.openai-api-host-placeholder")}
value={openAIConfig.host}
onChange={(event) => handleOpenAIConfigHostChanged(event.target.value)}
/>
<div className="mt-4">
<Button onClick={handleSaveOpenAIConfig}>{t("common.save")}</Button>
</div>
</div>
);
};
export default OpenAISection;

@ -138,10 +138,6 @@ export function deleteMemo(memoId: MemoId) {
return axios.delete(`/api/v1/memo/${memoId}`);
}
export function checkOpenAIEnabled() {
return axios.get<boolean>(`/api/openai/enabled`);
}
export function getResourceList() {
return axios.get<Resource[]>("/api/v1/resource");
}

@ -5,16 +5,15 @@ import Icon from "@/components/Icon";
import MobileHeader from "@/components/MobileHeader";
import MemberSection from "@/components/Settings/MemberSection";
import MyAccountSection from "@/components/Settings/MyAccountSection";
import OpenAISection from "@/components/Settings/OpenAISection";
import PreferencesSection from "@/components/Settings/PreferencesSection";
import SSOSection from "@/components/Settings/SSOSection";
import StorageSection from "@/components/Settings/StorageSection";
import SystemSection from "@/components/Settings/SystemSection";
import { useGlobalStore, useUserStore } from "@/store/module";
import { useUserStore } from "@/store/module";
import { useTranslate } from "@/utils/i18n";
import "@/less/setting.less";
type SettingSection = "my-account" | "preference" | "member" | "system" | "openai" | "storage" | "sso";
type SettingSection = "my-account" | "preference" | "member" | "system" | "storage" | "sso";
interface State {
selectedSection: SettingSection;
@ -22,7 +21,6 @@ interface State {
const Setting = () => {
const t = useTranslate();
const globalStore = useGlobalStore();
const userStore = useUserStore();
const user = userStore.state.user;
const [state, setState] = useState<State>({
@ -39,11 +37,7 @@ const Setting = () => {
const getSettingSectionList = () => {
let settingList: SettingSection[] = ["my-account", "preference"];
if (isHost) {
if (globalStore.isDev()) {
settingList = settingList.concat(["member", "system", "openai", "storage", "sso"]);
} else {
settingList = settingList.concat(["member", "system", "storage", "sso"]);
}
settingList = settingList.concat(["member", "system", "storage", "sso"]);
}
return settingList;
};
@ -84,14 +78,6 @@ const Setting = () => {
>
<Icon.Settings2 className="w-4 h-auto mr-2 opacity-80" /> {t("setting.system")}
</span>
{globalStore.isDev() && (
<span
onClick={() => handleSectionSelectorItemClick("openai")}
className={`section-item ${state.selectedSection === "openai" ? "selected" : ""}`}
>
<Icon.Bot className="w-4 h-auto mr-2 opacity-80" /> {t("setting.openai")} <BetaBadge />
</span>
)}
<span
onClick={() => handleSectionSelectorItemClick("storage")}
className={`section-item ${state.selectedSection === "storage" ? "selected" : ""}`}
@ -128,8 +114,6 @@ const Setting = () => {
<MemberSection />
) : state.selectedSection === "system" ? (
<SystemSection />
) : state.selectedSection === "openai" ? (
<OpenAISection />
) : state.selectedSection === "storage" ? (
<StorageSection />
) : state.selectedSection === "sso" ? (

Loading…
Cancel
Save