How to change from astream to astream_events #25655
Unanswered
levalencia
asked this question in
Q&A
Replies: 1 comment 4 replies
-
To change your code from using Original code using async for chunk in accumulate_and_yield(conversational_rag_chain.astream_({"input": prompt}, config={"configurable": {"session_id": "unbound"}})):
yield chunk Modified code using events = []
async for event in accumulate_and_yield(conversational_rag_chain.astream_events({"input": prompt}, config={"configurable": {"session_id": "unbound"}}, version="v2")):
events.append(event)
kind = event["event"]
if kind == "on_chat_model_stream":
yield f"Chat model chunk: {repr(event['data']['chunk'].content)}".encode()
if kind == "on_parser_stream":
yield f"Parser chunk: {event['data']['chunk']}".encode() This modification will allow you to stream results from intermediate steps using SSE. Note that if you are running Python <= 3.10, you may need to manually propagate the |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I want to use SSE instead of streaming, how can I change my code from astream to astream_events
System Info
Beta Was this translation helpful? Give feedback.
All reactions