mirror of
https://github.com/langgenius/webapp-conversation.git
synced 2025-12-08 17:32:27 +08:00
12 lines
431 B
TypeScript
12 lines
431 B
TypeScript
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
|
|
})
|
|
} |