Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
218159bf
Unverified
Commit
218159bf
authored
Aug 05, 2023
by
boojack
Committed by
GitHub
Aug 05, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: remove openai setting section (#2084)
parent
238f8969
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
3 additions
and
142 deletions
+3
-142
system_setting.go
api/v1/system_setting.go
+0
-12
server.go
server/server.go
+0
-5
OpenAISection.tsx
web/src/components/Settings/OpenAISection.tsx
+0
-102
api.ts
web/src/helpers/api.ts
+0
-4
Setting.tsx
web/src/pages/Setting.tsx
+3
-19
No files found.
api/v1/system_setting.go
View file @
218159bf
...
@@ -40,8 +40,6 @@ const (
...
@@ -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 {
...
@@ -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 {
...
@@ -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
{
...
...
server/server.go
View file @
218159bf
...
@@ -73,11 +73,6 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
...
@@ -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
,
}))
}))
...
...
web/src/components/Settings/OpenAISection.tsx
deleted
100644 → 0
View file @
238f8969
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
;
web/src/helpers/api.ts
View file @
218159bf
...
@@ -138,10 +138,6 @@ export function deleteMemo(memoId: MemoId) {
...
@@ -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"
);
}
}
...
...
web/src/pages/Setting.tsx
View file @
218159bf
...
@@ -5,16 +5,15 @@ import Icon from "@/components/Icon";
...
@@ -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
{
use
GlobalStore
,
use
UserStore
}
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 {
...
@@ -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,11 +37,7 @@ const Setting = () => {
...
@@ -39,11 +37,7 @@ 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"
,
"storage"
,
"sso"
]);
settingList
=
settingList
.
concat
([
"member"
,
"system"
,
"openai"
,
"storage"
,
"sso"
]);
}
else
{
settingList
=
settingList
.
concat
([
"member"
,
"system"
,
"storage"
,
"sso"
]);
}
}
}
return
settingList
;
return
settingList
;
};
};
...
@@ -84,14 +78,6 @@ const Setting = () => {
...
@@ -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 = () => {
...
@@ -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"
?
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment