Skip to content

Commit a70465e

Browse files
committed
Created extract/fill functions ↞ [auto-sync from https://github.com/KudoAI/ai-personas/tree/main/python]
1 parent 1fd7330 commit a70465e

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

ai-personas/docs/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff 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

129142
print(filled_prompt)
130143

0 commit comments

Comments
 (0)