From 514ab7e9e4bca52b31c980deb90276bf68dbd733 Mon Sep 17 00:00:00 2001 From: ChenZhaoYu <790348264@qq.com> Date: Sat, 11 Mar 2023 10:50:58 +0800 Subject: [PATCH 01/74] chore: change docs --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 73569b9e84..47797786f7 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,13 @@ 1. `ChatGPTAPI` 使用 `gpt-3.5-turbo-0301` 通过官方`OpenAI`补全`API`模拟`ChatGPT`(最稳健的方法,但它不是免费的,并且没有使用针对聊天进行微调的模型) 2. `ChatGPTUnofficialProxyAPI` 使用非官方代理服务器访问 `ChatGPT` 的后端`API`,绕过`Cloudflare`(使用真实的的`ChatGPT`,非常轻量级,但依赖于第三方服务器,并且有速率限制) -[查看详情](https://github.com/Chanzhaoyu/chatgpt-web/issues/138) +警告: +1. 你应该使用 `API` 方式并自建代理使你使用的风险降到最低。 +2. 使用 `accessToken` 方式时反向代理将向第三方暴露您的访问令牌。这样做应该不会产生任何不良影响,但在使用这种方法之前请考虑风险,修改代理地址时也请使用公开的[社区方案](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy),不要不要不要使用来源不明的地址! +2. 因为国内 `API` 被墙,如果服务器不在国外,则需要代理才能请求到官方接口,也非常不建议使用别人发出来的代理地址,请自己搭建。 +3. 人性是丑陋的,你永远不知道你相信的某些乐于分享的`好人`在用你的账号做什么!!! + +注:强烈建议使用`ChatGPTAPI`,因为它使用 `OpenAI` 官方支持的`API`。并且可能会在将来的版本中删除对`ChatGPTUnofficialProxyAPI`的支持。 切换方式: 1. 进入 `service/.env.example` 文件,复制内容到 `service/.env` 文件 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 02/74] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20Prompt=20?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=92=8C=20Prompt=20=E5=95=86=E5=BA=97?= =?UTF-8?q?=E6=94=AF=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 @@ diff --git a/src/locales/en-US.ts b/src/locales/en-US.ts index e8b470b080..e64eaca8ee 100644 --- a/src/locales/en-US.ts +++ b/src/locales/en-US.ts @@ -50,6 +50,7 @@ export default { reverseProxy: 'Reverse Proxy', timeout: 'Timeout', socks: 'Socks', + httpsProxy: 'HTTPS Proxy', }, } diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index a0cb26b4d7..8ee0e648d5 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -50,6 +50,7 @@ export default { reverseProxy: '反向代理', timeout: '超时', socks: 'Socks', + httpsProxy: 'HTTPS Proxy', }, } From 7bebee202e594331b9f94b53dd0c4ecd03241b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=9D=89=28Shan=20Wu=29?= Date: Sun, 12 Mar 2023 13:42:56 +0200 Subject: [PATCH 12/74] =?UTF-8?q?fix:=20Prompt=E5=95=86=E5=BA=97=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E5=AF=BC=E5=85=A5=E5=8F=AF=E4=BB=A5=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E4=B8=A4=E7=A7=8Drecommend.json=E9=87=8C=E6=8F=90=E5=88=B0?= =?UTF-8?q?=E7=9A=84=E6=A8=A1=E6=9D=BF=20(#516)=20(#521)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(PromptStore): import prompt template using different dict keys * chore(PromptStore): clear url field after downloading --- src/assets/recommend.json | 8 +++++- src/components/common/PromptStore/index.vue | 28 +++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/assets/recommend.json b/src/assets/recommend.json index 33786e18c9..4d6e82d1a9 100644 --- a/src/assets/recommend.json +++ b/src/assets/recommend.json @@ -1,8 +1,14 @@ [ + { + "key": "chatgpt-prompt-collection", + "desc": "Nothing1024收集整理的prompts", + "downloadUrl": "https://raw.githubusercontent.com/Nothing1024/chatgpt-prompt-collection/main/awesome-chatgpt-prompts-zh.json", + "url": "https://github.com/Nothing1024/chatgpt-prompt-collection" + }, { "key": "awesome-chatgpt-prompts-zh", "desc": "ChatGPT 中文调教指南", - "downloadUrl": "https://raw.githubusercontent.com/Nothing1024/chatgpt-prompt-collection/main/awesome-chatgpt-prompts-zh.json", + "downloadUrl": "https://raw.githubusercontent.com/PlexPt/awesome-chatgpt-prompts-zh/main/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 index 80efb08e7d..99017e032e 100644 --- a/src/components/common/PromptStore/index.vue +++ b/src/components/common/PromptStore/index.vue @@ -144,24 +144,41 @@ const clearPromptTemplate = () => { const importPromptTemplate = () => { try { const jsonData = JSON.parse(tempPromptValue.value) + let key = '' + let value = '' + // 可以扩展加入更多模板字典的key + if ('key' in jsonData[0]) { + key = 'key' + value = 'value' + } + else if ('act' in jsonData[0]) { + key = 'act' + value = 'prompt' + } + else { + // 不支持的字典的key防止导入 以免破坏prompt商店打开 + message.warning('prompt key not supported.') + throw new Error('prompt key not supported.') + } + for (const i of jsonData) { if (!('key' in i) || !('value' in i)) throw new Error('键值不匹配') let safe = true for (const j of promptList.value) { - if (j.key === i.key) { - message.warning(`因标题重复跳过:${i.key}`) + if (j.key === i[key]) { + message.warning(`因标题重复跳过:${i[key]}`) safe = false break } - if (j.value === i.value) { - message.warning(`因内容重复跳过:${i.key}`) + if (j.value === i[value]) { + message.warning(`因内容重复跳过:${i[key]}`) safe = false break } } if (safe) - promptList.value.unshift({ key: i.key, value: i.value } as never) + promptList.value.unshift({ key: i[key], value: i[value] } as never) } message.success('导入成功') changeShowModal('') @@ -194,6 +211,7 @@ const downloadPromptTemplate = async () => { }).then(() => { importPromptTemplate() }) + downloadURL.value = '' } catch { message.error('网络导入出现问题,请检查网络状态与 JSON 文件有效性') From de6632d631614f5f0857a9bb8b4c545fc66972e0 Mon Sep 17 00:00:00 2001 From: ChenZhaoYu <790348264@qq.com> Date: Sun, 12 Mar 2023 20:49:10 +0800 Subject: [PATCH 13/74] =?UTF-8?q?feat:=20=E4=BB=93=E5=BA=93=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/PromptStore/index.vue | 173 ++++++++++---------- src/locales/en-US.ts | 30 +++- src/locales/index.ts | 4 +- src/locales/zh-CN.ts | 30 +++- src/locales/zh-TW.ts | 28 ++++ 5 files changed, 176 insertions(+), 89 deletions(-) diff --git a/src/components/common/PromptStore/index.vue b/src/components/common/PromptStore/index.vue index 99017e032e..b1b41ae099 100644 --- a/src/components/common/PromptStore/index.vue +++ b/src/components/common/PromptStore/index.vue @@ -1,11 +1,12 @@