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

Add args to Jinja filters #902

Merged
merged 7 commits into from
May 17, 2024
Merged

Add args to Jinja filters #902

merged 7 commits into from
May 17, 2024

Conversation

eitanturok
Copy link
Contributor

In the outlines docs, we have the example

import outlines

def my_tool(arg1: str, arg2: int):
    """Tool description.

    The rest of the docstring
    """
    pass

@outlines.prompt
def tool_prompt(question, tool):
    """{{ question }}

    COMMANDS
    1. {{ tool | name }}: {{ tool | description }}, args: {{ tool | args }}

    {{ tool | source }}
    """

prompt = tool_prompt("Can you do something?", my_tool)
print(prompt)

However, when I tried running this code, it did not work because the args filter used in {{ tool | args }} was not implemented. I implemented the args filter so now this example works.

Now the args filter will output all of the arguments with the type annotations and default values (if they are provided).
Example:

from typing import List

def foo(x, y: str, z: List[int]=[1, 2, 3]):
    pass

@outlines.prompt
def tool_prompt(fn):
    """My args: {{ fn | args }}"""

prompt = tool_prompt(foo)
print(prompt)

which outputs

My args: x, y: str, z: List[int] = [1, 2, 3]

@rlouf rlouf changed the title add args to prompt Add args to Jinja filters May 17, 2024
@rlouf rlouf merged commit 3e291b1 into outlines-dev:main May 17, 2024
5 checks passed
@rlouf
Copy link
Member

rlouf commented May 17, 2024

Thank you so much for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants