Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow templates to be stored in subdirectories #65

Open
wants to merge 1 commit into
base: main_july_updates
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions promptify/prompter/nlp_prompter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches anything in the main directory as well as subdirectories, e.g.:

text2text/en/ner.jinja
text2text/en/qa.jinja
...
text2text/en/data_analysis/clustering.jinja

template_names = [os.path.basename(template) for template in all_templates]
template_dict = dict(zip(template_names, all_templates))
return template_dict
Expand Down Expand Up @@ -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)

Expand Down