Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion service/src/chatgpt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion service/src/chatgpt/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export interface RequestOptions {
previousResponseId?: string
tools?: Array<ImageGenerationTool>
process?: (chunk: ResponseChunk) => void
systemMessage?: string
user: UserInfo
messageId: string
room: ChatRoom
Expand Down
46 changes: 2 additions & 44 deletions service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,7 +33,6 @@ import {
updateGiftCards,
updateUser,
updateUser2FA,
updateUserAdvancedConfig,
updateUserAmount,
updateUserChatModel,
updateUserInfo,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 1 addition & 4 deletions service/src/routes/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -352,7 +350,6 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
})
}
},
systemMessage,
user,
messageId: message._id.toString(),
room,
Expand Down
8 changes: 1 addition & 7 deletions service/src/storage/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions service/src/storage/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -242,7 +241,6 @@ export class Config {
public mailConfig?: MailConfig,
public auditConfig?: AuditConfig,
public searchConfig?: SearchConfig,
public advancedConfig?: AdvancedConfig,
public announceConfig?: AnnounceConfig,
) { }
}
Expand Down Expand Up @@ -302,12 +300,6 @@ export class AuditConfig {
) { }
}

export class AdvancedConfig {
constructor(
public systemMessage: string,
) { }
}

export enum TextAudioType {
None = 0,
Request = 1, // 二进制 01
Expand Down
7 changes: 0 additions & 7 deletions service/src/storage/mongo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Collection, Filter, WithId } from 'mongodb'
import type {
AdvancedConfig,
BuiltInPrompt,
ChatOptions,
Config,
Expand Down Expand Up @@ -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() } })
}
Expand Down Expand Up @@ -809,8 +804,6 @@ async function initUserInfo(userInfo: WithId<UserInfo>) {
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) {
Expand Down
1 change: 0 additions & 1 deletion service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export interface RequestProps {
prompt: string
uploadFileKeys?: string[]
options?: ChatContext
systemMessage: string
tools?: ImageGenerationTool[]
previousResponseId?: string
}
Expand Down
18 changes: 0 additions & 18 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -45,16 +43,13 @@ export function fetchChatAPIProcessSSE(
},
handlers: SSEEventHandlers,
): Promise<void> {
const userStore = useUserStore()

const data: Record<string, any> = {
roomId: params.roomId,
uuid: params.uuid,
regenerate: params.regenerate || false,
prompt: params.prompt,
uploadFileKeys: params.uploadFileKeys,
options: params.options,
systemMessage: userStore.userInfo.advanced.systemMessage,
}

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

export function fetchUpdateAdvanced<T = any>(sync: boolean, advanced: SettingsState) {
const data = { sync, ...advanced }
return post<T>({
url: '/setting-advanced',
data,
})
}

export function fetchResetAdvanced<T = any>() {
return post<T>({
url: '/setting-reset-advanced',
})
}
export function fetchUpdateSite<T = any>(config: SiteConfig) {
return post<T>({
url: '/setting-site',
Expand Down
45 changes: 0 additions & 45 deletions src/components/common/Setting/Advanced.vue

This file was deleted.

10 changes: 0 additions & 10 deletions src/components/common/Setting/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -104,15 +103,6 @@ const show = computed({
</template>
<TwoFA />
</NTabPane>
<NTabPane name="Advanced" tab="Advanced">
<template #tab>
<IconRiEqualizerLine class="text-lg" />
<span class="ml-2">{{ t('setting.advanced') }}</span>
</template>
<div class="min-h-[100px]">
<Advanced />
</div>
</NTabPane>
<NTabPane name="Statistics" tab="Statistics">
<template #tab>
<IconRiBarChartBoxLine class="text-lg" />
Expand Down
3 changes: 0 additions & 3 deletions src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"delete": "Delete",
"deleteSuccess": "Delete Success",
"save": "Save",
"sync": "Save and sync everyone",
"test": "Test",
"saveSuccess": "Save Success",
"reset": "Reset",
Expand Down Expand Up @@ -136,7 +135,6 @@
"useAmount": "No. of questions",
"setting": "Setting",
"general": "General",
"advanced": "Advanced",
"statistics": "Statistics",
"config": "Base Config",
"chatRecord": "Chat History",
Expand All @@ -149,7 +147,6 @@
"name": "Name",
"description": "Description",
"saveUserInfo": "Save User Info",
"role": "Role",
"chatHistory": "ChatHistory",
"theme": "Theme",
"language": "Language",
Expand Down
3 changes: 0 additions & 3 deletions src/locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"delete": "削除",
"deleteSuccess": "削除しました",
"save": "保存",
"sync": "保存して全員に同期",
"test": "テスト",
"saveSuccess": "保存しました",
"reset": "リセット",
Expand Down Expand Up @@ -136,7 +135,6 @@
"useAmount": "質問回数",
"setting": "設定",
"general": "一般",
"advanced": "詳細",
"statistics": "統計",
"config": "基本設定",
"chatRecord": "チャット履歴",
Expand All @@ -149,7 +147,6 @@
"name": "名前",
"description": "説明",
"saveUserInfo": "ユーザー情報を保存",
"role": "ロール",
"chatHistory": "チャット履歴",
"theme": "テーマ",
"language": "言語",
Expand Down
Loading