mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-07-04 06:29:22 +00:00
feat: enhance streaming support in conversational flow
- Introduced function to determine if a result is a streaming output. - Added method to handle streaming results before accessing them. - Updated method to utilize the new streaming result handling. - Implemented context management for LLM streaming in the conversational mixin. - Added tests to verify streaming behavior and ensure proper handling of user messages during streaming.
This commit is contained in:
@@ -24,6 +24,7 @@ from crewai.events.types.tool_usage_events import (
|
||||
ToolUsageFinishedEvent,
|
||||
ToolUsageStartedEvent,
|
||||
)
|
||||
from crewai.types.streaming import FlowStreamingOutput, StreamChunk
|
||||
from crewai_cli.command import AuthenticationRequiredError
|
||||
from crewai_cli import run_crew
|
||||
from crewai_cli.crew_run_tui import (
|
||||
@@ -144,6 +145,29 @@ def test_conversation_turn_done_records_assistant_message() -> None:
|
||||
assert isinstance(app._crew_result, RawResult)
|
||||
|
||||
|
||||
def test_conversation_streaming_result_is_consumed_before_result_access() -> None:
|
||||
streaming = FlowStreamingOutput()
|
||||
result_accessed_before_completion = False
|
||||
|
||||
def chunks():
|
||||
yield StreamChunk(content="hello ")
|
||||
yield StreamChunk(content="world")
|
||||
streaming._set_result("hello world")
|
||||
|
||||
streaming._sync_iterator = chunks()
|
||||
|
||||
try:
|
||||
streaming.result
|
||||
except RuntimeError:
|
||||
result_accessed_before_completion = True
|
||||
|
||||
app = CrewRunApp(conversational=True)
|
||||
|
||||
assert result_accessed_before_completion is True
|
||||
assert app._consume_conversation_streaming_result(streaming) == "hello world"
|
||||
assert streaming.get_full_text() == "hello world"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_conversation_input_submits_turn() -> None:
|
||||
class FakeFlow:
|
||||
|
||||
Reference in New Issue
Block a user