1
2
3
4
5
6
7
8
9
10
11
12
13
| import type { PromptVariable } from '@/models/debug'
|
| export function replaceStringWithValues(str: string, promptVariables: PromptVariable[], inputs: Record<string, any>) {
| return str.replace(/\{\{([^}]+)\}\}/g, (match, key) => {
| const name = inputs[key]
| if (name) { // has set value
| return name
| }
|
| const valueObj: PromptVariable | undefined = promptVariables.find(v => v.key === key)
| return valueObj ? `{{${valueObj.name}}}` : match
| })
| }
|
|