@@ -41,8 +41,8 @@ def server(zephyr_lora_added_tokens_files: str): # noqa: F811
41
41
@pytest .fixture (scope = "module" )
42
42
def tokenizer_name (model_name : str ,
43
43
zephyr_lora_added_tokens_files : str ): # noqa: F811
44
- return zephyr_lora_added_tokens_files if (
45
- model_name == "zephyr-lora2" ) else model_name
44
+ return ( zephyr_lora_added_tokens_files if
45
+ ( model_name == "zephyr-lora2" ) else model_name )
46
46
47
47
48
48
@pytest_asyncio .fixture
@@ -69,12 +69,14 @@ async def test_tokenize_completions(
69
69
prompt = "vllm1 This is a test prompt."
70
70
tokens = tokenizer .encode (prompt , add_special_tokens = add_special )
71
71
72
- response = requests .post (server .url_for ("tokenize" ),
73
- json = {
74
- "add_special_tokens" : add_special ,
75
- "model" : model_name ,
76
- "prompt" : prompt
77
- })
72
+ response = requests .post (
73
+ server .url_for ("tokenize" ),
74
+ json = {
75
+ "add_special_tokens" : add_special ,
76
+ "model" : model_name ,
77
+ "prompt" : prompt ,
78
+ },
79
+ )
78
80
response .raise_for_status ()
79
81
80
82
result = response .json ()
@@ -100,16 +102,20 @@ async def test_tokenize_chat(
100
102
101
103
for add_generation in [False , True ]:
102
104
for add_special in [False , True ]:
103
- conversation = [{
104
- "role" : "user" ,
105
- "content" : "Hi there!"
106
- }, {
107
- "role" : "assistant" ,
108
- "content" : "Nice to meet you!"
109
- }, {
110
- "role" : "user" ,
111
- "content" : "Can I ask a question? vllm1"
112
- }]
105
+ conversation = [
106
+ {
107
+ "role" : "user" ,
108
+ "content" : "Hi there!"
109
+ },
110
+ {
111
+ "role" : "assistant" ,
112
+ "content" : "Nice to meet you!"
113
+ },
114
+ {
115
+ "role" : "user" ,
116
+ "content" : "Can I ask a question? vllm1"
117
+ },
118
+ ]
113
119
for continue_final in [False , True ]:
114
120
if add_generation and continue_final :
115
121
continue
@@ -123,20 +129,21 @@ async def test_tokenize_chat(
123
129
add_generation_prompt = add_generation ,
124
130
continue_final_message = continue_final ,
125
131
conversation = conversation ,
126
- tokenize = False )
132
+ tokenize = False ,
133
+ )
127
134
tokens = tokenizer .encode (prompt ,
128
135
add_special_tokens = add_special )
129
136
130
- response = requests .post (server . url_for ( "tokenize" ),
131
- json = {
132
- "add_generation_prompt" :
133
- add_generation ,
134
- "continue_final_message" :
135
- continue_final ,
136
- "add_special_tokens " : add_special ,
137
- "messages " : conversation ,
138
- "model" : model_name
139
- } )
137
+ response = requests .post (
138
+ server . url_for ( "tokenize" ),
139
+ json = {
140
+ "add_generation_prompt" : add_generation ,
141
+ "continue_final_message" : continue_final ,
142
+ "add_special_tokens" : add_special ,
143
+ "messages " : conversation ,
144
+ "model " : model_name ,
145
+ },
146
+ )
140
147
response .raise_for_status ()
141
148
142
149
result = response .json ()
@@ -275,11 +282,13 @@ async def test_detokenize(
275
282
prompt = "This is a test prompt. vllm1"
276
283
tokens = tokenizer .encode (prompt , add_special_tokens = False )
277
284
278
- response = requests .post (server .url_for ("detokenize" ),
279
- json = {
280
- "model" : model_name ,
281
- "tokens" : tokens
282
- })
285
+ response = requests .post (
286
+ server .url_for ("detokenize" ),
287
+ json = {
288
+ "model" : model_name ,
289
+ "tokens" : tokens
290
+ },
291
+ )
283
292
response .raise_for_status ()
284
293
285
294
assert response .json () == {"prompt" : prompt }
@@ -302,18 +311,18 @@ async def test_get_tokenizer_info_basic(
302
311
result = response .json ()
303
312
assert "tokenizer_class" in result
304
313
assert isinstance (result ["tokenizer_class" ], str )
305
- assert result ["tokenizer_class" ]
314
+ assert result ["tokenizer_class" ]
306
315
307
316
308
- @pytest .mark .asyncio
317
+ @pytest .mark .asyncio
309
318
async def test_get_tokenizer_info_schema (server : RemoteOpenAIServer ):
310
319
"""Test that the response matches expected schema types."""
311
320
response = requests .get (server .url_for ("get_tokenizer_info" ))
312
321
response .raise_for_status ()
313
322
result = response .json ()
314
323
field_types = {
315
324
"add_bos_token" : bool ,
316
- "add_prefix_space" : bool ,
325
+ "add_prefix_space" : bool ,
317
326
"clean_up_tokenization_spaces" : bool ,
318
327
"split_special_tokens" : bool ,
319
328
"bos_token" : str ,
@@ -328,11 +337,14 @@ async def test_get_tokenizer_info_schema(server: RemoteOpenAIServer):
328
337
}
329
338
for field , expected_type in field_types .items ():
330
339
if field in result and result [field ] is not None :
331
- assert isinstance (result [field ], expected_type ), f"{ field } should be { expected_type .__name__ } "
340
+ assert isinstance (
341
+ result [field ],
342
+ expected_type ), (f"{ field } should be { expected_type .__name__ } " )
332
343
333
344
334
345
@pytest .mark .asyncio
335
- async def test_get_tokenizer_info_added_tokens_structure (server : RemoteOpenAIServer ):
346
+ async def test_get_tokenizer_info_added_tokens_structure (
347
+ server : RemoteOpenAIServer , ):
336
348
"""Test added_tokens_decoder structure if present."""
337
349
response = requests .get (server .url_for ("get_tokenizer_info" ))
338
350
response .raise_for_status ()
@@ -343,26 +355,33 @@ async def test_get_tokenizer_info_added_tokens_structure(server: RemoteOpenAISer
343
355
assert isinstance (token_id , str ), "Token IDs should be strings"
344
356
assert isinstance (token_info , dict ), "Token info should be a dict"
345
357
assert "content" in token_info , "Token info should have content"
346
- assert "special" in token_info , "Token info should have special flag"
347
- assert isinstance (token_info ["special" ], bool ), "Special flag should be boolean"
358
+ assert "special" in token_info , (
359
+ "Token info should have special flag" )
360
+ assert isinstance (token_info ["special" ],
361
+ bool ), ("Special flag should be boolean" )
348
362
349
363
350
364
@pytest .mark .asyncio
351
- async def test_get_tokenizer_info_consistency_with_tokenize (server : RemoteOpenAIServer ):
365
+ async def test_get_tokenizer_info_consistency_with_tokenize (
366
+ server : RemoteOpenAIServer , ):
352
367
"""Test that tokenizer info is consistent with tokenization endpoint."""
353
368
info_response = requests .get (server .url_for ("get_tokenizer_info" ))
354
369
info_response .raise_for_status ()
355
370
info = info_response .json ()
356
371
tokenize_response = requests .post (
357
372
server .url_for ("tokenize" ),
358
- json = {"model" : MODEL_NAME , "prompt" : "Hello world!" }
373
+ json = {
374
+ "model" : MODEL_NAME ,
375
+ "prompt" : "Hello world!"
376
+ },
359
377
)
360
378
tokenize_response .raise_for_status ()
361
379
tokenize_result = tokenize_response .json ()
362
380
info_max_len = info .get ("model_max_length" )
363
381
tokenize_max_len = tokenize_result .get ("max_model_len" )
364
382
if info_max_len and tokenize_max_len :
365
- assert info_max_len >= tokenize_max_len , "Info max length should be >= tokenize max length"
383
+ assert info_max_len >= tokenize_max_len , (
384
+ "Info max length should be >= tokenize max length" )
366
385
367
386
368
387
@pytest .mark .asyncio
@@ -373,5 +392,6 @@ async def test_get_tokenizer_info_chat_template(server: RemoteOpenAIServer):
373
392
result = response .json ()
374
393
chat_template = result .get ("chat_template" )
375
394
if chat_template :
376
- assert isinstance (chat_template , str ), "Chat template should be a string"
377
- assert chat_template .strip (), "Chat template should not be empty"
395
+ assert isinstance (chat_template ,
396
+ str ), ("Chat template should be a string" )
397
+ assert chat_template .strip (), "Chat template should not be empty"
0 commit comments