Find answers from the community

Updated 4 months ago

I have a pretty simple use case where I'

I have a pretty simple use case where I'm trying to stream back results with FastAPI. When I log the token over the response iterator, I see each token being logged in the console, but I'm not seeing the streamed results. Anyone see an issue I'm missing?
Plain Text
async def response_streamer(response):
    for token in response:
        logger.info(token)
        yield f"{token}"

class ChatInput(BaseModel):
    query_text: str

@app.post("/chat")
async def query_index(chat_input: ChatInput):
    global index

    chat_engine = index.as_chat_engine(
        chat_mode="condense_question",
        verbose=True,
        llm=Settings.llm,
    )

    streaming_response = chat_engine.stream_chat(chat_input.query_text)
    return StreamingResponse(
        response_streamer(streaming_response.response_gen),
        media_type="text/event-stream",
        status_code=200,
    )
O
W
3 comments
If it helps, the StreamingResponse is from fastapi. I know there's one for llama index too, but StackOverflow suggested I should use the one from fastapi
I tried that. It didn't cause post man to produce an event per token
Add a reply
Sign up and join the conversation on Discord