Skip to content

Commit bb08436

Browse files
authored
feat: remove advanced system prompt (#688)
Signed-off-by: Bob Du <i@bobdu.cc>
1 parent d490f64 commit bb08436

File tree

19 files changed

+8
-210
lines changed

19 files changed

+8
-210
lines changed

service/src/chatgpt/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export async function initApi(key: KeyConfig) {
108108
}
109109

110110
const processThreads: { userId: string, chatUuid: number, abort: AbortController }[] = []
111+
const DEFAULT_SYSTEM_MESSAGE = 'You are a helpful assistant. Follow the user\'s instructions carefully. Be concise, accurate, and transparent. Respond in the same language as the user\'s request. Never fabricate facts, sources, or results. If you must make assumptions, state them explicitly. If you are unsure or need more context, say so and ask a clarifying question. Respond in Markdown (LaTeX with $...$).'
111112

112113
async function chatReplyProcess(options: RequestOptions) {
113114
const globalConfig = await getCacheConfig()
@@ -122,7 +123,8 @@ async function chatReplyProcess(options: RequestOptions) {
122123
if (key == null || key === undefined)
123124
throw new Error('没有对应的apikeys配置。请再试一次 | No available apikeys configuration. Please try again.')
124125

125-
const { message, uploadFileKeys, parentMessageId, previousResponseId, tools, process, systemMessage, chatUuid } = options
126+
const { message, uploadFileKeys, parentMessageId, previousResponseId, tools, process, chatUuid } = options
127+
const systemMessage = isNotEmptyString(options.room.prompt) ? options.room.prompt : DEFAULT_SYSTEM_MESSAGE
126128
let instructions = systemMessage
127129

128130
try {

service/src/chatgpt/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export interface RequestOptions {
4646
previousResponseId?: string
4747
tools?: Array<ImageGenerationTool>
4848
process?: (chunk: ResponseChunk) => void
49-
systemMessage?: string
5049
user: UserInfo
5150
messageId: string
5251
room: ChatRoom

service/src/index.ts

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { router as promptRouter } from './routes/prompt'
1616
import { router as roomRouter } from './routes/room'
1717
import { router as uploadRouter } from './routes/upload'
1818
import { clearApiKeyCache, clearConfigCache, getApiKeys, getCacheApiKeys, getCacheConfig, getOriginConfig } from './storage/config'
19-
import { AdvancedConfig, Status, UserConfig, UserRole } from './storage/model'
19+
import { Status, UserConfig, UserRole } from './storage/model'
2020
import {
2121
createUser,
2222
disableUser2FA,
@@ -33,7 +33,6 @@ import {
3333
updateGiftCards,
3434
updateUser,
3535
updateUser2FA,
36-
updateUserAdvancedConfig,
3736
updateUserAmount,
3837
updateUserChatModel,
3938
updateUserInfo,
@@ -169,7 +168,7 @@ router.post('/session', async (req, res) => {
169168
// Parse external chat sites list
170169
const externalChatSites: Array<{ name: string, url: string }> = config.siteConfig.externalChatSites || []
171170

172-
let userInfo: { name: string, description: string, avatar: string, userId: string, root: boolean, roles: UserRole[], config: UserConfig, advanced: AdvancedConfig }
171+
let userInfo: { name: string, description: string, avatar: string, userId: string, root: boolean, roles: UserRole[], config: UserConfig }
173172
if (userId != null) {
174173
const user = await getUserById(userId)
175174
if (user === null) {
@@ -254,7 +253,6 @@ router.post('/session', async (req, res) => {
254253
root: user.roles.includes(UserRole.Admin),
255254
roles: user.roles,
256255
config: user.config,
257-
advanced: user.advanced,
258256
}
259257

260258
const keys = (await getCacheApiKeys()).filter(d => hasAnyRole(d.userRoles, user.roles))
@@ -987,46 +985,6 @@ router.post('/search-test', rootAuth, async (req, res) => {
987985
}
988986
})
989987

990-
router.post('/setting-advanced', auth, async (req, res) => {
991-
try {
992-
const config = req.body as {
993-
systemMessage: string
994-
sync: boolean
995-
}
996-
if (config.sync) {
997-
if (!isAdmin(req.headers.userId as string)) {
998-
res.send({ status: 'Fail', message: '无权限 | No permission', data: null })
999-
return
1000-
}
1001-
const thisConfig = await getOriginConfig()
1002-
thisConfig.advancedConfig = new AdvancedConfig(
1003-
config.systemMessage,
1004-
)
1005-
await updateConfig(thisConfig)
1006-
clearConfigCache()
1007-
}
1008-
const userId = req.headers.userId.toString()
1009-
await updateUserAdvancedConfig(userId, new AdvancedConfig(
1010-
config.systemMessage,
1011-
))
1012-
res.send({ status: 'Success', message: '操作成功 | Successfully' })
1013-
}
1014-
catch (error) {
1015-
res.send({ status: 'Fail', message: error.message, data: null })
1016-
}
1017-
})
1018-
1019-
router.post('/setting-reset-advanced', auth, async (req, res) => {
1020-
try {
1021-
const userId = req.headers.userId.toString()
1022-
await updateUserAdvancedConfig(userId, null)
1023-
res.send({ status: 'Success', message: '操作成功 | Successfully' })
1024-
}
1025-
catch (error) {
1026-
res.send({ status: 'Fail', message: error.message, data: null })
1027-
}
1028-
})
1029-
1030988
router.get('/setting-keys', rootAuth, async (req, res) => {
1031989
try {
1032990
const result = await getApiKeys()

service/src/routes/chat.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,12 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
249249
res.setHeader('Access-Control-Allow-Origin', '*')
250250
res.setHeader('Access-Control-Allow-Headers', 'Cache-Control')
251251

252-
let { roomId, uuid, regenerate, prompt, uploadFileKeys = [], options = {}, systemMessage, tools, previousResponseId } = req.body as RequestProps
252+
const { roomId, uuid, regenerate, prompt, uploadFileKeys = [], options = {}, tools, previousResponseId } = req.body as RequestProps
253253
const userId = req.headers.userId.toString()
254254
const config = await getCacheConfig()
255255
const room = await getChatRoom(userId, roomId)
256256
if (room == null)
257257
globalThis.console.error(`Unable to get chat room \t ${userId}\t ${roomId}`)
258-
if (room != null && isNotEmptyString(room.prompt))
259-
systemMessage = room.prompt
260258
const model = room.chatModel
261259

262260
let lastResponse
@@ -352,7 +350,6 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
352350
})
353351
}
354352
},
355-
systemMessage,
356353
user,
357354
messageId: message._id.toString(),
358355
room,

service/src/storage/config.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { TextAuditServiceProvider } from 'src/utils/textAudit'
22
import * as process from 'node:process'
33
import { ObjectId } from 'mongodb'
44
import { isNotEmptyString, isTextAuditServiceProvider } from '../utils/is'
5-
import { AdvancedConfig, AnnounceConfig, AuditConfig, Config, KeyConfig, MailConfig, SearchConfig, SiteConfig, TextAudioType, UserRole } from './model'
5+
import { AnnounceConfig, AuditConfig, Config, KeyConfig, MailConfig, SearchConfig, SiteConfig, TextAudioType, UserRole } from './model'
66
import { getConfig, getKeys, upsertKey } from './mongo'
77

88
let cachedConfig: Config | undefined
@@ -74,12 +74,6 @@ export async function getOriginConfig() {
7474
)
7575
}
7676

77-
if (!config.advancedConfig) {
78-
config.advancedConfig = new AdvancedConfig(
79-
'You are a large language model. Follow the user\'s instructions carefully. Respond using markdown (latex start with $).',
80-
)
81-
}
82-
8377
if (!config.announceConfig) {
8478
config.announceConfig = new AnnounceConfig(
8579
false,

service/src/storage/model.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export class UserInfo {
5151
roles?: UserRole[]
5252
remark?: string
5353
secretKey?: string // 2fa
54-
advanced?: AdvancedConfig
5554
useAmount?: number // chat usage amount
5655
limit_switch?: boolean // chat amount limit switch
5756
constructor(email: string, password: string) {
@@ -242,7 +241,6 @@ export class Config {
242241
public mailConfig?: MailConfig,
243242
public auditConfig?: AuditConfig,
244243
public searchConfig?: SearchConfig,
245-
public advancedConfig?: AdvancedConfig,
246244
public announceConfig?: AnnounceConfig,
247245
) { }
248246
}
@@ -302,12 +300,6 @@ export class AuditConfig {
302300
) { }
303301
}
304302

305-
export class AdvancedConfig {
306-
constructor(
307-
public systemMessage: string,
308-
) { }
309-
}
310-
311303
export enum TextAudioType {
312304
None = 0,
313305
Request = 1, // 二进制 01

service/src/storage/mongo.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Collection, Filter, WithId } from 'mongodb'
22
import type {
3-
AdvancedConfig,
43
BuiltInPrompt,
54
ChatOptions,
65
Config,
@@ -744,10 +743,6 @@ export async function updateUserMaxContextCount(userId: string, maxContextCount:
744743
await userCol.updateOne({ _id: new ObjectId(userId) }, { $set: { 'config.maxContextCount': maxContextCount } })
745744
}
746745

747-
export async function updateUserAdvancedConfig(userId: string, config: AdvancedConfig) {
748-
await userCol.updateOne({ _id: new ObjectId(userId) }, { $set: { advanced: config } })
749-
}
750-
751746
export async function updateUser2FA(userId: string, secretKey: string) {
752747
await userCol.updateOne({ _id: new ObjectId(userId) }, { $set: { secretKey, updateTime: new Date().toLocaleString() } })
753748
}
@@ -809,8 +804,6 @@ async function initUserInfo(userInfo: WithId<UserInfo>) {
809804
userInfo.roles.push(UserRole.Admin)
810805
userInfo.roles.push(UserRole.User)
811806
}
812-
if (!userInfo.advanced)
813-
userInfo.advanced = (await getCacheConfig()).advancedConfig
814807
}
815808

816809
export async function verifyUser(email: string, status: Status) {

service/src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export interface RequestProps {
1414
prompt: string
1515
uploadFileKeys?: string[]
1616
options?: ChatContext
17-
systemMessage: string
1817
tools?: ImageGenerationTool[]
1918
previousResponseId?: string
2019
}

src/api/index.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import type { AnnounceConfig, AuditConfig, BuiltInPrompt, ConfigState, GiftCard, KeyConfig, MailConfig, SearchConfig, SiteConfig, Status, UserInfo, UserPassword, UserPrompt } from '@/components/common/Setting/model'
2-
import type { SettingsState } from '@/store/modules/user/helper'
3-
import { useUserStore } from '@/store'
42
import { get, post } from '@/utils/request'
53
import fetchService from '@/utils/request/fetchService'
64

@@ -45,16 +43,13 @@ export function fetchChatAPIProcessSSE(
4543
},
4644
handlers: SSEEventHandlers,
4745
): Promise<void> {
48-
const userStore = useUserStore()
49-
5046
const data: Record<string, any> = {
5147
roomId: params.roomId,
5248
uuid: params.uuid,
5349
regenerate: params.regenerate || false,
5450
prompt: params.prompt,
5551
uploadFileKeys: params.uploadFileKeys,
5652
options: params.options,
57-
systemMessage: userStore.userInfo.advanced.systemMessage,
5853
}
5954

6055
if (params.tools && params.tools.length > 0) {
@@ -493,19 +488,6 @@ export function fetchUpdateAnnounce<T = any>(announce: AnnounceConfig) {
493488
})
494489
}
495490

496-
export function fetchUpdateAdvanced<T = any>(sync: boolean, advanced: SettingsState) {
497-
const data = { sync, ...advanced }
498-
return post<T>({
499-
url: '/setting-advanced',
500-
data,
501-
})
502-
}
503-
504-
export function fetchResetAdvanced<T = any>() {
505-
return post<T>({
506-
url: '/setting-reset-advanced',
507-
})
508-
}
509491
export function fetchUpdateSite<T = any>(config: SiteConfig) {
510492
return post<T>({
511493
url: '/setting-site',

src/components/common/Setting/Advanced.vue

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)