From 00ade41a7630d64b7657347f65ed3ba265b99ec5 Mon Sep 17 00:00:00 2001 From: Nothing1024 <78358913+Nothing1024@users.noreply.github.com> Date: Sat, 11 Mar 2023 16:09:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20Prompt=20=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=92=8C=20Prompt=20=E5=95=86=E5=BA=97=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20(#268)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 添加Prompt模板和Prompt商店支持 * feat: well done --------- Co-authored-by: Redon <790348264@qq.com> --- src/assets/recommend.json | 8 + src/components/common/PromptStore/index.vue | 429 ++++++++++++++++++++ src/components/common/index.ts | 3 +- src/store/modules/index.ts | 1 + src/store/modules/prompt/helper.ts | 18 + src/store/modules/prompt/index.ts | 17 + src/views/chat/index.vue | 50 ++- src/views/chat/layout/sider/index.vue | 10 +- 8 files changed, 525 insertions(+), 11 deletions(-) create mode 100644 src/assets/recommend.json create mode 100644 src/components/common/PromptStore/index.vue create mode 100644 src/store/modules/prompt/helper.ts create mode 100644 src/store/modules/prompt/index.ts diff --git a/src/assets/recommend.json b/src/assets/recommend.json new file mode 100644 index 0000000000..33786e18c9 --- /dev/null +++ b/src/assets/recommend.json @@ -0,0 +1,8 @@ +[ + { + "key": "awesome-chatgpt-prompts-zh", + "desc": "ChatGPT 中文调教指南", + "downloadUrl": "https://raw.githubusercontent.com/Nothing1024/chatgpt-prompt-collection/main/awesome-chatgpt-prompts-zh.json", + "url": "https://github.com/PlexPt/awesome-chatgpt-prompts-zh" + } +] diff --git a/src/components/common/PromptStore/index.vue b/src/components/common/PromptStore/index.vue new file mode 100644 index 0000000000..97b567510c --- /dev/null +++ b/src/components/common/PromptStore/index.vue @@ -0,0 +1,429 @@ + + + diff --git a/src/components/common/index.ts b/src/components/common/index.ts index 16b6d1083a..d8f03ec65c 100644 --- a/src/components/common/index.ts +++ b/src/components/common/index.ts @@ -3,5 +3,6 @@ import NaiveProvider from './NaiveProvider/index.vue' import SvgIcon from './SvgIcon/index.vue' import UserAvatar from './UserAvatar/index.vue' import Setting from './Setting/index.vue' +import PromptStore from './PromptStore/index.vue' -export { HoverButton, NaiveProvider, SvgIcon, UserAvatar, Setting } +export { HoverButton, NaiveProvider, SvgIcon, UserAvatar, Setting, PromptStore } diff --git a/src/store/modules/index.ts b/src/store/modules/index.ts index b33b51b5ab..74e4825532 100644 --- a/src/store/modules/index.ts +++ b/src/store/modules/index.ts @@ -1,4 +1,5 @@ export * from './app' export * from './chat' export * from './user' +export * from './prompt' export * from './auth' diff --git a/src/store/modules/prompt/helper.ts b/src/store/modules/prompt/helper.ts new file mode 100644 index 0000000000..6b21c2b8c9 --- /dev/null +++ b/src/store/modules/prompt/helper.ts @@ -0,0 +1,18 @@ +import { ss } from '@/utils/storage' + +const LOCAL_NAME = 'promptStore' + +export type PromptList = [] + +export interface PromptStore { + promptList: PromptList +} + +export function getLocalPromptList(): PromptStore { + const promptStore: PromptStore | undefined = ss.get(LOCAL_NAME) + return promptStore ?? { promptList: [] } +} + +export function setLocalPromptList(promptStore: PromptStore): void { + ss.set(LOCAL_NAME, promptStore) +} diff --git a/src/store/modules/prompt/index.ts b/src/store/modules/prompt/index.ts new file mode 100644 index 0000000000..2365ecdcc5 --- /dev/null +++ b/src/store/modules/prompt/index.ts @@ -0,0 +1,17 @@ +import { defineStore } from 'pinia' +import type { PromptStore } from './helper' +import { getLocalPromptList, setLocalPromptList } from './helper' + +export const usePromptStore = defineStore('prompt-store', { + state: (): PromptStore => getLocalPromptList(), + + actions: { + updatePromptList(promptList: []) { + this.$patch({ promptList }) + setLocalPromptList({ promptList }) + }, + getPromptList() { + return this.$state + }, + }, +}) diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index f18cd4b8cc..92ecd58c31 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -1,7 +1,8 @@