# How to create a multi-user chatbot with langchain

**URL:** <https://community.deeplearning.ai/t/how-to-create-a-multi-user-chatbot-with-langchain/350580>\
**Category:** LangChain for LLM Application Development\
**Tags:** langchain\
**Created:** [June 5, 2023, 2:12pm UTC](https://community.deeplearning.ai/t/how-to-create-a-multi-user-chatbot-with-langchain/350580 "2023-06-05T14:12:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SuryaKorivipadu](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@SuryaKorivipadu](https://community.deeplearning.ai/u/SuryaKorivipadu)\
**Post date:** [June 5, 2023, 2:12pm UTC](https://community.deeplearning.ai/t/how-to-create-a-multi-user-chatbot-with-langchain/350580/1 "2023-06-05T14:12:48Z")

</div>

Hi. Hope you are doing good. I’ve prepared a chatbot based on the below langchain documentation:  
[https://python.langchain.com/en/latest/modules/agents/agent\_executors/examples/chatgpt\_clone.html](https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/chatgpt_clone.html)  
In the above langchain documenation, the prompt template has two input variables - history and human input.

I’ve variables for UserID, SessionID. I’m storing UserID, SessionID, UserMessage, LLM-Response in a csv file. I used python pandas module to read the csv and filtered the data frame for given UserID and SessionID and prepared the chat-history for that specific user session. I’m passing this chat-history as the ‘history’ input to the langchain prompt template(which was discussed in the above link). As I set verbose=true, the langchain was printing the prompt template on the console for every API call. I’ve started the conversation for the first user and first session and sent 3 human\_inputs one by one. Later I started the second user session(now session ID and user ID are changed). After observing that prompt template on the console, I’ve observed that langchain is not only taking chat-history of second user session, it’s taking some of the chat-history from previous user session as well, even though I’ve written the correct code to prepare chat-history for the given user session. The code to get chat-history is below:

```auto
# get chat_history
def get_chat_history(user_id,session_id,user_query):
    chat_history = "You're a chatbot based on a large language model trained by OpenAI. The text followed by Human: will be user input and your response should be followed by AI: as shown below.\n"
    chat_data = pd.read_csv("DB.csv")
    for index in chat_data.index:
        if ((chat_data['user_id'][index] == user_id) and (chat_data['session_id'][index] == session_id)):
            chat_history += "Human: " + chat_data['user_query'][index] + "\n" + "AI: " + chat_data['gpt_response'][index] + "\n"
    chat_history += "Human: " + user_query + "\n" + "AI: "
    return chat_history

```

How to teach langchain to consider only the given user session chat-history in it’s prompt. Please help
