Compare commits

...

1 Commits

Author SHA1 Message Date
pablodanswer
f1381cc55a Cleaner stream handling in Answer class (#2314)
* add cleaner stream

* add cleaner stream handling
2024-09-03 11:54:08 -07:00

View File

@@ -543,15 +543,21 @@ class Answer:
answer_style_configs=self.answer_style_config,
)
def _stream() -> Iterator[str | StreamStopInfo]:
yield cast(str | StreamStopInfo, message)
yield from (cast(str | StreamStopInfo, item) for item in stream)
stream_stop_info = None
for item in _stream():
if isinstance(item, StreamStopInfo):
yield item
else:
yield from process_answer_stream_fn(iter([item]))
def _stream() -> Iterator[str]:
nonlocal stream_stop_info
yield cast(str, message)
for item in stream:
if isinstance(item, StreamStopInfo):
stream_stop_info = item
return
yield cast(str, item)
yield from process_answer_stream_fn(_stream())
if stream_stop_info:
yield stream_stop_info
processed_stream = []
for processed_packet in _process_stream(output_generator):