I asked ChatGPT what might cause the issue and here is the answer:
The BaseLangchainStreamingResponse class uses the async and await keywords to execute asynchronous code. When you use asynchronous programming, multiple coroutines can execute concurrently, meaning that different parts of your application may execute simultaneously. This can lead to race conditions where different coroutines try to modify the same data at the same time.
In this case, it is possible that multiple coroutines are trying to send response messages concurrently, which can cause the 'Unexpected ASGI message' error message to appear. To fix this issue, you can try synchronizing access to the send function by using a lock.
I asked ChatGPT what might cause the issue and here is the answer:
Fixes ajndkr/fastapi-async-langchain#17