mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-27 20:38:32 +02:00
Cleaner stream handling in Answer class (#2314)
* add cleaner stream * add cleaner stream handling
This commit is contained in:
@@ -550,15 +550,21 @@ class Answer:
|
|||||||
answer_style_configs=self.answer_style_config,
|
answer_style_configs=self.answer_style_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _stream() -> Iterator[str | StreamStopInfo]:
|
stream_stop_info = None
|
||||||
yield cast(str | StreamStopInfo, message)
|
|
||||||
yield from (cast(str | StreamStopInfo, item) for item in stream)
|
|
||||||
|
|
||||||
for item in _stream():
|
def _stream() -> Iterator[str]:
|
||||||
if isinstance(item, StreamStopInfo):
|
nonlocal stream_stop_info
|
||||||
yield item
|
yield cast(str, message)
|
||||||
else:
|
for item in stream:
|
||||||
yield from process_answer_stream_fn(iter([item]))
|
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 = []
|
processed_stream = []
|
||||||
for processed_packet in _process_stream(output_generator):
|
for processed_packet in _process_stream(output_generator):
|
||||||
|
Reference in New Issue
Block a user