Find answers from the community

Updated 2 months ago

Hi I ve been trying to stream into my

Hi! I've been trying to stream into my front end (Javascript) but having no joy. I can get the streaming to work to the console but can't figure out how to stream the text to the front end. Any help is much appreciated!
a
1 comment
I have used the following and it worked with flask backend and react front end:


Plain Text
from flask import Response

def generate_response_stream(response_gen):
    """Yield the response stream."""
    for text in response_gen:
        yield text

@app.route('/query', methods=['POST'])
def process_query():
    data = request.get_json()
    user_query = data['query']
    response = query_engine.query(user_query)
    return Response(generate_response_stream(response.response_gen), mimetype='text/plain')
Add a reply
Sign up and join the conversation on Discord