Skip to content

Commit 855b7bf

Browse files
committed
🚧 renamed endpoint from get_tokenizer_info to tokenizer_info and ran pre-commit
1 parent ade7167 commit 855b7bf

File tree

5 files changed

+239
-189
lines changed

5 files changed

+239
-189
lines changed

tests/entrypoints/openai/test_tokenization.py

Lines changed: 66 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def server(zephyr_lora_added_tokens_files: str): # noqa: F811
4141
@pytest.fixture(scope="module")
4242
def tokenizer_name(model_name: str,
4343
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)
4646

4747

4848
@pytest_asyncio.fixture
@@ -69,12 +69,14 @@ async def test_tokenize_completions(
6969
prompt = "vllm1 This is a test prompt."
7070
tokens = tokenizer.encode(prompt, add_special_tokens=add_special)
7171

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+
)
7880
response.raise_for_status()
7981

8082
result = response.json()
@@ -100,16 +102,20 @@ async def test_tokenize_chat(
100102

101103
for add_generation in [False, True]:
102104
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+
]
113119
for continue_final in [False, True]:
114120
if add_generation and continue_final:
115121
continue
@@ -123,20 +129,21 @@ async def test_tokenize_chat(
123129
add_generation_prompt=add_generation,
124130
continue_final_message=continue_final,
125131
conversation=conversation,
126-
tokenize=False)
132+
tokenize=False,
133+
)
127134
tokens = tokenizer.encode(prompt,
128135
add_special_tokens=add_special)
129136

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+
)
140147
response.raise_for_status()
141148

142149
result = response.json()
@@ -275,11 +282,13 @@ async def test_detokenize(
275282
prompt = "This is a test prompt. vllm1"
276283
tokens = tokenizer.encode(prompt, add_special_tokens=False)
277284

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+
)
283292
response.raise_for_status()
284293

285294
assert response.json() == {"prompt": prompt}
@@ -302,18 +311,18 @@ async def test_get_tokenizer_info_basic(
302311
result = response.json()
303312
assert "tokenizer_class" in result
304313
assert isinstance(result["tokenizer_class"], str)
305-
assert result["tokenizer_class"]
314+
assert result["tokenizer_class"]
306315

307316

308-
@pytest.mark.asyncio
317+
@pytest.mark.asyncio
309318
async def test_get_tokenizer_info_schema(server: RemoteOpenAIServer):
310319
"""Test that the response matches expected schema types."""
311320
response = requests.get(server.url_for("get_tokenizer_info"))
312321
response.raise_for_status()
313322
result = response.json()
314323
field_types = {
315324
"add_bos_token": bool,
316-
"add_prefix_space": bool,
325+
"add_prefix_space": bool,
317326
"clean_up_tokenization_spaces": bool,
318327
"split_special_tokens": bool,
319328
"bos_token": str,
@@ -328,11 +337,14 @@ async def test_get_tokenizer_info_schema(server: RemoteOpenAIServer):
328337
}
329338
for field, expected_type in field_types.items():
330339
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__}")
332343

333344

334345
@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, ):
336348
"""Test added_tokens_decoder structure if present."""
337349
response = requests.get(server.url_for("get_tokenizer_info"))
338350
response.raise_for_status()
@@ -343,26 +355,33 @@ async def test_get_tokenizer_info_added_tokens_structure(server: RemoteOpenAISer
343355
assert isinstance(token_id, str), "Token IDs should be strings"
344356
assert isinstance(token_info, dict), "Token info should be a dict"
345357
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")
348362

349363

350364
@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, ):
352367
"""Test that tokenizer info is consistent with tokenization endpoint."""
353368
info_response = requests.get(server.url_for("get_tokenizer_info"))
354369
info_response.raise_for_status()
355370
info = info_response.json()
356371
tokenize_response = requests.post(
357372
server.url_for("tokenize"),
358-
json={"model": MODEL_NAME, "prompt": "Hello world!"}
373+
json={
374+
"model": MODEL_NAME,
375+
"prompt": "Hello world!"
376+
},
359377
)
360378
tokenize_response.raise_for_status()
361379
tokenize_result = tokenize_response.json()
362380
info_max_len = info.get("model_max_length")
363381
tokenize_max_len = tokenize_result.get("max_model_len")
364382
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")
366385

367386

368387
@pytest.mark.asyncio
@@ -373,5 +392,6 @@ async def test_get_tokenizer_info_chat_template(server: RemoteOpenAIServer):
373392
result = response.json()
374393
chat_template = result.get("chat_template")
375394
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"

vllm/entrypoints/openai/api_server.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
ResponsesResponse, ScoreRequest,
7474
ScoreResponse, TokenizeRequest,
7575
TokenizeResponse,
76-
TokenizerInfoResponse,
7776
TranscriptionRequest,
7877
TranscriptionResponse,
7978
TranslationRequest,
@@ -527,15 +526,16 @@ async def detokenize(request: DetokenizeRequest, raw_request: Request):
527526
def maybe_register_tokenizer_info_endpoint(args):
528527
"""Conditionally register the tokenizer info endpoint if enabled."""
529528
if getattr(args, 'enable_tokenizer_info_endpoint', False):
530-
@router.get("/get_tokenizer_info")
529+
530+
@router.get("/tokenizer_info")
531531
async def get_tokenizer_info(raw_request: Request):
532532
"""Get comprehensive tokenizer information."""
533533
result = await tokenization(raw_request).get_tokenizer_info()
534-
return JSONResponse(
535-
content=result.model_dump(),
536-
status_code=result.code if isinstance(result, ErrorResponse) else 200)
537-
538-
534+
return JSONResponse(content=result.model_dump(),
535+
status_code=result.code if isinstance(
536+
result, ErrorResponse) else 200)
537+
538+
539539
@router.get("/v1/models")
540540
async def show_available_models(raw_request: Request):
541541
handler = models(raw_request)

vllm/entrypoints/openai/cli_args.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,8 @@ def make_arg_parser(parser: FlexibleArgumentParser) -> FlexibleArgumentParser:
299299
"--enable-tokenizer-info-endpoint",
300300
action='store_true',
301301
default=False,
302-
help="Enable the /get_tokenizer_info endpoint. May expose chat "
303-
"templates and other tokenizer configuration."
304-
)
302+
help="Enable the /tokenizer_info endpoint. May expose chat "
303+
"templates and other tokenizer configuration.")
305304

306305
return parser
307306

0 commit comments

Comments
 (0)