|
1 | 1 | import inspect |
2 | 2 | import re |
3 | | -import warnings |
4 | 3 | from dataclasses import dataclass, field |
5 | 4 | from functools import lru_cache |
6 | 5 | from typing import Callable, Dict, Hashable, Optional |
7 | 6 |
|
8 | 7 | from jinja2 import Environment, StrictUndefined |
9 | 8 |
|
10 | | -from prompts.tokens import SPECIAL_TOKENS, Special |
11 | | - |
12 | 9 |
|
13 | 10 | @dataclass |
14 | 11 | class Template: |
@@ -148,10 +145,6 @@ def render( |
148 | 145 | allow users to enter prompts more naturally than if they used Python's |
149 | 146 | constructs directly. See the examples for a detailed explanation. |
150 | 147 |
|
151 | | - We also define the `bos` and `eos` special variables which, when used, will |
152 | | - be replaced by the model's BOS and EOS tokens respectively. This allows you |
153 | | - to write prompts that are model-agnostic. |
154 | | -
|
155 | 148 | Examples |
156 | 149 | -------- |
157 | 150 |
|
@@ -252,28 +245,12 @@ def render( |
252 | 245 | # used to continue to the next line without linebreak. |
253 | 246 | cleaned_template = re.sub(r"(?![\r\n])(\b\s+)", " ", cleaned_template) |
254 | 247 |
|
255 | | - # Warn the user when the model is not present in the special token registry |
256 | | - if model_name not in SPECIAL_TOKENS: |
257 | | - warnings.warn( |
258 | | - UserWarning( |
259 | | - f"The model {model_name} is not present in the special token registry." |
260 | | - "As a result, EOS and BOS tokens will be rendered as the empty string." |
261 | | - "Please open an issue: https://github.com/outlines-dev/prompts/issues" |
262 | | - "And ask for the model to be added to the registry." |
263 | | - ) |
264 | | - ) |
265 | | - |
266 | 248 | env = Environment( |
267 | 249 | trim_blocks=True, |
268 | 250 | lstrip_blocks=True, |
269 | 251 | keep_trailing_newline=True, |
270 | 252 | undefined=StrictUndefined, |
271 | 253 | ) |
272 | | - env.globals["bos"] = SPECIAL_TOKENS.get(model_name, Special()).sequence.begin |
273 | | - env.globals["eos"] = SPECIAL_TOKENS.get(model_name, Special()).sequence.end |
274 | | - env.globals["user"] = SPECIAL_TOKENS.get(model_name, Special()).user |
275 | | - env.globals["assistant"] = SPECIAL_TOKENS.get(model_name, Special()).assistant |
276 | | - env.globals["system"] = SPECIAL_TOKENS.get(model_name, Special()).system |
277 | 254 | jinja_template = env.from_string(cleaned_template) |
278 | 255 |
|
279 | 256 | return jinja_template.render(**values) |
0 commit comments