[Frontend] Make finish_reason and Responses item status truthful (#59324)

Signed-off-by: Flora Feng <4florafeng@gmail.com>
Signed-off-by: sfeng33 <4florafeng@gmail.com>
Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
This commit is contained in:
Flora Feng
2026-10-15 10:12:02 +01:00
committed by GitHub
co-authored by Chauncey
parent 427915bed2
commit 80dd705c1d
14 changed files with 421 additions and 62 deletions
@@ -4,6 +4,7 @@ from typing import TypeVar
from vllm.entrypoints.generate.base.protocol import DeltaMessage, FunctionCall
from vllm.entrypoints.openai.chat_completion.protocol import (
ChatCompletionNamedToolChoiceParam,
ChatCompletionRequest,
ChatCompletionResponseChoice,
ChatCompletionResponseStreamChoice,
@@ -41,3 +42,24 @@ def maybe_filter_parallel_tool_calls(
tool_call for tool_call in delta.tool_calls if tool_call.index == 0
]
return item
def resolve_finish_reason(
engine_finish_reason: str | None,
request: ChatCompletionRequest | None,
tool_calls_made: bool,
) -> str:
"""Map the engine finish reason to the OpenAI chat ``finish_reason``.
``tool_calls`` is reported only when the choice actually carries tool
calls, the engine stopped on its own (a ``length`` cut stays visible so
clients can tell a truncated call from a complete one) and the caller did
not force a single named tool, for which OpenAI reports ``stop``.
"""
finish_reason = engine_finish_reason or "stop"
forced_named_tool = request is not None and isinstance(
request.tool_choice, ChatCompletionNamedToolChoiceParam
)
if tool_calls_made and finish_reason == "stop" and not forced_named_tool:
return "tool_calls"
return finish_reason