Skip to content

Commit bad718f

Browse files
committed
initial commit, should there be a ResponseReasoningPartAdded type?
Signed-off-by: Andrew Xia <axia@meta.com>
1 parent fedb75f commit bad718f

File tree

2 files changed

+88
-32
lines changed

2 files changed

+88
-32
lines changed

vllm/entrypoints/openai/protocol.py

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
ResponseReasoningTextDeltaEvent, ResponseReasoningTextDoneEvent,
3232
ResponseStatus, ResponseWebSearchCallCompletedEvent,
3333
ResponseWebSearchCallInProgressEvent, ResponseWebSearchCallSearchingEvent)
34+
from openai.types.responses.response_reasoning_item import (
35+
Content as ResponseReasoningTextContent)
3436

3537
# Backward compatibility for OpenAI client versions
3638
try: # For older openai versions (< 1.100.0)
@@ -260,26 +262,6 @@ def get_logits_processors(processors: Optional[LogitsProcessors],
260262
ResponseReasoningItem,
261263
ResponseFunctionToolCall]
262264

263-
StreamingResponsesResponse: TypeAlias = Union[
264-
ResponseCreatedEvent,
265-
ResponseInProgressEvent,
266-
ResponseCompletedEvent,
267-
ResponseOutputItemAddedEvent,
268-
ResponseOutputItemDoneEvent,
269-
ResponseContentPartAddedEvent,
270-
ResponseContentPartDoneEvent,
271-
ResponseReasoningTextDeltaEvent,
272-
ResponseReasoningTextDoneEvent,
273-
ResponseCodeInterpreterCallInProgressEvent,
274-
ResponseCodeInterpreterCallCodeDeltaEvent,
275-
ResponseWebSearchCallInProgressEvent,
276-
ResponseWebSearchCallSearchingEvent,
277-
ResponseWebSearchCallCompletedEvent,
278-
ResponseCodeInterpreterCallCodeDoneEvent,
279-
ResponseCodeInterpreterCallInterpretingEvent,
280-
ResponseCodeInterpreterCallCompletedEvent,
281-
]
282-
283265

284266
class ResponsesRequest(OpenAIBaseModel):
285267
# Ordered by official OpenAI API documentation
@@ -1978,6 +1960,72 @@ def from_request(
19781960
)
19791961

19801962

1963+
# TODO: this code can be removed once
1964+
# https://github.com/openai/openai-python/issues/2634 has been resolved
1965+
class ResponseReasoningPartDoneEvent(OpenAIBaseModel):
1966+
content_index: int
1967+
"""The index of the content part that is done."""
1968+
1969+
item_id: str
1970+
"""The ID of the output item that the content part was added to."""
1971+
1972+
output_index: int
1973+
"""The index of the output item that the content part was added to."""
1974+
1975+
part: ResponseReasoningTextContent
1976+
"""The content part that is done."""
1977+
1978+
sequence_number: int
1979+
"""The sequence number of this event."""
1980+
1981+
type: Literal["response.reasoning_part.done"]
1982+
"""The type of the event. Always `response.reasoning_part.done`."""
1983+
1984+
1985+
# TODO: this code can be removed once
1986+
# https://github.com/openai/openai-python/issues/2634 has been resolved
1987+
class ResponseReasoningPartAddedEvent(OpenAIBaseModel):
1988+
content_index: int
1989+
"""The index of the content part that is done."""
1990+
1991+
item_id: str
1992+
"""The ID of the output item that the content part was added to."""
1993+
1994+
output_index: int
1995+
"""The index of the output item that the content part was added to."""
1996+
1997+
part: ResponseReasoningTextContent
1998+
"""The content part that is done."""
1999+
2000+
sequence_number: int
2001+
"""The sequence number of this event."""
2002+
2003+
type: Literal["response.reasoning_part.added"]
2004+
"""The type of the event. Always `response.reasoning_part.added`."""
2005+
2006+
2007+
StreamingResponsesResponse: TypeAlias = Union[
2008+
ResponseCreatedEvent,
2009+
ResponseInProgressEvent,
2010+
ResponseCompletedEvent,
2011+
ResponseOutputItemAddedEvent,
2012+
ResponseOutputItemDoneEvent,
2013+
ResponseContentPartAddedEvent,
2014+
ResponseContentPartDoneEvent,
2015+
ResponseReasoningTextDeltaEvent,
2016+
ResponseReasoningTextDoneEvent,
2017+
ResponseReasoningPartAddedEvent,
2018+
ResponseReasoningPartDoneEvent,
2019+
ResponseCodeInterpreterCallInProgressEvent,
2020+
ResponseCodeInterpreterCallCodeDeltaEvent,
2021+
ResponseWebSearchCallInProgressEvent,
2022+
ResponseWebSearchCallSearchingEvent,
2023+
ResponseWebSearchCallCompletedEvent,
2024+
ResponseCodeInterpreterCallCodeDoneEvent,
2025+
ResponseCodeInterpreterCallInterpretingEvent,
2026+
ResponseCodeInterpreterCallCompletedEvent,
2027+
]
2028+
19812029
BatchRequestInputBody = Union[ChatCompletionRequest, EmbeddingRequest,
19822030
ScoreRequest, RerankRequest]
19832031

