From e4acc539491670da404bb341f3ca8470b58ebe60 Mon Sep 17 00:00:00 2001 From: escesare Date: Wed, 19 Apr 2023 16:47:16 -0400 Subject: [PATCH] Allow templates to be stored in subdirectories --- promptify/prompter/nlp_prompter.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/promptify/prompter/nlp_prompter.py b/promptify/prompter/nlp_prompter.py index 13bd98d..b4422af 100644 --- a/promptify/prompter/nlp_prompter.py +++ b/promptify/prompter/nlp_prompter.py @@ -136,7 +136,7 @@ def get_available_templates(self, template_path: str) -> Dict[str, str]: A dictionary containing the names and paths of the templates in the directory. """ - all_templates = glob.glob(f"{template_path}/*.jinja") + all_templates = glob.glob(f"{template_path}/**/*.jinja", recursive=True) template_names = [os.path.basename(template) for template in all_templates] template_dict = dict(zip(template_names, all_templates)) return template_dict @@ -199,8 +199,7 @@ def load_template(self, template: str): default_templates = self.get_available_templates(templates_dir) if template in default_templates: - template_name = template - template_dir = templates_dir + template_dir, template_name = os.path.split(default_templates[template]) environment = Environment(loader=FileSystemLoader(template_dir)) template_instance = environment.get_template(template)