streaming #28892
Replies: 1 comment
-
To incorporate async def stream_to_websocket(llm, websocket, prompt):
async for chunk in llm.astream(prompt):
await websocket.send(chunk.content)
print(chunk.content, end="", flush=True) # Print each chunk immediately
yield chunk.content
# Usage example
# Assuming `websocket` is your WebSocket connection object
async for content in stream_to_websocket(llm, websocket, "write an essay on Sachin in 200 words"):
# Process each chunk as needed
pass In this code, To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
async def stream_to_websocket(llm, websocket, prompt):
async for chunk in llm.astream(prompt):
await websocket.send(chunk.content)
yield chunk.content
Usage example
Assuming
websocket
is your WebSocket connection objectasync for content in stream_to_websocket(llm, websocket, "write an essay on Sachin in 200 words"):
# Process each chunk as needed
pass
Beta Was this translation helpful? Give feedback.
All reactions