vllm/entrypoints/openai/serving_responses.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
InputTokensDetails,
5959
OutputTokensDetails,
6060
RequestResponseMetadata,
61+
ResponseReasoningPartAddedEvent,
62+
ResponseReasoningPartDoneEvent,
6163
ResponsesRequest,
6264
ResponsesResponse, ResponseUsage,
6365
StreamingResponsesResponse)
@@ -1280,14 +1282,13 @@ async def _process_harmony_streaming_events(
12801282
# Deal with tool call here
12811283
pass
12821284
elif previous_item.channel == "analysis":
1285+
content = ResponseReasoningTextContent(
1286+
text=previous_item.content[0].text,
1287+
type="reasoning_text",
1288+
)
12831289
reasoning_item = ResponseReasoningItem(
12841290
type="reasoning",
1285-
content=[
1286-
ResponseReasoningTextContent(
1287-
text=previous_item.content[0].text,
1288-
type="reasoning_text",
1289-
),
1290-
],
1291+
content=[content],
12911292
status="completed",
12921293
id=current_item_id,
12931294
summary=[],
@@ -1301,6 +1302,15 @@ async def _process_harmony_streaming_events(
13011302
content_index=current_content_index,
13021303
text=previous_item.content[0].text,
13031304
))
1305+
yield _increment_sequence_number_and_return(
1306+
ResponseReasoningPartDoneEvent(
1307+
type="response.reasoning_part.done",
1308+
sequence_number=-1,
1309+
item_id=current_item_id,
1310+
output_index=current_output_index,
1311+
content_index=current_content_index,
1312+
part=content,
1313+
))
13041314
yield _increment_sequence_number_and_return(
13051315
ResponseOutputItemDoneEvent(
13061316
type="response.output_item.done",
@@ -1412,17 +1422,15 @@ async def _process_harmony_streaming_events(
14121422
))
14131423
current_content_index += 1
14141424
yield _increment_sequence_number_and_return(
1415-
ResponseContentPartAddedEvent(
1416-
type="response.content_part.added",
1425+
ResponseReasoningPartAddedEvent(
1426+
type="response.reasoning_part.added",
14171427
sequence_number=-1,
14181428
output_index=current_output_index,
14191429
item_id=current_item_id,
14201430
content_index=current_content_index,
1421-
part=ResponseOutputText(
1422-
type="output_text",
1431+
part=ResponseReasoningTextContent(
14231432
text="",
1424-
annotations=[],
1425-
logprobs=[],
1433+
type="reasoning_text",
14261434
),
14271435
))
14281436
yield _increment_sequence_number_and_return(

0 commit comments

Comments
 (0)