Skip to content

Commit b4083e4

Browse files
author
ochafik
committed
Test chat_template in e2e test
1 parent a6afb27 commit b4083e4

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

examples/server/tests/unit/test_chat_completion.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@ def create_server():
1111

1212

1313
@pytest.mark.parametrize(
14-
"model,system_prompt,user_prompt,max_tokens,re_content,n_prompt,n_predicted,finish_reason,jinja",
14+
"model,system_prompt,user_prompt,max_tokens,re_content,n_prompt,n_predicted,finish_reason,jinja,chat_template",
1515
[
16-
(None, "Book", "What is the best book", 8, "(Suddenly)+", 77, 8, "length", False),
17-
(None, "Book", "What is the best book", 8, "(Suddenly)+", 77, 8, "length", True),
18-
("codellama70b", "You are a coding assistant.", "Write the fibonacci function in c++.", 128, "(Aside|she|felter|alonger)+", 104, 64, "length", False),
19-
("codellama70b", "You are a coding assistant.", "Write the fibonacci function in c++.", 128, "(Aside|she|felter|alonger)+", 104, 64, "length", True),
16+
(None, "Book", "What is the best book", 8, "(Suddenly)+", 77, 8, "length", False, None),
17+
(None, "Book", "What is the best book", 8, "(Suddenly)+", 77, 8, "length", True, None),
18+
(None, "Book", "What is the best book", 8, " blue and shin", 23, 8, "length", True, "This is not a chat template, it is"),
19+
("codellama70b", "You are a coding assistant.", "Write the fibonacci function in c++.", 128, "(Aside|she|felter|alonger)+", 104, 64, "length", False, None),
20+
("codellama70b", "You are a coding assistant.", "Write the fibonacci function in c++.", 128, "(Aside|she|felter|alonger)+", 104, 64, "length", True, None),
2021
]
2122
)
22-
def test_chat_completion(model, system_prompt, user_prompt, max_tokens, re_content, n_prompt, n_predicted, finish_reason, jinja):
23+
def test_chat_completion(model, system_prompt, user_prompt, max_tokens, re_content, n_prompt, n_predicted, finish_reason, jinja, chat_template):
2324
global server
2425
server.jinja = jinja
26+
server.chat_template = chat_template
2527
server.start()
2628
res = server.make_request("POST", "/chat/completions", data={
2729
"model": model,

examples/server/tests/utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ class ServerProcess:
7070
draft: int | None = None
7171
api_key: str | None = None
7272
lora_files: List[str] | None = None
73-
chat_template_file: str | None = None
74-
jinja: bool | None = None
7573
disable_ctx_shift: int | None = False
7674
draft_min: int | None = None
7775
draft_max: int | None = None
7876
no_webui: bool | None = None
77+
jinja: bool | None = None
7978
chat_template: str | None = None
79+
chat_template_file: str | None = None
8080

8181
# session variables
8282
process: subprocess.Popen | None = None
@@ -157,10 +157,6 @@ def start(self, timeout_seconds: int = 10) -> None:
157157
if self.lora_files:
158158
for lora_file in self.lora_files:
159159
server_args.extend(["--lora", lora_file])
160-
if self.chat_template_file:
161-
server_args.extend(["--chat-template-file", self.chat_template_file])
162-
if self.jinja:
163-
server_args.append("--jinja")
164160
if self.disable_ctx_shift:
165161
server_args.extend(["--no-context-shift"])
166162
if self.api_key:
@@ -171,9 +167,13 @@ def start(self, timeout_seconds: int = 10) -> None:
171167
server_args.extend(["--draft-min", self.draft_min])
172168
if self.no_webui:
173169
server_args.append("--no-webui")
170+
if self.jinja:
171+
server_args.append("--jinja")
174172
if self.chat_template:
175173
server_args.extend(["--chat-template", self.chat_template])
176-
174+
if self.chat_template_file:
175+
server_args.extend(["--chat-template-file", self.chat_template_file])
176+
177177
args = [str(arg) for arg in [server_path, *server_args]]
178178
print(f"bench: starting server with: {' '.join(args)}")
179179

0 commit comments

Comments
 (0)