Skip to content
Open
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"typescript": "4.9",
"vite": "4.3.1",
"vite-plugin-html": "3.2.0",
"vite-plugin-progress": "^0.0.6"
"vite-plugin-progress": "^0.0.6",
"xlsx-js-style": "^1.2.0"
},
"dependencies": {
"@fontsource/fira-code": "4.5.13",
Expand Down
41 changes: 37 additions & 4 deletions src/Compoents/PromptEditor/Lib/DatabaseServer/DatabaseServer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fetchFromNotion } from "./lib/fetchFromNotion"
import XLSX from "xlsx-js-style"

export interface IPromptDefineItem {
text: string
Expand All @@ -22,10 +23,42 @@ export class DatabaseServer {
return this.isReady
}
async init() {
// localJson
let localPromptDescMap = await (await fetch("./localPromptDefineMap.json")).json()
// console.log('localPromptDescMap',localPromptDescMap)
this.localPromptDefineMap = localPromptDescMap
let buffer = await (await fetch("./prompt.xlsx")).arrayBuffer()
let workbook = XLSX.read(new Uint8Array(buffer), { type: "array" }),
subTypeMap:any = {
角色: "character",
风格: "style",
质量: "quality",
命令: "command",
负面: "eg",
},
sheetNameList = workbook.SheetNames,
mapDict:any = {}

sheetNameList.forEach((sheetName) => {
let subTypeName = sheetName.replace(/[-\.].*/, ""),
subType = subTypeMap[subTypeName];
if (!subType) {
console.log(`遇到无对应 subType 的 Sheet: "${sheetName}", 跳过`)
return; //如果sheet不是以subType名字开头的话,就跳过
}
console.log(`已经读入 ${sheetName}" 对应 ${subType} 类型`)
let ws:any = workbook.Sheets[sheetName],
lenth = XLSX.utils.decode_range(ws["!ref"]).e.r //How much lines of this sheet
Array.from(Array(lenth), (_, i) => i + 2).forEach((id) => {
if (ws[`A${id}`]) {
let prompt:any = { text: ws[`A${id}`].v, dir: `${subTypeName}/未知` } //text
ws[`B${id}`] && (prompt.lang_zh = ws[`B${id}`].v) //lang_zh
prompt.subType = subType //subType
ws[`E${id}`] && (prompt.desc = ws[`E${id}`].v) //desc
ws[`D${id}`] && (prompt.sampleCmds = JSON.parse(ws[`D${id}`].v)) //sampleCmds
ws[`C${id}`] && (prompt.dir = `${subTypeName}/${ws[`C${id}`].v}`) //dir
mapDict[ws[`A${id}`].v.toLowerCase()] = prompt
}
})
})

this.localPromptDefineMap = mapDict
return true
}
async queryPromptsDefine(prompts: string[]): Promise<IPromptDefineItem[]> {
Expand Down
Binary file added web/public/prompt.xlsx
Binary file not shown.