Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prompt商店在线导入可以导入两种recommend.json里提到的模板 (#516) #521

Merged
merged 2 commits into from
Mar 12, 2023
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
8 changes: 7 additions & 1 deletion src/assets/recommend.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
28 changes: 23 additions & 5 deletions src/components/common/PromptStore/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,39 @@ 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) {
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('')
Expand Down Expand Up @@ -192,6 +209,7 @@ const downloadPromptTemplate = async () => {
}).then(() => {
importPromptTemplate()
})
downloadURL.value = ''
}
catch {
message.error('网络导入出现问题,请检查网络状态与 JSON 文件有效性')
Expand Down