Spaces:
Build error
Build error
File size: 599 Bytes
63551f1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import yaml
from pathlib import Path
def load_prompt(path: str, prompt_name: str, **kwargs) -> str:
"""
Load a specific named prompt from a YAML file and replace placeholders.
Args:
path (str): Path to YAML file.
prompt_name (str): Key of the prompt inside the YAML.
**kwargs: Replacement values for placeholders.
Returns:
str: Final formatted prompt string.
"""
with open(path, "r", encoding="utf-8") as f:
prompts = yaml.safe_load(f)
prompt_template = prompts[prompt_name]
return prompt_template.format(**kwargs)
|