Issue:How can I resolve memory with conversation retreival chain error?
Labels: name: area: memory, name: auto:bug, name: integration: chroma

### Issue you'd like to raise.
below is my code
def generate_custom_prompt(query=None,name=None,not_uuid=None,chroma_db_path=None):  
    check = query.lower() 
    embedding = OpenAIEmbeddings()
    vectordb = Chroma(persist_directory=chroma_db_path, embedding_function=embedding)
    retriever = vectordb.as_retriever(search_kwargs={"k": 2})
    relevant_document = retriever.get_relevant_documents(query)
    print(relevant_document,"*****************************************")
    context_text="\n\n---\n\n".join([doc.page_content for doc in relevant_document])
    # print(context_text,"context_text")
    user_experience_inst = UserExperience.objects.get(not_uuid=not_uuid)
    greetings = ['hi', 'hello', 'hey', 'hui', 'hiiii', 'hii', 'hiii', 'heyyy']
    if check in greetings:
        custom_prompt_template = f"""
        Just simply reply with "Hello {name}! How can I assist you today?"
        """
    elif check not in greetings and user_experience_inst.custom_prompt:
        custom_prompt_template = f"""Answer the question based only on following context: ```{context_text} ```
        You are a chatbot designed to provide answers to User's Questions:```{check}```, delimited by triple backticks.
        Generate your answer to match the user's requirements: {user_experience_inst.custom_prompt}

        If you encounter a question for which you don't know the answer, please respond with 'I don't know' and refrain from making up an answer.
        - Before saying 'I don't know,' please re-verify your vector store to ensure the answer is not present in the database.

        Remember, your goal is to assist the user in the best way possible. If the question is unclear or ambiguous, feel free to ask for clarification.

        User's Question: ```{check}```
        AI Answer:"""
    else:
        
        # Create the custom prompt template
        custom_prompt_template = f"""Generate your response exclusively from the provided context: {{context_text}}. You function as a chatbot specializing in delivering detailed answers to the User's Question: ```{{check}} ```, enclosed within triple backticks.
            Generate your answer in points in the following format: {{chat_history}}
            1. Point no 1
                1.1 Its subpoint in details
                1.2 More information if needed.
            2. Point no 2
                2.1 Its subpoint in details
                2.2 More information if needed.
            …
            N. Another main point.

            If you encounter a question for which you don't know the answer based on the predefined points, please respond with 'I don't know' and refrain from making up an answer.
            However, if the answer is not present in the predefined points, then Provide comprehensive information related to the user's query.
            Remember, your goal is to assist the user in the best way possible. If the question is unclear or ambiguous, you can ask for clarification.

            User's Question: ```{{check}} ```  
            AI Answer:"""


    # Create the PromptTemplate
    custom_prompt = PromptTemplate(input_variables=["context_text","check","chat_history"],template=custom_prompt_template)
    formatted_prompt = custom_prompt.format(context_text=context_text, check=check)
    # QA_CHAIN_PROMPT = PromptTemplate(
    # input_variables=["context_text","check"],template=custom_prompt_template,)
    llm = ChatOpenAI(temperature=0.1)
    memory = ConversationBufferMemory(memory_key='chat_history', output_key='answer', return_messages=True) 
    # qa = ConversationalRetrievalChain.from_llm(llm=llm,memory=memory,chain_type="stuff",retriever=retriever,return_source_documents=True,get_chat_history=lambda h : h,verbose=True)
    qa = ConversationalRetrievalChain.from_llm(llm=llm,memory=memory,chain_type="stuff",retriever=retriever,return_source_documents=True,get_chat_history=lambda h : h,verbose=True, combine_docs_chain_kwargs={"prompt": custom_prompt})
    # prompt_qa={"qa": qa, "formatted_prompt": formatted_prompt}
    return qa
    
The error I am getting is:
  File "/usr/lib/python3.8/string.py", line 272, in get_field
    obj = self.get_value(first, args, kwargs)
  File "/usr/lib/python3.8/string.py", line 229, in get_value
    return kwargs[key]
KeyError: 'chat_history'
_No response_

### Suggestion:

_No response_