Enhance text stream processing by adding synchronization for interrupted assistant turns. Introduce sync_streamed_assistant_context to align LLM context with UI text, and modify ProductTextStreamProcessor to handle interrupted text. Update pipeline to utilize the new functionality for managing assistant turn interruptions.
This commit is contained in:
@@ -36,7 +36,7 @@ from .config import EngineConfig
|
||||
from .product_protocol import ProductWebsocketSerializer
|
||||
from .services import create_llm_service, create_stt_service, create_tts_service
|
||||
from .text_input import ProductTextInputProcessor
|
||||
from .text_stream import ProductTextStreamProcessor
|
||||
from .text_stream import ProductTextStreamProcessor, sync_streamed_assistant_context
|
||||
from .transcript_stream import ProductTranscriptStreamProcessor
|
||||
from .turn_start import InterruptionGateUserTurnStartStrategy
|
||||
|
||||
@@ -142,6 +142,8 @@ async def run_pipeline_with_serializer(
|
||||
),
|
||||
)
|
||||
|
||||
text_stream = ProductTextStreamProcessor()
|
||||
|
||||
pipeline = Pipeline(
|
||||
[
|
||||
transport.input(),
|
||||
@@ -150,7 +152,7 @@ async def run_pipeline_with_serializer(
|
||||
ProductTranscriptStreamProcessor(),
|
||||
user_aggregator,
|
||||
llm,
|
||||
ProductTextStreamProcessor(),
|
||||
text_stream,
|
||||
tts,
|
||||
transport.output(),
|
||||
assistant_aggregator,
|
||||
@@ -210,6 +212,14 @@ async def run_pipeline_with_serializer(
|
||||
@assistant_aggregator.event_handler("on_assistant_turn_stopped")
|
||||
async def on_assistant_turn_stopped(_aggregator, message: AssistantTurnStoppedMessage):
|
||||
logger.info(f"Assistant: {message.content}")
|
||||
if message.interrupted:
|
||||
streamed = text_stream.take_interrupted_stream_text()
|
||||
if streamed:
|
||||
sync_streamed_assistant_context(
|
||||
_aggregator,
|
||||
streamed_text=streamed,
|
||||
committed_text=message.content or "",
|
||||
)
|
||||
|
||||
runner = PipelineRunner(handle_sigint=False)
|
||||
await runner.run(task)
|
||||
|
||||
Reference in New Issue
Block a user