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

Provide generic bos and eos variables #6

Merged
merged 3 commits into from
Jul 30, 2024

Conversation

rlouf
Copy link
Member

@rlouf rlouf commented Jul 30, 2024

This PR provides generic bos and eos variables that can be added to a prompt template and will be rendered correctly for the specified model. For instance:

import prompts


@prompt.template
def simple_prompt(query: str):
    """{{ bos + query + eos}}"""


print(simple_prompt["mistralai/Mistral-7B-v0.1"]("test"))
# <s>test</s>

This begs a question: should we automatically add BOS tokens to prompt templates? My current inclination is to answer no: @prompt.template should give full control to the user over which tokens are used. We could, however, introduce a function that takes care of formatting the prompt correctly for non-chat workflows (which are handled via #4) and could handle common mistakes such as double BOS tokens.

Closes #2.

When rendering templates with special variables representing, e.g., BOS
tokens we need to know which model the prompt is going to be passed to
so as to render the template with the appropriate token. This PR adds
a `model_name` attribute to the `Template` class.
@rlouf rlouf added the enhancement New feature or request label Jul 30, 2024
@rlouf rlouf self-assigned this Jul 30, 2024
@rlouf rlouf force-pushed the add-special-variables branch 3 times, most recently from 5adddb5 to ec36ba8 Compare July 30, 2024 11:28
rlouf added 2 commits July 30, 2024 13:28
We define Jinja2 `eos` and `bos` global variables that are rendered
as EOS and BOS tokens.
@rlouf rlouf merged commit d2eeaf9 into dottxt-ai:master Jul 30, 2024
5 checks passed
@rlouf rlouf deleted the add-special-variables branch July 30, 2024 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide generic BOS and EOS variables
1 participant