diff --git a/README.en.md b/README.en.md index fd557cb3..185cf1a4 100644 --- a/README.en.md +++ b/README.en.md @@ -7,7 +7,18 @@
## Introduction -> **This project is forked from [Chanzhaoyu/chatgpt-web](https://github.com/Chanzhaoyu/chatgpt-web). In addition to regularly merging this branch, some unique features have been added such as registration and login, setting API key on the front-end page.** +> **This project is forked from [Chanzhaoyu/chatgpt-web](https://github.com/Chanzhaoyu/chatgpt-web), some unique features have been added:** + +[✓] Register & Login & Reset Password + +[✓] Sync chat history + +[✓] Front-end page setting apikey + +[✓] Custom Sensitive Words + +[✓] Set unique prompts for each chat room +
## Screenshots @@ -17,6 +28,7 @@ ![cover](./docs/c1.png) ![cover2](./docs/c2.png) ![cover3](./docs/basesettings.jpg) +![cover3](./docs/prompt_en.jpg) - [ChatGPT Web](#chatgpt-web) - [Introduction](#introduction) diff --git a/README.md b/README.md index 55496da3..56196026 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,17 @@
## 说明 -> **此项目 Fork 自 [Chanzhaoyu/chatgpt-web](https://github.com/Chanzhaoyu/chatgpt-web), 除了定时合并该分支, 新增了部分特色功能, 注册&登录, 前端页面设置apikey 等** +> **此项目 Fork 自 [Chanzhaoyu/chatgpt-web](https://github.com/Chanzhaoyu/chatgpt-web), 新增了部分特色功能:** + +[✓] 注册&登录&重置密码 + +[✓] 同步历史会话 + +[✓] 前端页面设置apikey + +[✓] 自定义敏感词 + +[✓] 每个会话设置独有 Prompt
## 截图 @@ -17,6 +27,7 @@ ![cover](./docs/c1.png) ![cover2](./docs/c2.png) ![cover3](./docs/basesettings.jpg) +![cover3](./docs/prompt.jpg) - [ChatGPT Web](#chatgpt-web) - [介绍](#介绍) diff --git a/docs/prompt.jpg b/docs/prompt.jpg new file mode 100644 index 00000000..ed21c8ba Binary files /dev/null and b/docs/prompt.jpg differ diff --git a/docs/prompt_en.jpg b/docs/prompt_en.jpg new file mode 100644 index 00000000..3fab12b1 Binary files /dev/null and b/docs/prompt_en.jpg differ diff --git a/package.json b/package.json index b8a226f1..4969b8e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chatgpt-web", - "version": "2.12.0", + "version": "2.12.3", "private": false, "description": "ChatGPT Web", "author": "ChenZhaoYu ", diff --git a/service/src/index.ts b/service/src/index.ts index ab73d182..bc0a6418 100644 --- a/service/src/index.ts +++ b/service/src/index.ts @@ -17,6 +17,7 @@ import { deleteChatRoom, existsChatRoom, getChat, + getChatRoom, getChatRooms, getChats, getUser, @@ -26,6 +27,7 @@ import { renameChatRoom, updateChat, updateConfig, + updateRoomPrompt, updateUserInfo, updateUserPassword, verifyUser, @@ -61,6 +63,7 @@ router.get('/chatrooms', auth, async (req, res) => { uuid: r.roomId, title: r.title, isEdit: false, + prompt: r.prompt, }) }) res.send({ status: 'Success', message: null, data: result }) @@ -97,6 +100,22 @@ router.post('/room-rename', auth, async (req, res) => { } }) +router.post('/room-prompt', auth, async (req, res) => { + try { + const userId = req.headers.userId as string + const { prompt, roomId } = req.body as { prompt: string; roomId: number } + const success = await updateRoomPrompt(userId, roomId, prompt) + if (success) + res.send({ status: 'Success', message: 'Saved successfully', data: null }) + else + res.send({ status: 'Fail', message: 'Saved Failed', data: null }) + } + catch (error) { + console.error(error) + res.send({ status: 'Fail', message: 'Rename error', data: null }) + } +}) + router.post('/room-delete', auth, async (req, res) => { try { const userId = req.headers.userId as string @@ -272,7 +291,11 @@ router.post('/chat', auth, async (req, res) => { router.post('/chat-process', [auth, limiter], async (req, res) => { res.setHeader('Content-type', 'application/octet-stream') - const { roomId, uuid, regenerate, prompt, options = {}, systemMessage, temperature, top_p } = req.body as RequestProps + let { roomId, uuid, regenerate, prompt, options = {}, systemMessage, temperature, top_p } = req.body as RequestProps + const userId = req.headers.userId as string + const room = await getChatRoom(userId, roomId) + if (room != null && isNotEmptyString(room.prompt)) + systemMessage = room.prompt let lastResponse let result diff --git a/service/src/storage/model.ts b/service/src/storage/model.ts index 51f59f09..27160cfc 100644 --- a/service/src/storage/model.ts +++ b/service/src/storage/model.ts @@ -37,10 +37,12 @@ export class ChatRoom { roomId: number userId: string title: string + prompt: string status: Status = Status.Normal constructor(userId: string, title: string, roomId: number) { this.userId = userId this.title = title + this.prompt = undefined this.roomId = roomId } } diff --git a/service/src/storage/mongo.ts b/service/src/storage/mongo.ts index 4b23ebe2..7e346ee5 100644 --- a/service/src/storage/mongo.ts +++ b/service/src/storage/mongo.ts @@ -77,6 +77,17 @@ export async function deleteChatRoom(userId: string, roomId: number) { return result } +export async function updateRoomPrompt(userId: string, roomId: number, prompt: string) { + const query = { userId, roomId } + const update = { + $set: { + prompt, + }, + } + const result = await roomCol.updateOne(query, update) + return result.modifiedCount > 0 +} + export async function getChatRooms(userId: string) { const cursor = await roomCol.find({ userId, status: { $ne: Status.Deleted } }) const rooms = [] @@ -84,6 +95,10 @@ export async function getChatRooms(userId: string) { return rooms } +export async function getChatRoom(userId: string, roomId: number) { + return await roomCol.findOne({ userId, roomId, status: { $ne: Status.Deleted } }) as ChatRoom +} + export async function existsChatRoom(userId: string, roomId: number) { const room = await roomCol.findOne({ roomId, userId }) return !!room diff --git a/src/api/index.ts b/src/api/index.ts index 9bad5dd4..57773fd0 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -134,6 +134,13 @@ export function fetchRenameChatRoom(title: string, roomId: number) { }) } +export function fetchUpdateChatRoomPrompt(prompt: string, roomId: number) { + return post({ + url: '/room-prompt', + data: { prompt, roomId }, + }) +} + export function fetchDeleteChatRoom(roomId: number) { return post({ url: '/room-delete', diff --git a/src/components/common/Setting/Prompt.vue b/src/components/common/Setting/Prompt.vue new file mode 100644 index 00000000..b9ac3c77 --- /dev/null +++ b/src/components/common/Setting/Prompt.vue @@ -0,0 +1,73 @@ + + + diff --git a/src/components/common/UserAvatar/index.vue b/src/components/common/UserAvatar/index.vue index 91116c64..41d9bb49 100644 --- a/src/components/common/UserAvatar/index.vue +++ b/src/components/common/UserAvatar/index.vue @@ -1,16 +1,20 @@ @@ -33,8 +37,11 @@ const userInfo = computed(() => userStore.userInfo)

