Prompt invalid with ConversationalRetrievalChain
Labels: name: auto:bug, name: auto:question, name: area: models, name: integration: chroma

I am trying to use a prompt with my chain but I am getting an error which I'm not sure how to solve. Also, I was wondering is it possible to use a constitutional principle to apply it to the ConversationalRetrievalChain? If so, can someone guide me on how to do so? Sorry for beginner questions but I am new to all of this including coding. Thanks in advance!

Code:
from dotenv import load_dotenv
import csv
import PyPDF2
from PyPDF2 import PdfReader
from langchain.document_loaders import DirectoryLoader, PyPDFLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.callbacks import get_openai_callback
from langchain.chat_models import ChatOpenAI
from langchain.chains import ConversationalRetrievalChain
from langchain.memory import ConversationBufferMemory
from langchain.prompts import PromptTemplate
import time
from langchain.chains.qa_with_sources import load_qa_with_sources_chain
from langchain.vectorstores import Chroma
from langchain.callbacks import StreamingStdOutCallbackHandler
import pandas as pd
from docx import Document
from nltk.tokenize import sent_tokenize, word_tokenize
from collections import Counter
from nltk.corpus import stopwords
import os

def print_letter_by_letter(text):
    for char in text:
        print(char, end='', flush=True)
        time.sleep(0.02)

def main():
    load_dotenv()
    # directory_path = input("Copy your directory path here or upload a file: ")
    directory_path = "C:\\Users\\Asus\\OneDrive\\Documents\\Vendolista"

    pdf_loader = DirectoryLoader(directory_path,
                                  glob="**/*.pdf",
                                  show_progress=True,
                                  use_multithreading=True,
                                  silent_errors=True,
                                  loader_cls = PyPDFLoader)

    documents = pdf_loader.load()
    print(str(len(documents))+ " documents loaded")

    llm = ChatOpenAI(temperature = 0, model_name='gpt-3.5-turbo', callbacks=[StreamingStdOutCallbackHandler()], streaming = True)


    # Split into chunks
    text_splitter = RecursiveCharacterTextSplitter(
        chunk_size=1000,
        chunk_overlap=200,
    )
    chunks = text_splitter.split_documents(documents)
    
    
    embeddings = OpenAIEmbeddings()
    persist_directory = "C:\\Users\\Asus\\OneDrive\\Documents\\Vendolista"
    knowledge_base = Chroma.from_documents(chunks, embeddings, persist_directory = persist_directory)
    #save to disk
    knowledge_base.persist() 
    #To delete the DB we created at first so that we can be sure that we will load from disk as fresh db
    knowledge_base = None
    new_knowledge_base = Chroma(persist_directory = persist_directory, embedding_function = embeddings)

    custom_template = ("""
    Help the users with answering questions based on the document.
    """
    )

    # prompt = PromptTemplate(input_variables=[], template=custom_template)
    prompt = PromptTemplate.from_template(custom_template)

    memory = ConversationBufferMemory(memory_key = "chat_history", return_messages = True)
    model = ConversationalRetrievalChain.from_llm(llm = llm,
                                                   chain_type = "refine",
                                                   retriever = new_knowledge_base.as_retriever(),
                                                   memory = memory,
                                                   combine_docs_chain_kwargs = {"prompt":prompt}
                                                   )


    while True:
        question = input("Ask me anything about the files (type 'exit' to quit): ")

        if question.lower() in ["exit"] and len(question) == 4:
            end_chat = "Thank you for visiting us! Have a nice day"
            print_letter_by_letter(end_chat)
            break

        if question:

            chat_history = []
            # with get_openai_callback() as cb:
            response = model({"question": question}, return_only_outputs = True)

            chat_history.append(('user', question))
            chat_history.append(('AI', response))
            print("AI:", response)

if __name__ == '__main__':
    main()

Error:

86 documents loaded
Traceback (most recent call last):
  File "C:\Users\Asus\Documents\Vendolista\app.py", line 100, in <module>
    main()
  File "C:\Users\Asus\Documents\Vendolista\app.py", line 73, in main
    model = ConversationalRetrievalChain.from_llm(llm = llm,
  File "C:\Users\Asus\AppData\Local\Programs\Python\Python310\lib\site-packages\langchain\chains\conversational_retrieval\base.py", line 341, in from_llm
    doc_chain = load_qa_chain(
  File "C:\Users\Asus\AppData\Local\Programs\Python\Python310\lib\site-packages\langchain\chains\question_answering\__init__.py", line 249, in load_qa_chain
    return loader_mapping[chain_type](
  File "C:\Users\Asus\AppData\Local\Programs\Python\Python310\lib\site-packages\langchain\chains\question_answering\__init__.py", line 206, in _load_refine_chain
    return RefineDocumentsChain(
  File "C:\Users\Asus\AppData\Local\Programs\Python\Python310\lib\site-packages\langchain\load\serializable.py", line 97, in __init__
    super().__init__(**kwargs)
  File "pydantic\main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for RefineDocumentsChain
prompt
  extra fields not permitted (type=value_error.extra)