@@ -10,7 +10,7 @@ import { abortChatProcess, chatConfig, chatReplyProcess, containsSensitiveWords,
1010import { auth , getUserId } from './middleware/auth'
1111import { clearApiKeyCache , clearConfigCache , getApiKeys , getCacheApiKeys , getCacheConfig , getOriginConfig } from './storage/config'
1212import type { AuditConfig , ChatInfo , ChatOptions , Config , KeyConfig , MailConfig , SiteConfig , UserConfig , UserInfo } from './storage/model'
13- import { Status , UsageResponse , UserRole } from './storage/model'
13+ import { AdvancedConfig , Status , UsageResponse , UserRole } from './storage/model'
1414import {
1515 clearChat ,
1616 createChatRoom ,
@@ -39,6 +39,7 @@ import {
3939 updateRoomUsingContext ,
4040 updateUser ,
4141 updateUser2FA ,
42+ updateUserAdvancedConfig ,
4243 updateUserChatModel ,
4344 updateUserInfo ,
4445 updateUserPassword ,
@@ -589,7 +590,7 @@ router.post('/session', async (req, res) => {
589590 }
590591 } )
591592
592- let userInfo : { name : string ; description : string ; avatar : string ; userId : string ; root : boolean ; roles : UserRole [ ] ; config : UserConfig }
593+ let userInfo : { name : string ; description : string ; avatar : string ; userId : string ; root : boolean ; roles : UserRole [ ] ; config : UserConfig ; advanced : AdvancedConfig }
593594 if ( userId != null ) {
594595 const user = await getUserById ( userId )
595596 userInfo = {
@@ -600,6 +601,7 @@ router.post('/session', async (req, res) => {
600601 root : user . roles . includes ( UserRole . Admin ) ,
601602 roles : user . roles ,
602603 config : user . config ,
604+ advanced : user . advanced ,
603605 }
604606
605607 const keys = ( await getCacheApiKeys ( ) ) . filter ( d => hasAnyRole ( d . userRoles , user . roles ) )
@@ -1067,6 +1069,55 @@ router.post('/audit-test', rootAuth, async (req, res) => {
10671069 }
10681070} )
10691071
1072+ router . post ( '/setting-advanced' , auth , async ( req , res ) => {
1073+ try {
1074+ const config = req . body as {
1075+ systemMessage : string
1076+ temperature : number
1077+ top_p : number
1078+ maxContextCount : number
1079+ sync : boolean
1080+ }
1081+ if ( config . sync ) {
1082+ if ( ! isAdmin ( req . headers . userId as string ) ) {
1083+ res . send ( { status : 'Fail' , message : '无权限 | No permission' , data : null } )
1084+ return
1085+ }
1086+ const thisConfig = await getOriginConfig ( )
1087+ thisConfig . advancedConfig = new AdvancedConfig (
1088+ config . systemMessage ,
1089+ config . temperature ,
1090+ config . top_p ,
1091+ config . maxContextCount ,
1092+ )
1093+ await updateConfig ( thisConfig )
1094+ clearConfigCache ( )
1095+ }
1096+ const userId = req . headers . userId . toString ( )
1097+ await updateUserAdvancedConfig ( userId , new AdvancedConfig (
1098+ config . systemMessage ,
1099+ config . temperature ,
1100+ config . top_p ,
1101+ config . maxContextCount ,
1102+ ) )
1103+ res . send ( { status : 'Success' , message : '操作成功 | Successfully' } )
1104+ }
1105+ catch ( error ) {
1106+ res . send ( { status : 'Fail' , message : error . message , data : null } )
1107+ }
1108+ } )
1109+
1110+ router . post ( '/setting-reset-advanced' , auth , async ( req , res ) => {
1111+ try {
1112+ const userId = req . headers . userId . toString ( )
1113+ await updateUserAdvancedConfig ( userId , null )
1114+ res . send ( { status : 'Success' , message : '操作成功 | Successfully' } )
1115+ }
1116+ catch ( error ) {
1117+ res . send ( { status : 'Fail' , message : error . message , data : null } )
1118+ }
1119+ } )
1120+
10701121router . get ( '/setting-keys' , rootAuth , async ( req , res ) => {
10711122 try {
10721123 const result = await getApiKeys ( )
0 commit comments