ryan0303 commited on
Commit
a87f8dd
1 Parent(s): 8848339

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -149,15 +149,27 @@ def initialize_llmchain(llm_model, temperature, max_tokens, top_k, vector_db, pr
149
  retriever=vector_db.as_retriever()
150
  progress(0.8, desc="Defining retrieval chain...")
151
 
152
- prompt_template_string = f'''Your task is as follows: 1. Determine if the input is compliant with the provided context. 2. If the requirement is compliant, report "This requirement is compliant." 3. If the requirement is not compliant report "This requirement is not compliant." 4. If the requirement is not compliant, give the reason for non compliance and return the specific rule or guideline the requirement violates. 5. If the requirement is not compliant, report a refined version of the requirement delimited in quotes that is compliant with the provided context.'''
153
 
154
  # Create a PromptTemplate object
155
- prompt_template = PromptTemplate(
156
- template=prompt_template_string,
157
- input_variables=["user_question","context"]
158
- )
 
 
159
 
 
 
 
 
 
160
 
 
 
 
 
 
161
  qa_chain = ConversationalRetrievalChain.from_llm(
162
  llm,
163
  retriever=retriever,
@@ -165,6 +177,7 @@ def initialize_llmchain(llm_model, temperature, max_tokens, top_k, vector_db, pr
165
  memory=memory,
166
  #prompt = prompt_template,
167
  #combine_docs_chain_kwargs={"prompt": prompt_template},
 
168
  return_source_documents=True,
169
  #return_generated_question=False,
170
  verbose=False,
 
149
  retriever=vector_db.as_retriever()
150
  progress(0.8, desc="Defining retrieval chain...")
151
 
152
+ #prompt_template_string = f'''Your task is as follows: 1. Determine if the input is compliant with the provided context. 2. If the requirement is compliant, report "This requirement is compliant." 3. If the requirement is not compliant report "This requirement is not compliant." 4. If the requirement is not compliant, give the reason for non compliance and return the specific rule or guideline the requirement violates. 5. If the requirement is not compliant, report a refined version of the requirement delimited in quotes that is compliant with the provided context.'''
153
 
154
  # Create a PromptTemplate object
155
+ #prompt_template = PromptTemplate(
156
+ # template=prompt_template_string,
157
+ # input_variables=["user_question","context"]
158
+ #)
159
+
160
+
161
 
162
+ template = """Your task is as follows: 1. Determine if the input requirement is compliant with the provided context. 2. If the requirement is compliant, report "This requirement is compliant." 3. If the requirement is not compliant report "This requirement is not compliant." 4. If the requirement is not compliant, give the reason for non compliance and return the specific rule or guideline the requirement violates. 5. If the requirement is not compliant, report a refined version of the requirement delimited in quotes that is compliant with the provided context.
163
+ Context: {context}
164
+ Chat History: {chat_history}
165
+ Follow Up Input: {question}
166
+ Standalone question:"""
167
 
168
+ PROMPT = PromptTemplate(
169
+ input_variables=["context", "chat_history", "question"],
170
+ template=template
171
+ )
172
+
173
  qa_chain = ConversationalRetrievalChain.from_llm(
174
  llm,
175
  retriever=retriever,
 
177
  memory=memory,
178
  #prompt = prompt_template,
179
  #combine_docs_chain_kwargs={"prompt": prompt_template},
180
+ combine_docs_chain_kwargs={"prompt": PROMPT}
181
  return_source_documents=True,
182
  #return_generated_question=False,
183
  verbose=False,