Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/entrypoints/openai/test_chat_echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,26 @@ async def test_prompt_logprobs(client: openai.AsyncOpenAI):

assert completion.prompt_logprobs is not None
assert len(completion.prompt_logprobs) > 0


@pytest.mark.asyncio
async def test_top_logprobs(client: openai.AsyncOpenAI):
messages = [{
"role": "system",
"content": "You are a helpful assistant."
}, {
"role": "user",
"content": "Beijing is the capital of which country?"
}]

completion = await client.chat.completions.create(
model=MODEL_NAME,
messages=messages,
extra_body={
"top_logprobs": -1,
"logprobs": "true",
},
)
assert completion.choices[0].logprobs is not None
assert completion.choices[0].logprobs.content is not None
assert len(completion.choices[0].logprobs.content) > 0
8 changes: 5 additions & 3 deletions vllm/entrypoints/openai/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,10 +863,12 @@ def check_logprobs(cls, data):
raise ValueError("`prompt_logprobs=-1` is only supported with "
"vLLM engine V1.")
if (top_logprobs := data.get("top_logprobs")) is not None:
if top_logprobs < 0:
raise ValueError("`top_logprobs` must be a positive value.")
if top_logprobs < 0 and top_logprobs != -1:
raise ValueError(
"`top_logprobs` must be a positive value or -1.")

if top_logprobs > 0 and not data.get("logprobs"):
if (top_logprobs == -1
or top_logprobs > 0) and not data.get("logprobs"):
raise ValueError(
"when using `top_logprobs`, `logprobs` must be set to true."
)
Expand Down