lekkalar commited on
Commit
fe13a0d
1 Parent(s): c7fe620

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -49,12 +49,12 @@ def load_pdf_and_generate_embeddings(pdf_doc, open_ai_key, relevant_pages):
49
  #Finally, we create the bot using the RetrievalQA class
50
  global pdf_qa
51
 
52
- prompt_template = """Use the following pieces of context to answer the question at the end. If you do not know the answer, just return N/A. If you encounter a date, return it in mm/dd/yyyy format.
53
-
54
  {context}
55
-
56
  Question: {question}
57
- Return just the answer. Provide the answer in the JSON format and extract the key from the question :"""
 
58
  PROMPT = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
59
  chain_type_kwargs = {"prompt": PROMPT}
60
  pdf_qa = RetrievalQA.from_chain_type(llm=ChatOpenAI(temperature=0, model_name="gpt-4"),chain_type="stuff", retriever=vectordb.as_retriever(search_kwargs={"k": 5}), chain_type_kwargs=chain_type_kwargs, return_source_documents=False)
 
49
  #Finally, we create the bot using the RetrievalQA class
50
  global pdf_qa
51
 
52
+ #Configuring the Prompt Template is the key to getting the desired response in the desired format.
53
+ prompt_template = """Use the following pieces of context to answer the question at the end. If you do not know the answer, just return N/A. If you encounter a date, return it in mm/dd/yyyy format. If there is a Preface section in the document, extract the chapter# and the short description from the Preface. Chapter numbers are listed to the left in Preface and always start with an alphabet, for example A1-1
54
  {context}
 
55
  Question: {question}
56
+ Return the answer. Provide the answer in the JSON format and extract the key from the question. Where applicable, break the answer into bullet points. When the sentences are long, try and break them into sub sections and include all the information and do not skip any information. If there is an exception to the answer, please do include it in a 'Note:' section. If there are no exceptions to the answer, please skip the 'Note:' section. Include a 'For additional details refer to' section when the document has more information to offer on the topic being questioned. If the document has a Preface or 'Table of Contents' section, extract the chapter# and a short description and include the info under the 'For additional details refer to' section. List only the chapters that contain information or skip this section altogether. Do not use page numbers as chapter numbers as they are different. If additional information is found in multiple pages within the same chapter, list the chapter only once. If chapter information cannot be extracted, include any other information that will help the user navigate to the relevant sections of the document. If the document does not contain a Preface or 'Table of Contents' section, please do not call that out. For example, do not include statements like the following in the answer - 'The document does not contain a Preface or 'Table of Contents' section'"""
57
+
58
  PROMPT = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
59
  chain_type_kwargs = {"prompt": PROMPT}
60
  pdf_qa = RetrievalQA.from_chain_type(llm=ChatOpenAI(temperature=0, model_name="gpt-4"),chain_type="stuff", retriever=vectordb.as_retriever(search_kwargs={"k": 5}), chain_type_kwargs=chain_type_kwargs, return_source_documents=False)