{{ userInfo.name }}

- - + + {{ $t('common.notLoggedIn') }} diff --git a/src/icons/Prompt.vue b/src/icons/Prompt.vue new file mode 100644 index 00000000..3a4aa0b5 --- /dev/null +++ b/src/icons/Prompt.vue @@ -0,0 +1,10 @@ + diff --git a/src/typings/chat.d.ts b/src/typings/chat.d.ts index 17ccac3d..a65b39e2 100644 --- a/src/typings/chat.d.ts +++ b/src/typings/chat.d.ts @@ -23,6 +23,7 @@ declare namespace Chat { uuid: number loading?: boolean all?: boolean + prompt?: string } interface ChatState { diff --git a/src/views/chat/components/Header/index.vue b/src/views/chat/components/Header/index.vue index ea53f279..3239bdc4 100644 --- a/src/views/chat/components/Header/index.vue +++ b/src/views/chat/components/Header/index.vue @@ -2,14 +2,17 @@ import { computed, nextTick } from 'vue' import { HoverButton, SvgIcon } from '@/components/common' import { useAppStore, useChatStore } from '@/store' +import IconPrompt from '@/icons/Prompt.vue' interface Props { usingContext: boolean + showPrompt: boolean } interface Emit { (ev: 'export'): void (ev: 'toggleUsingContext'): void + (ev: 'toggleShowPrompt'): void } defineProps() @@ -39,6 +42,10 @@ function handleExport() { function toggleUsingContext() { emit('toggleUsingContext') } + +function handleShowPrompt() { + emit('toggleShowPrompt') +}