fix(providers): handle response.reasoning_text.* events in the SSE Responses consumer
(cherry picked from commit 87d3686a78530680ea04cb67210538967bcd9742)
This commit is contained in:
1 parent
49bdbb1a83
commit
3c866d63ac
2 files changed
+41
-1
No files matched your search
@@ -362,7 +362,7 @@ async def consume_sse_with_reasoning(
|
||||
on_response_event: Callable[[dict[str, Any]], Awaitable[None]] | None = None,
|
||||
capture: ResponsesStreamCapture | None = None,
|
||||
) -> tuple[str, list[ToolCallRequest], str, LLMUsage | None, str | None]:
|
||||
"""Consume a Responses API SSE stream, including visible reasoning summaries."""
|
||||
"""Consume a Responses API SSE stream, including reasoning text and summaries."""
|
||||
return await consume_responses_events(
|
||||
iter_sse(response),
|
||||
on_content_delta=on_content_delta,
|
||||
|
||||
@@ -1415,6 +1415,46 @@ class TestConsumeSse:
|
||||
|
||||
assert reasoning == "part summary"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reasoning_text_streamed(self):
|
||||
response = _SseResponse([
|
||||
{"type": "response.reasoning_text.delta", "delta": "step 1 "},
|
||||
{"type": "response.reasoning_text.delta", "delta": "step 2"},
|
||||
{"type": "response.reasoning_text.done", "text": "step 1 step 2"},
|
||||
{"type": "response.completed", "response": {"status": "completed", "output": []}},
|
||||
])
|
||||
deltas: list[str] = []
|
||||
|
||||
async def on_reasoning(delta: str) -> None:
|
||||
deltas.append(delta)
|
||||
|
||||
_, _, _, _, reasoning = await consume_sse_with_reasoning(
|
||||
response,
|
||||
on_reasoning_delta=on_reasoning,
|
||||
)
|
||||
|
||||
assert reasoning == "step 1 step 2"
|
||||
assert deltas == ["step 1 ", "step 2"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reasoning_text_done_without_deltas(self):
|
||||
response = _SseResponse([
|
||||
{"type": "response.reasoning_text.done", "text": "final reasoning"},
|
||||
{"type": "response.completed", "response": {"status": "completed", "output": []}},
|
||||
])
|
||||
deltas: list[str] = []
|
||||
|
||||
async def on_reasoning(delta: str) -> None:
|
||||
deltas.append(delta)
|
||||
|
||||
_, _, _, _, reasoning = await consume_sse_with_reasoning(
|
||||
response,
|
||||
on_reasoning_delta=on_reasoning,
|
||||
)
|
||||
|
||||
assert reasoning == "final reasoning"
|
||||
assert deltas == ["final reasoning"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_raw_sse_usage_extracted(self):
|
||||
response = _SseResponse([
|
||||
|
||||
Reference in new issue
Block a user