Skip to content

Commit cf21ce6

Browse files
committed
Remove special token management
1 parent c583f2e commit cf21ce6

File tree

4 files changed

+0
-79
lines changed

4 files changed

+0
-79
lines changed

prompts/templates.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import inspect
22
import re
3-
import warnings
43
from dataclasses import dataclass, field
54
from functools import lru_cache
65
from typing import Callable, Dict, Hashable, Optional
76

87
from jinja2 import Environment, StrictUndefined
98

10-
from prompts.tokens import SPECIAL_TOKENS, Special
11-
129

1310
@dataclass
1411
class Template:
@@ -148,10 +145,6 @@ def render(
148145
allow users to enter prompts more naturally than if they used Python's
149146
constructs directly. See the examples for a detailed explanation.
150147
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-
155148
Examples
156149
--------
157150
@@ -252,28 +245,12 @@ def render(
252245
# used to continue to the next line without linebreak.
253246
cleaned_template = re.sub(r"(?![\r\n])(\b\s+)", " ", cleaned_template)
254247

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-
266248
env = Environment(
267249
trim_blocks=True,
268250
lstrip_blocks=True,
269251
keep_trailing_newline=True,
270252
undefined=StrictUndefined,
271253
)
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
277254
jinja_template = env.from_string(cleaned_template)
278255

279256
return jinja_template.render(**values)

prompts/tokens.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

tests/test_templates.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -192,24 +192,3 @@ def simple_prompt_name(query: str):
192192
assert simple_prompt("test") == "test"
193193
assert simple_prompt["gpt2"]("test") == "test"
194194
assert simple_prompt["provider/name"]("test") == "name: test"
195-
196-
197-
def test_special_tokens():
198-
199-
@prompts.template
200-
def simple_prompt(query: str):
201-
return """{{ bos + query + eos }}"""
202-
203-
assert simple_prompt("test") == "test"
204-
assert simple_prompt["openai-community/gpt2"]("test") == "test<|endoftext|>"
205-
assert simple_prompt["mistralai/Mistral-7B-v0.1"]("test") == "<s>test</s>"
206-
207-
208-
def test_warn():
209-
210-
@prompts.template
211-
def simple_prompt():
212-
return """test"""
213-
214-
with pytest.warns(UserWarning, match="not present in the special token"):
215-
simple_prompt["non-existent-model"]()

tests/test_tokens.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)