[Fix] Emit Responses reasoning content-part events (#41789)
Co-authored-by: ai-jz <ai-jz@users.noreply.github.com> Co-authored-by: Yuwei An <ayw.sirius19@gmail.com> Co-authored-by: Xinyuan Tong <xinyuantong.cs@gmail.com> Co-authored-by: Xinyuan Tong <115166877+JustinTong0323@users.noreply.github.com>
This commit is contained in:
co-authored by
ai-jz
Yuwei An
Xinyuan Tong
Xinyuan Tong
parent
99c59a2ea6
commit
ebdeba2fee
@@ -21,6 +21,12 @@ from openai.types.responses import (
|
||||
ResponseOutputText,
|
||||
ResponseReasoningItem,
|
||||
)
|
||||
from openai.types.responses.response_content_part_added_event import (
|
||||
PartReasoningText as ResponseReasoningTextAddedPart,
|
||||
)
|
||||
from openai.types.responses.response_content_part_done_event import (
|
||||
PartReasoningText as ResponseReasoningTextDonePart,
|
||||
)
|
||||
from openai.types.responses.response_custom_tool_call import ResponseCustomToolCall
|
||||
from openai.types.responses.response_function_tool_call import ResponseFunctionToolCall
|
||||
from openai.types.responses.response_output_text import Logprob, LogprobTopLogprob
|
||||
@@ -2130,6 +2136,20 @@ class OpenAIServingResponses(OpenAIServingChat):
|
||||
)
|
||||
)
|
||||
)
|
||||
events.append(
|
||||
_send_event(
|
||||
openai_responses_types.ResponseContentPartDoneEvent(
|
||||
type="response.content_part.done",
|
||||
item_id=reasoning_state["item_id"],
|
||||
sequence_number=-1,
|
||||
output_index=reasoning_state["output_index"],
|
||||
content_index=0,
|
||||
part=ResponseReasoningTextDonePart(
|
||||
type="reasoning_text", text=text
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
events += [
|
||||
_send_event(
|
||||
openai_responses_types.ResponseOutputItemDoneEvent(
|
||||
@@ -2367,6 +2387,19 @@ class OpenAIServingResponses(OpenAIServingChat):
|
||||
sequence_number=-1,
|
||||
)
|
||||
)
|
||||
else:
|
||||
yield _send_event(
|
||||
openai_responses_types.ResponseContentPartAddedEvent(
|
||||
type="response.content_part.added",
|
||||
item_id=item_id,
|
||||
output_index=reasoning_state["output_index"],
|
||||
content_index=0,
|
||||
part=ResponseReasoningTextAddedPart(
|
||||
type="reasoning_text", text=""
|
||||
),
|
||||
sequence_number=-1,
|
||||
)
|
||||
)
|
||||
reasoning_state["text"] += reasoning_chunk
|
||||
if wants_summary:
|
||||
yield _send_event(
|
||||
|
||||
Reference in New Issue
Block a user