feat: init

This commit is contained in:
Joel
2023-04-14 20:35:08 +08:00
parent 8acd8f6fbd
commit 97d3a6277d
77 changed files with 5299 additions and 0 deletions

12
utils/prompt.ts Normal file
View File

@ -0,0 +1,12 @@
import { PromptVariable } from '@/types/app'
export function replaceVarWithValues(str: string, promptVariables: PromptVariable[], inputs: Record<string, any>) {
return str.replace(/\{\{([^}]+)\}\}/g, (match, key) => {
const name = inputs[key]
if (name)
return name
const valueObj: PromptVariable | undefined = promptVariables.find(v => v.key === key)
return valueObj ? `{{${valueObj.key}}}` : match
})
}

6
utils/string.ts Normal file
View File

@ -0,0 +1,6 @@
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'
export function randomString(length: number) {
let result = ''
for (let i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)]
return result
}