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

Use Jinja filters instead of a tool decorator #69

Merged
merged 2 commits into from
Apr 25, 2023
Merged

Use Jinja filters instead of a tool decorator #69

merged 2 commits into from
Apr 25, 2023

Conversation

rlouf
Copy link
Member

@rlouf rlouf commented Apr 25, 2023

We can now use custom Jinja filters to get function names, descriptions, sources and signatures inside prompt templates:

import outlines.text as text


@text.prompt
def a_prompt(question: str, fn: Callable):
    """{{question}}

    COMMANDS:
    {{fn|name}}
    {{fn|description}}
    {{fn|signature}}
    {{fn|source}}
    """

This removes the need for the @outlines.tool decorator defined in #64. We also add a filter to get the simplified schema of a Pydantic model:

import outlines.text as text
from pydantic import BaseModel, Field

class Joke(BaseModel):
    joke: str = Field(description="a good joke")
    explanation: str

@text.prompt
def a_prompt(question: str, response_format: type(BaseModel)):
    """{{question}}

    OUTPUT FORMAT:
    {{response_format|schema}}
    """

a_prompt("Can you tell me a good joke?", Joke)
# Can you tell me a good joke?
#
# OUTPUT FORMAT:
# {
#    "joke": "a good joke", 
#    "explanation": "<explanation>"
# }

Closes #68

@rlouf rlouf merged commit ab47242 into main Apr 25, 2023
@rlouf rlouf deleted the jinja-filters branch April 25, 2023 20:38
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.

Implement the prompt encoding functionalities as Jinja custom filters
1 participant