mirror of
https://github.com/langchain-ai/langserve.git
synced 2026-07-16 09:34:30 -04:00
Running background tasks #202
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Sara2823 on GitHub (Jun 27, 2024).
How to add a FastAPI BackgroundTask to a LangServe endpoint?
We need to save chat history to a database after each request, and not block the user input until the messages are saved.
This is how we add the endpoint to the app:
Thanks
@eyurtsev commented on GitHub (Jun 27, 2024):
Hi @Sara2823 you can use the
APIHandlerdirectly if you need fine grained control over the endpoint definition (e.g., to expose background tasks).@Sara2823 commented on GitHub (Jul 7, 2024):
Thanks @eyurtsev
This code works but I had to copy the whole streaming function to the route to put the insertion function(
insert_message) in the middle of the process. Is there a better solution I'm missing?