From 4775d94aa728544e020c00698c71b97f2470132f Mon Sep 17 00:00:00 2001 From: Bob Du Date: Tue, 20 Jan 2026 19:05:30 +0800 Subject: [PATCH] feat: remove advanced system prompt Signed-off-by: Bob Du --- service/src/chatgpt/index.ts | 4 +- service/src/chatgpt/types.ts | 1 - service/src/index.ts | 46 +--------------------- service/src/routes/chat.ts | 5 +-- service/src/storage/config.ts | 8 +--- service/src/storage/model.ts | 8 ---- service/src/storage/mongo.ts | 7 ---- service/src/types.ts | 1 - src/api/index.ts | 18 --------- src/components/common/Setting/Advanced.vue | 45 --------------------- src/components/common/Setting/index.vue | 10 ----- src/locales/en-US.json | 3 -- src/locales/ja-JP.json | 3 -- src/locales/ko-KR.json | 3 -- src/locales/zh-CN.json | 3 -- src/locales/zh-TW.json | 3 -- src/store/modules/settings/helper.ts | 26 ------------ src/store/modules/user/helper.ts | 13 ------ src/store/modules/user/index.ts | 11 +----- 19 files changed, 8 insertions(+), 210 deletions(-) delete mode 100644 src/components/common/Setting/Advanced.vue delete mode 100644 src/store/modules/settings/helper.ts diff --git a/service/src/chatgpt/index.ts b/service/src/chatgpt/index.ts index c85425a9..651bad77 100644 --- a/service/src/chatgpt/index.ts +++ b/service/src/chatgpt/index.ts @@ -108,6 +108,7 @@ export async function initApi(key: KeyConfig) { } const processThreads: { userId: string, chatUuid: number, abort: AbortController }[] = [] +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 $...$).' async function chatReplyProcess(options: RequestOptions) { const globalConfig = await getCacheConfig() @@ -122,7 +123,8 @@ async function chatReplyProcess(options: RequestOptions) { if (key == null || key === undefined) throw new Error('没有对应的apikeys配置。请再试一次 | No available apikeys configuration. Please try again.') - const { message, uploadFileKeys, parentMessageId, previousResponseId, tools, process, systemMessage, chatUuid } = options + const { message, uploadFileKeys, parentMessageId, previousResponseId, tools, process, chatUuid } = options + const systemMessage = isNotEmptyString(options.room.prompt) ? options.room.prompt : DEFAULT_SYSTEM_MESSAGE let instructions = systemMessage try { diff --git a/service/src/chatgpt/types.ts b/service/src/chatgpt/types.ts index bc78eef2..da64f286 100644 --- a/service/src/chatgpt/types.ts +++ b/service/src/chatgpt/types.ts @@ -46,7 +46,6 @@ export interface RequestOptions { previousResponseId?: string tools?: Array process?: (chunk: ResponseChunk) => void - systemMessage?: string user: UserInfo messageId: string room: ChatRoom diff --git a/service/src/index.ts b/service/src/index.ts index be8731b7..c5ccde99 100644 --- a/service/src/index.ts +++ b/service/src/index.ts @@ -16,7 +16,7 @@ import { router as promptRouter } from './routes/prompt' import { router as roomRouter } from './routes/room' import { router as uploadRouter } from './routes/upload' import { clearApiKeyCache, clearConfigCache, getApiKeys, getCacheApiKeys, getCacheConfig, getOriginConfig } from './storage/config' -import { AdvancedConfig, Status, UserConfig, UserRole } from './storage/model' +import { Status, UserConfig, UserRole } from './storage/model' import { createUser, disableUser2FA, @@ -33,7 +33,6 @@ import { updateGiftCards, updateUser, updateUser2FA, - updateUserAdvancedConfig, updateUserAmount, updateUserChatModel, updateUserInfo, @@ -169,7 +168,7 @@ router.post('/session', async (req, res) => { // Parse external chat sites list const externalChatSites: Array<{ name: string, url: string }> = config.siteConfig.externalChatSites || [] - let userInfo: { name: string, description: string, avatar: string, userId: string, root: boolean, roles: UserRole[], config: UserConfig, advanced: AdvancedConfig } + let userInfo: { name: string, description: string, avatar: string, userId: string, root: boolean, roles: UserRole[], config: UserConfig } if (userId != null) { const user = await getUserById(userId) if (user === null) { @@ -254,7 +253,6 @@ router.post('/session', async (req, res) => { root: user.roles.includes(UserRole.Admin), roles: user.roles, config: user.config, - advanced: user.advanced, } const keys = (await getCacheApiKeys()).filter(d => hasAnyRole(d.userRoles, user.roles)) @@ -987,46 +985,6 @@ router.post('/search-test', rootAuth, async (req, res) => { } }) -router.post('/setting-advanced', auth, async (req, res) => { - try { - const config = req.body as { - systemMessage: string - sync: boolean - } - if (config.sync) { - if (!isAdmin(req.headers.userId as string)) { - res.send({ status: 'Fail', message: '无权限 | No permission', data: null }) - return - } - const thisConfig = await getOriginConfig() - thisConfig.advancedConfig = new AdvancedConfig( - config.systemMessage, - ) - await updateConfig(thisConfig) - clearConfigCache() - } - const userId = req.headers.userId.toString() - await updateUserAdvancedConfig(userId, new AdvancedConfig( - config.systemMessage, - )) - res.send({ status: 'Success', message: '操作成功 | Successfully' }) - } - catch (error) { - res.send({ status: 'Fail', message: error.message, data: null }) - } -}) - -router.post('/setting-reset-advanced', auth, async (req, res) => { - try { - const userId = req.headers.userId.toString() - await updateUserAdvancedConfig(userId, null) - res.send({ status: 'Success', message: '操作成功 | Successfully' }) - } - catch (error) { - res.send({ status: 'Fail', message: error.message, data: null }) - } -}) - router.get('/setting-keys', rootAuth, async (req, res) => { try { const result = await getApiKeys() diff --git a/service/src/routes/chat.ts b/service/src/routes/chat.ts index 8baf0651..4dc1ad37 100644 --- a/service/src/routes/chat.ts +++ b/service/src/routes/chat.ts @@ -249,14 +249,12 @@ router.post('/chat-process', [auth, limiter], async (req, res) => { res.setHeader('Access-Control-Allow-Origin', '*') res.setHeader('Access-Control-Allow-Headers', 'Cache-Control') - let { roomId, uuid, regenerate, prompt, uploadFileKeys = [], options = {}, systemMessage, tools, previousResponseId } = req.body as RequestProps + const { roomId, uuid, regenerate, prompt, uploadFileKeys = [], options = {}, tools, previousResponseId } = req.body as RequestProps const userId = req.headers.userId.toString() const config = await getCacheConfig() const room = await getChatRoom(userId, roomId) if (room == null) globalThis.console.error(`Unable to get chat room \t ${userId}\t ${roomId}`) - if (room != null && isNotEmptyString(room.prompt)) - systemMessage = room.prompt const model = room.chatModel let lastResponse @@ -352,7 +350,6 @@ router.post('/chat-process', [auth, limiter], async (req, res) => { }) } }, - systemMessage, user, messageId: message._id.toString(), room, diff --git a/service/src/storage/config.ts b/service/src/storage/config.ts index ce1961b3..27c4fd4d 100644 --- a/service/src/storage/config.ts +++ b/service/src/storage/config.ts @@ -2,7 +2,7 @@ import type { TextAuditServiceProvider } from 'src/utils/textAudit' import * as process from 'node:process' import { ObjectId } from 'mongodb' import { isNotEmptyString, isTextAuditServiceProvider } from '../utils/is' -import { AdvancedConfig, AnnounceConfig, AuditConfig, Config, KeyConfig, MailConfig, SearchConfig, SiteConfig, TextAudioType, UserRole } from './model' +import { AnnounceConfig, AuditConfig, Config, KeyConfig, MailConfig, SearchConfig, SiteConfig, TextAudioType, UserRole } from './model' import { getConfig, getKeys, upsertKey } from './mongo' let cachedConfig: Config | undefined @@ -74,12 +74,6 @@ export async function getOriginConfig() { ) } - if (!config.advancedConfig) { - config.advancedConfig = new AdvancedConfig( - 'You are a large language model. Follow the user\'s instructions carefully. Respond using markdown (latex start with $).', - ) - } - if (!config.announceConfig) { config.announceConfig = new AnnounceConfig( false, diff --git a/service/src/storage/model.ts b/service/src/storage/model.ts index 0add1438..de8d2bc9 100644 --- a/service/src/storage/model.ts +++ b/service/src/storage/model.ts @@ -51,7 +51,6 @@ export class UserInfo { roles?: UserRole[] remark?: string secretKey?: string // 2fa - advanced?: AdvancedConfig useAmount?: number // chat usage amount limit_switch?: boolean // chat amount limit switch constructor(email: string, password: string) { @@ -242,7 +241,6 @@ export class Config { public mailConfig?: MailConfig, public auditConfig?: AuditConfig, public searchConfig?: SearchConfig, - public advancedConfig?: AdvancedConfig, public announceConfig?: AnnounceConfig, ) { } } @@ -302,12 +300,6 @@ export class AuditConfig { ) { } } -export class AdvancedConfig { - constructor( - public systemMessage: string, - ) { } -} - export enum TextAudioType { None = 0, Request = 1, // 二进制 01 diff --git a/service/src/storage/mongo.ts b/service/src/storage/mongo.ts index bdce61f0..c5430519 100644 --- a/service/src/storage/mongo.ts +++ b/service/src/storage/mongo.ts @@ -1,6 +1,5 @@ import type { Collection, Filter, WithId } from 'mongodb' import type { - AdvancedConfig, BuiltInPrompt, ChatOptions, Config, @@ -744,10 +743,6 @@ export async function updateUserMaxContextCount(userId: string, maxContextCount: await userCol.updateOne({ _id: new ObjectId(userId) }, { $set: { 'config.maxContextCount': maxContextCount } }) } -export async function updateUserAdvancedConfig(userId: string, config: AdvancedConfig) { - await userCol.updateOne({ _id: new ObjectId(userId) }, { $set: { advanced: config } }) -} - export async function updateUser2FA(userId: string, secretKey: string) { await userCol.updateOne({ _id: new ObjectId(userId) }, { $set: { secretKey, updateTime: new Date().toLocaleString() } }) } @@ -809,8 +804,6 @@ async function initUserInfo(userInfo: WithId) { userInfo.roles.push(UserRole.Admin) userInfo.roles.push(UserRole.User) } - if (!userInfo.advanced) - userInfo.advanced = (await getCacheConfig()).advancedConfig } export async function verifyUser(email: string, status: Status) { diff --git a/service/src/types.ts b/service/src/types.ts index d0446b07..bc05188e 100644 --- a/service/src/types.ts +++ b/service/src/types.ts @@ -14,7 +14,6 @@ export interface RequestProps { prompt: string uploadFileKeys?: string[] options?: ChatContext - systemMessage: string tools?: ImageGenerationTool[] previousResponseId?: string } diff --git a/src/api/index.ts b/src/api/index.ts index 2756a307..24bcfd3c 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,6 +1,4 @@ import type { AnnounceConfig, AuditConfig, BuiltInPrompt, ConfigState, GiftCard, KeyConfig, MailConfig, SearchConfig, SiteConfig, Status, UserInfo, UserPassword, UserPrompt } from '@/components/common/Setting/model' -import type { SettingsState } from '@/store/modules/user/helper' -import { useUserStore } from '@/store' import { get, post } from '@/utils/request' import fetchService from '@/utils/request/fetchService' @@ -45,8 +43,6 @@ export function fetchChatAPIProcessSSE( }, handlers: SSEEventHandlers, ): Promise { - const userStore = useUserStore() - const data: Record = { roomId: params.roomId, uuid: params.uuid, @@ -54,7 +50,6 @@ export function fetchChatAPIProcessSSE( prompt: params.prompt, uploadFileKeys: params.uploadFileKeys, options: params.options, - systemMessage: userStore.userInfo.advanced.systemMessage, } if (params.tools && params.tools.length > 0) { @@ -493,19 +488,6 @@ export function fetchUpdateAnnounce(announce: AnnounceConfig) { }) } -export function fetchUpdateAdvanced(sync: boolean, advanced: SettingsState) { - const data = { sync, ...advanced } - return post({ - url: '/setting-advanced', - data, - }) -} - -export function fetchResetAdvanced() { - return post({ - url: '/setting-reset-advanced', - }) -} export function fetchUpdateSite(config: SiteConfig) { return post({ url: '/setting-site', diff --git a/src/components/common/Setting/Advanced.vue b/src/components/common/Setting/Advanced.vue deleted file mode 100644 index f43d6bb9..00000000 --- a/src/components/common/Setting/Advanced.vue +++ /dev/null @@ -1,45 +0,0 @@ - - - diff --git a/src/components/common/Setting/index.vue b/src/components/common/Setting/index.vue index a3b8417e..415085c5 100644 --- a/src/components/common/Setting/index.vue +++ b/src/components/common/Setting/index.vue @@ -3,7 +3,6 @@ import ChatRecord from '@/components/common/Setting/ChatRecord.vue' import { useBasicLayout } from '@/hooks/useBasicLayout' import { useAuthStore, useUserStore } from '@/store' import About from './About.vue' -import Advanced from './Advanced.vue' import Announcement from './Anonuncement.vue' import Audit from './Audit.vue' import BuiltInPrompt from './BuiltInPrompt.vue' @@ -104,15 +103,6 @@ const show = computed({ - - -
- -
-