-
Notifications
You must be signed in to change notification settings - Fork 539
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
add filters to prompt function #1371
base: main
Are you sure you want to change the base?
Conversation
outlines/prompts.py
Outdated
return env.get_template(os.path.basename(path)) | ||
|
||
|
||
def prompt(fn: Callable) -> Prompt: | ||
def prompt(fn: Optional[Callable] = None, **filters: Dict[str, Callable]) -> Callable: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filters
should be a simple argument that has type Dict[str, Callable]
and maps the filter names to the functions.
outlines/prompts.py
Outdated
@@ -118,10 +125,14 @@ def _template_from_file(_, path: Path) -> jinja2.Template: | |||
keep_trailing_newline=True, | |||
undefined=jinja2.StrictUndefined, | |||
) | |||
|
|||
for name, filter_fn in filters.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally don't mind a little repetition but I think we should refactor the code and add a create_environment
class that can be used in both class methods. @yvan-sraka are there any reasons we shouldn't do that?
thanks for your review @rlouf. I've taken your comments into account. While doing so the following alternative approach came to me:
what do you think? |
Allow giving custom filters to the prompt decorator