File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -123,8 +123,21 @@ print(random_prompt())
123123#### Fill variables in template prompts:
124124
125125``` py
126- prompt = ai_personas[' Node.js Automation Script Developer' ][' prompt' ]
127- filled_prompt = prompt.replace(' ${taskType} ' , ' web scraping' )
126+ def extract_placeholders (prompt ):
127+ import re
128+ matches = re.findall(r ' \$\{ ( . *? ) \} ' , prompt)
129+ return list (dict .fromkeys(matches))
130+
131+ def fill_vars_in_prompt (prompt , placeholders , vals ):
132+ filled_prompt = prompt
133+ for name in placeholders:
134+ if name in vals:
135+ filled_prompt = filled_prompt.replace(f " $ {{ { name} }} " , vals[name])
136+ return filled_prompt
137+
138+ prompt = personas[' Node.js Automation Script Developer' ][' prompt' ]
139+ placeholders = extract_placeholders(prompt)
140+ filled_prompt = fill_vars_in_prompt(prompt, placeholders, {' taskType' : ' web scraping' })
128141
129142print (filled_prompt)
130143
You can’t perform that action at this time.
0 commit comments