for a chatbot i am using fastapi and react on the front end. to generate and response i am using the "get" route. but for the frontend implementation i would require a websocket for the chat function. As i am super new with fastapi, i am really confused and stuck with this. please help.
I'm going to build a similar application in a few days (fastAPI + React) but I have a question why do you need a websocket and you are using GET instead of POST ?
So you are currently using a get request with the client message to generate a response, and you want to replace that with a websocket?
Your websocket_endpoint seems odd, what's the deal with the global dataFromFront? I assume you want to use just one instance of your bot but I don't see a reason why you need the variables declared as global. What is you issue? Hard to help when I would just need to guess what the problem is.
When I made realtime notifications for my app I used broadcaster as I had multiple threads running, users communicating with eachother, server pushing messages, and message history. The PyPI page has an example. It might be helpful for async message processing and to easily push messages to the client.
If all the bot does is respond to a message then I see no need for websockets, but those global's are very odd and hopefully unnecessary.
2
u/Impressive_Essay927 Oct 27 '22
for a chatbot i am using fastapi and react on the front end. to generate and response i am using the "get" route. but for the frontend implementation i would require a websocket for the chat function. As i am super new with fastapi, i am really confused and stuck with this. please help.