mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: remove openai setting section (#2084)
This commit is contained in:
@ -40,8 +40,6 @@ const (
|
|||||||
SystemSettingTelegramBotTokenName SystemSettingName = "telegram-bot-token"
|
SystemSettingTelegramBotTokenName SystemSettingName = "telegram-bot-token"
|
||||||
// SystemSettingMemoDisplayWithUpdatedTsName is the name of memo display with updated ts.
|
// SystemSettingMemoDisplayWithUpdatedTsName is the name of memo display with updated ts.
|
||||||
SystemSettingMemoDisplayWithUpdatedTsName SystemSettingName = "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 is the name of auto backup interval as seconds.
|
||||||
SystemSettingAutoBackupIntervalName SystemSettingName = "auto-backup-interval"
|
SystemSettingAutoBackupIntervalName SystemSettingName = "auto-backup-interval"
|
||||||
)
|
)
|
||||||
@ -73,11 +71,6 @@ type SystemSetting struct {
|
|||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OpenAIConfig struct {
|
|
||||||
Key string `json:"key"`
|
|
||||||
Host string `json:"host"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpsertSystemSettingRequest struct {
|
type UpsertSystemSettingRequest struct {
|
||||||
Name SystemSettingName `json:"name"`
|
Name SystemSettingName `json:"name"`
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
@ -144,11 +137,6 @@ func (upsert UpsertSystemSettingRequest) Validate() error {
|
|||||||
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
|
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
|
||||||
return fmt.Errorf(systemSettingUnmarshalError, settingName)
|
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:
|
case SystemSettingAutoBackupIntervalName:
|
||||||
var value int
|
var value int
|
||||||
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
|
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{
|
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",
|
ErrorMessage: "Request timeout",
|
||||||
Timeout: 30 * time.Second,
|
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}`);
|
return axios.delete(`/api/v1/memo/${memoId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkOpenAIEnabled() {
|
|
||||||
return axios.get<boolean>(`/api/openai/enabled`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getResourceList() {
|
export function getResourceList() {
|
||||||
return axios.get<Resource[]>("/api/v1/resource");
|
return axios.get<Resource[]>("/api/v1/resource");
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,15 @@ import Icon from "@/components/Icon";
|
|||||||
import MobileHeader from "@/components/MobileHeader";
|
import MobileHeader from "@/components/MobileHeader";
|
||||||
import MemberSection from "@/components/Settings/MemberSection";
|
import MemberSection from "@/components/Settings/MemberSection";
|
||||||
import MyAccountSection from "@/components/Settings/MyAccountSection";
|
import MyAccountSection from "@/components/Settings/MyAccountSection";
|
||||||
import OpenAISection from "@/components/Settings/OpenAISection";
|
|
||||||
import PreferencesSection from "@/components/Settings/PreferencesSection";
|
import PreferencesSection from "@/components/Settings/PreferencesSection";
|
||||||
import SSOSection from "@/components/Settings/SSOSection";
|
import SSOSection from "@/components/Settings/SSOSection";
|
||||||
import StorageSection from "@/components/Settings/StorageSection";
|
import StorageSection from "@/components/Settings/StorageSection";
|
||||||
import SystemSection from "@/components/Settings/SystemSection";
|
import SystemSection from "@/components/Settings/SystemSection";
|
||||||
import { useGlobalStore, useUserStore } from "@/store/module";
|
import { useUserStore } from "@/store/module";
|
||||||
import { useTranslate } from "@/utils/i18n";
|
import { useTranslate } from "@/utils/i18n";
|
||||||
import "@/less/setting.less";
|
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 {
|
interface State {
|
||||||
selectedSection: SettingSection;
|
selectedSection: SettingSection;
|
||||||
@ -22,7 +21,6 @@ interface State {
|
|||||||
|
|
||||||
const Setting = () => {
|
const Setting = () => {
|
||||||
const t = useTranslate();
|
const t = useTranslate();
|
||||||
const globalStore = useGlobalStore();
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const user = userStore.state.user;
|
const user = userStore.state.user;
|
||||||
const [state, setState] = useState<State>({
|
const [state, setState] = useState<State>({
|
||||||
@ -39,12 +37,8 @@ const Setting = () => {
|
|||||||
const getSettingSectionList = () => {
|
const getSettingSectionList = () => {
|
||||||
let settingList: SettingSection[] = ["my-account", "preference"];
|
let settingList: SettingSection[] = ["my-account", "preference"];
|
||||||
if (isHost) {
|
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;
|
return settingList;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -84,14 +78,6 @@ const Setting = () => {
|
|||||||
>
|
>
|
||||||
<Icon.Settings2 className="w-4 h-auto mr-2 opacity-80" /> {t("setting.system")}
|
<Icon.Settings2 className="w-4 h-auto mr-2 opacity-80" /> {t("setting.system")}
|
||||||
</span>
|
</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
|
<span
|
||||||
onClick={() => handleSectionSelectorItemClick("storage")}
|
onClick={() => handleSectionSelectorItemClick("storage")}
|
||||||
className={`section-item ${state.selectedSection === "storage" ? "selected" : ""}`}
|
className={`section-item ${state.selectedSection === "storage" ? "selected" : ""}`}
|
||||||
@ -128,8 +114,6 @@ const Setting = () => {
|
|||||||
<MemberSection />
|
<MemberSection />
|
||||||
) : state.selectedSection === "system" ? (
|
) : state.selectedSection === "system" ? (
|
||||||
<SystemSection />
|
<SystemSection />
|
||||||
) : state.selectedSection === "openai" ? (
|
|
||||||
<OpenAISection />
|
|
||||||
) : state.selectedSection === "storage" ? (
|
) : state.selectedSection === "storage" ? (
|
||||||
<StorageSection />
|
<StorageSection />
|
||||||
) : state.selectedSection === "sso" ? (
|
) : state.selectedSection === "sso" ? (
|
||||||
|
Reference in New Issue
Block a user