I'm currently implementing a Chatbot only in python.
In my current implementation, whenever the user starts a new conversation from one session, another instance of Chatbot is started and therefore, Chatbot starts from the initial state.
I want to change this behavior and make it similar to, say, chat on Facebook / Messenger, where you can move seamlessly between sessions while chatting without inconsistencies. Namely, I want these attributes:
- If the user enters something in session A, for example, it should be immediately visible in all current sessions. Likewise, the Chatbot response should be immediately visible on all devices.
- All sessions display the same discussion history
To implement the first point, I used this example django-channels documents and I modified it by creating a single group / chatroom for each user. All sessions of the same user are connected to the same group / chat room and therefore receive all messages from the group / chat room regardless of where they were sent.
However, this implementation currently has a bug. Whenever a user is logged in, he initializes a Chatbot instance that resumes from the initial state, while the old connections have Chatbot instances that are currently in a different state.
This leads to inconsistent responses that are different depending on the window in which the user has entered something.
Basically, instead of having two sessions that talk to the same Chatbot instance, we have two sessions that talk to two different Chatbot instances and the messages from these four sources are added to the same chat room.
In addition, we waste resources by keeping multiple Chatbot instances per user, which increases with the number of currently active sessions.
I want all user windows to interact with the same Chatbot instance. What would be the best way to implement this?
Currently, I can think of three solutions:
- Create another project Django the Chatbot and make requests to this HTTP server. The Chatbot state is kept on this server and any request from the user will go to the same Chatbot instance.
- It's easy to implement for me (just run another server)
- This naturally resolves all state problems because all instances will query the same Chatbot object.
- To create a Control The channel wire that will contain the current Chatbot instance (a python object) and all new channels will be returned to it for the chatbot response.
- It will be complicated to implement
- I will have to maintain which thread is master and which ones are slaves
- In situations where a user closes the master wire connection, I will have to one way or another change one of the slave connections into a master connection and transmit the entire object ( ?!) Or at least pass the state variable and recreate the chatbot instance.
- Create an independent thread / process in python for the chatbot instance and have all the channel connections communicate with that thread / process.
- It will be difficult for me to implement because I do not know how to make IPC Python
Are there other possible solutions? What would be the ideal solution?
I use the following technologies:
- Django as the main server, with Django channels for WebSockets
- RASA NLU for the chatbot NLU component and a finite state machine model implemented with pytransitions for the management of python dialogs