You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(hooks): add BeforeStreamChunkEvent for true stream chunk interception
Add BeforeStreamChunkEvent hook that fires BEFORE each stream chunk is
processed, enabling true interception capabilities:
- Monitor streaming progress in real-time
- Modify chunk content before processing (affects final message)
- Skip chunks entirely by setting skip=True (excluded from final message)
- Implement content transformation (e.g., redaction, translation)
Implementation details:
- Added ChunkInterceptor callback type to streaming.py
- Modified process_stream() to invoke interceptor BEFORE processing
- Modified stream_messages() to accept chunk_interceptor parameter
- event_loop.py creates interceptor that invokes BeforeStreamChunkEvent
When skip=True:
- The chunk is not processed at all
- No events (ModelStreamChunkEvent, TextStreamEvent) are yielded
- The chunk does not contribute to the final message
When chunk is modified:
- The modified chunk is used for all downstream processing
- TextStreamEvent will contain the modified text
- The final message will contain the modified content
0 commit comments