[Bugfix] Emit reasoning_part events in simple streaming path for Resp… (#35184)
Signed-off-by: Daniel Salib <danielsalib@meta.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import pytest_asyncio
|
|||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
|
|
||||||
from ....utils import RemoteOpenAIServer
|
from ....utils import RemoteOpenAIServer
|
||||||
|
from .conftest import validate_streaming_event_stack
|
||||||
|
|
||||||
MODEL_NAME = "Qwen/Qwen3-8B"
|
MODEL_NAME = "Qwen/Qwen3-8B"
|
||||||
|
|
||||||
@@ -219,3 +220,23 @@ async def test_extra_sampling_params(client: OpenAI, model_name: str):
|
|||||||
assert response.status in ["completed", "incomplete"]
|
assert response.status in ["completed", "incomplete"]
|
||||||
assert len(response.output) > 0
|
assert len(response.output) > 0
|
||||||
assert response.output[0].content[0].text # Has text output
|
assert response.output[0].content[0].text # Has text output
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@pytest.mark.parametrize("model_name", [MODEL_NAME])
|
||||||
|
async def test_streaming_types(
|
||||||
|
pairs_of_event_types: dict[str, str], client: OpenAI, model_name: str
|
||||||
|
):
|
||||||
|
stream = await client.responses.create(
|
||||||
|
model=model_name,
|
||||||
|
input="tell me a story about a cat in 20 words",
|
||||||
|
reasoning={"effort": "low"},
|
||||||
|
tools=[],
|
||||||
|
stream=True,
|
||||||
|
background=False,
|
||||||
|
)
|
||||||
|
events = []
|
||||||
|
async for event in stream:
|
||||||
|
events.append(event)
|
||||||
|
|
||||||
|
validate_streaming_event_stack(events, pairs_of_event_types)
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ from vllm.entrypoints.openai.responses.protocol import (
|
|||||||
ResponseCreatedEvent,
|
ResponseCreatedEvent,
|
||||||
ResponseInProgressEvent,
|
ResponseInProgressEvent,
|
||||||
ResponseInputOutputMessage,
|
ResponseInputOutputMessage,
|
||||||
|
ResponseReasoningPartAddedEvent,
|
||||||
|
ResponseReasoningPartDoneEvent,
|
||||||
ResponsesRequest,
|
ResponsesRequest,
|
||||||
ResponsesResponse,
|
ResponsesResponse,
|
||||||
ResponseUsage,
|
ResponseUsage,
|
||||||
@@ -1339,6 +1341,19 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
yield _increment_sequence_number_and_return(
|
||||||
|
ResponseReasoningPartAddedEvent(
|
||||||
|
type="response.reasoning_part.added",
|
||||||
|
sequence_number=-1,
|
||||||
|
output_index=current_output_index,
|
||||||
|
item_id=current_item_id,
|
||||||
|
content_index=current_content_index,
|
||||||
|
part=ResponseReasoningTextContent(
|
||||||
|
text="",
|
||||||
|
type="reasoning_text",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
yield _increment_sequence_number_and_return(
|
yield _increment_sequence_number_and_return(
|
||||||
ResponseOutputItemAddedEvent(
|
ResponseOutputItemAddedEvent(
|
||||||
@@ -1354,22 +1369,21 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
yield _increment_sequence_number_and_return(
|
yield _increment_sequence_number_and_return(
|
||||||
ResponseContentPartAddedEvent(
|
ResponseContentPartAddedEvent(
|
||||||
type="response.content_part.added",
|
type="response.content_part.added",
|
||||||
sequence_number=-1,
|
sequence_number=-1,
|
||||||
output_index=current_output_index,
|
output_index=current_output_index,
|
||||||
item_id=current_item_id,
|
item_id=current_item_id,
|
||||||
content_index=current_content_index,
|
content_index=current_content_index,
|
||||||
part=ResponseOutputText(
|
part=ResponseOutputText(
|
||||||
type="output_text",
|
type="output_text",
|
||||||
text="",
|
text="",
|
||||||
annotations=[],
|
annotations=[],
|
||||||
logprobs=[],
|
logprobs=[],
|
||||||
),
|
),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
current_content_index += 1
|
|
||||||
first_delta_sent = True
|
first_delta_sent = True
|
||||||
# todo(kebe7jun) tool call support
|
# todo(kebe7jun) tool call support
|
||||||
|
|
||||||
@@ -1397,6 +1411,19 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
text=reason_content,
|
text=reason_content,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
yield _increment_sequence_number_and_return(
|
||||||
|
ResponseReasoningPartDoneEvent(
|
||||||
|
type="response.reasoning_part.done",
|
||||||
|
sequence_number=-1,
|
||||||
|
item_id=current_item_id,
|
||||||
|
output_index=current_output_index,
|
||||||
|
content_index=current_content_index,
|
||||||
|
part=ResponseReasoningTextContent(
|
||||||
|
text=reason_content,
|
||||||
|
type="reasoning_text",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
current_content_index = 0
|
current_content_index = 0
|
||||||
reasoning_item = ResponseReasoningItem(
|
reasoning_item = ResponseReasoningItem(
|
||||||
type="reasoning",
|
type="reasoning",
|
||||||
@@ -1418,6 +1445,8 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
item=reasoning_item,
|
item=reasoning_item,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
current_output_index += 1
|
||||||
|
current_item_id = str(uuid.uuid4())
|
||||||
yield _increment_sequence_number_and_return(
|
yield _increment_sequence_number_and_return(
|
||||||
ResponseOutputItemAddedEvent(
|
ResponseOutputItemAddedEvent(
|
||||||
type="response.output_item.added",
|
type="response.output_item.added",
|
||||||
@@ -1432,8 +1461,6 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
current_output_index += 1
|
|
||||||
current_item_id = str(uuid.uuid4())
|
|
||||||
yield _increment_sequence_number_and_return(
|
yield _increment_sequence_number_and_return(
|
||||||
ResponseContentPartAddedEvent(
|
ResponseContentPartAddedEvent(
|
||||||
type="response.content_part.added",
|
type="response.content_part.added",
|
||||||
@@ -1449,7 +1476,6 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
current_content_index += 1
|
|
||||||
# reset previous delta messages
|
# reset previous delta messages
|
||||||
previous_delta_messages = []
|
previous_delta_messages = []
|
||||||
|
|
||||||
@@ -1485,7 +1511,6 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
current_content_index += 1
|
|
||||||
|
|
||||||
previous_delta_messages.append(delta_message)
|
previous_delta_messages.append(delta_message)
|
||||||
if previous_delta_messages:
|
if previous_delta_messages:
|
||||||
@@ -1505,7 +1530,19 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
text=reason_content,
|
text=reason_content,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
current_content_index += 1
|
yield _increment_sequence_number_and_return(
|
||||||
|
ResponseReasoningPartDoneEvent(
|
||||||
|
type="response.reasoning_part.done",
|
||||||
|
sequence_number=-1,
|
||||||
|
item_id=current_item_id,
|
||||||
|
output_index=current_output_index,
|
||||||
|
content_index=current_content_index,
|
||||||
|
part=ResponseReasoningTextContent(
|
||||||
|
text=reason_content,
|
||||||
|
type="reasoning_text",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
reasoning_item = ResponseReasoningItem(
|
reasoning_item = ResponseReasoningItem(
|
||||||
type="reasoning",
|
type="reasoning",
|
||||||
content=[
|
content=[
|
||||||
@@ -1543,7 +1580,6 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
item_id=current_item_id,
|
item_id=current_item_id,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
current_content_index += 1
|
|
||||||
part = ResponseOutputText(
|
part = ResponseOutputText(
|
||||||
text=final_content,
|
text=final_content,
|
||||||
type="output_text",
|
type="output_text",
|
||||||
@@ -1559,7 +1595,6 @@ class OpenAIServingResponses(OpenAIServing):
|
|||||||
part=part,
|
part=part,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
current_content_index += 1
|
|
||||||
item = ResponseOutputMessage(
|
item = ResponseOutputMessage(
|
||||||
type="message",
|
type="message",
|
||||||
role="assistant",
|
role="assistant",
|
||||||
|
|||||||
Reference in New Issue
Block a user