feat(stream): yield sources in stream

This commit is contained in:
ManishMadan2882
2024-09-21 01:50:02 +05:30
parent bf7cce52db
commit 59b6c56262

View File

@@ -221,7 +221,13 @@ def complete_stream(
"timestamp": datetime.datetime.now(datetime.timezone.utc),
}
)
sources = retriever.search()
for source in sources:
if("text" in source):
source["text"] = source["text"][:100].strip()+"..."
if(len(sources) > 0):
data = json.dumps({"type":"source","source":sources})
yield f"data: {data}\n\n"
data = json.dumps({"type": "end"})
yield f"data: {data}\n\n"
except Exception as e: