streaming response #28925
-
async def stream_to_websocket(prompt:str):
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I found two similar unsolved discussions that might be relevant to your question:
To integrate your from fastapi import FastAPI, WebSocket
from langchain import LLM # Assuming LLM is the class you're using
app = FastAPI()
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
prompt = "Your prompt here" # You can modify this to receive from the client
async for chunk in llm.astream(prompt):
await websocket.send_text(chunk.content) In this setup, the WebSocket connection is established at the 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.
I found two similar unsolved discussions that might be relevant to your question:
To integrate your
stream_to_websocket
function with FastAPI WebSockets, you can use FastAPI's WebSocket support. Here's a basic example of how you might set this up: