FrancescoCoding/easyGPT

How to separate context for each client?

Closed this issue · 8 comments

This tool is amazing! But when I use it into a Chatbot, I notice that the API does not distinguish requests from different clients (it acts like if all requests came from a single client - so the memory of the chat is shared between them). How to implement a different context (id) for each client so that each one has a different memory? I presume you shoud be a parameter (like context_id) in the ask() method. Is there any other way to solve this situation? Thank you!

Hi @fredcobain, could you please provide an example? if so that would be great and I will work on providing you a fix :)

Hi @AdamGovier , thank you for your reply.
The way I tested was like this:
step 1: Started the express-server on my machine
step 2: Opened a postman client on my machine and asked: Hi, my name is Fred - how are you?
step 3: Opened a insomnia client on another machine (another ip) to simulate another session/user and asked: do you know my name?

The result is that easygpt did not notice they are different sessions (or different users), so the response I get from the second client is: "yes, I remember. Your name is Fred."

In this scenario, I think each client should have its own context_id (or memory_id) like other chatbot solutions do (for example ibm watson).

Hi @fredcobain!

Thank you for bringing this to our attention and sharing the scenario with us. This server template is currently lacking a session management system, which is why it is not able to distinguish requests from different clients. While we are working on implementing this feature in the near future (EST. mid-May), we appreciate your suggestion of adding a parameter (such as context_id) in the ask() method.

If you would like to contribute to the project or happen to solve this issue before us, please feel free to send a pull request with your implementation!

One popular library for session management in Express is express-session. You can try using it as a workaround for now.

Thank you for using our tool and for your feedback! Let us know if you have any other questions or suggestions! 😎

Hi @FrancescoCoding, thank you for your attention to this. I do not feel skilled enough to contribute with a pull request but I can contribute with the theory behind on how it should work based on other conversational solutions (such as watson assistant). Let me explain in details what I'm thinking to solve this:

The Session ID is a unique identifier that should be generated from EasyGPT for each conversation session that you initiate. It is created when you send the first message to the assistant and is used to track the ongoing conversation.

The Session ID value allows the virtual assistant to maintain the context of the conversation (memory) during the interaction for each client. It is stored and can be used to retrieve the current state of the conversation at any time, even if the connection is interrupted or you leave and come back later.

For example, imagine that you are chatting with a virtual assistant to make a restaurant reservation. You can initiate the conversation and inform the assistant about your preferences, such as the type of food, the time, and the number of people. The Session ID will be generated when you send the first message to the assistant and all subsequent messages will be associated with that ID.

If you need to interrupt the conversation and come back later, the virtual assistant can retrieve the conversation state using the Session ID and continue the interaction where it left off. This is especially useful for more complex interactions, where it is necessary to maintain the context and continuity of the conversation over time for each client.

In our context, I presume we should generate a random unique session id when we call the ask() method. For the next calls, we should pass the generated session_id as a parameter ask(session_id) in order to tell the backend it is the same client.

What do you think, guys? @FrancescoCoding @AdamGovier

Hi @FrancescoCoding, any updates? =)

Hi @FrancescoCoding, any updates? =)

Hey @fredcobain! Me and @FrancescoCoding have been very busy with university & our full-time jobs, so apologies on the delay! Here is a possible fix: Branch(issue-15). The problem with the express-server is that it utilized the same easyGPT instance for every request. As suggested, I have now implemented a separate instance for each session. However, please note that this implementation was done hastily, so there may still be potential issues. The API will now store the conversation context on a per-session basis. It's worth mentioning that this can be easily modified, for instance, by having a header containing the context ID instead of relying on the session ID.

@FrancescoCoding I am going to create a pull request so if you could have a look over the code that will be great.

Thanks,
Adam.

Issue 15 branch is now merged to the master branch.

Working like a charm! Thank you, guys!