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] =?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 33786e1..4d6e82d 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 80efb08..99017e0 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 文件有效性')