Skip to content

Commit

Permalink
pass the filters with an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
derfred committed Jan 11, 2025
1 parent d0420a8 commit 04754df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions outlines/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ def _template_from_file(


def prompt(
fn_or_filters: Optional[
Union[Callable, List[Callable], Dict[str, Callable]]
] = None,
fn: Optional[Callable] = None,
filters: Union[List[Callable], Dict[str, Callable]] = [],
) -> Callable:
"""Decorate a function that contains a prompt template.
Expand Down Expand Up @@ -175,7 +173,7 @@ def prompt(
>>> def reverse(s: str) -> str:
... return s[::-1]
...
>>> @outlines.prompt([reverse])
>>> @outlines.prompt(filters=[reverse])
... def reverse_prompt(text):
... '''{{ text | reverse }}'''
...
Expand All @@ -188,16 +186,16 @@ def prompt(
A `Prompt` callable class which will render the template when called.
"""
if not callable(fn_or_filters):
if fn is None:
return lambda fn: prompt(
fn, cast(Union[List[Callable], Dict[str, Callable]], fn_or_filters)
fn, cast(Union[List[Callable], Dict[str, Callable]], filters)
)

signature = inspect.signature(fn_or_filters)
signature = inspect.signature(fn)

# The docstring contains the template that will be rendered to be used
# as a prompt to the language model.
docstring = fn_or_filters.__doc__
docstring = fn.__doc__
if docstring is None:
raise TypeError("Could not find a template in the function's docstring.")

Expand Down
4 changes: 2 additions & 2 deletions tests/test_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def test_prompt_with_additional_filters_as_dict():
def reverse(s: str) -> str:
return s[::-1]

@outlines.prompt(dict(reverse=reverse))
@outlines.prompt(filters=dict(reverse=reverse))
def test_tpl(variable):
"""{{ variable | reverse }} test"""

Expand All @@ -342,7 +342,7 @@ def test_prompt_with_additional_filters_as_list():
def reverse(s: str) -> str:
return s[::-1]

@outlines.prompt([reverse])
@outlines.prompt(filters=[reverse])
def test_tpl(variable):
"""{{ variable | reverse }} test"""

Expand Down

0 comments on commit 04754df

Please sign in to comment.