KonradSzafer commited on
Commit
9ec47bf
1 Parent(s): d22d549

2 step answer

Browse files
Files changed (1) hide show
  1. qa_engine/qa_engine.py +18 -2
qa_engine/qa_engine.py CHANGED
@@ -234,7 +234,7 @@ class QAEngine():
234
 
235
  @staticmethod
236
  def _preprocess_question(question: str) -> str:
237
- if question[-1] != '?':
238
  question += '?'
239
  return question
240
 
@@ -304,8 +304,24 @@ class QAEngine():
304
 
305
  logger.info('Running LLM chain')
306
  question_processed = QAEngine._preprocess_question(question)
 
307
  answer = self.llm_chain.run(question=question_processed, context=context)
308
- answer_postprocessed = QAEngine._postprocess_answer(answer)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  response.set_answer(answer_postprocessed)
310
  logger.info('Received answer')
311
 
 
234
 
235
  @staticmethod
236
  def _preprocess_question(question: str) -> str:
237
+ if '?' not in question:
238
  question += '?'
239
  return question
240
 
 
304
 
305
  logger.info('Running LLM chain')
306
  question_processed = QAEngine._preprocess_question(question)
307
+
308
  answer = self.llm_chain.run(question=question_processed, context=context)
309
+
310
+ answer_step_2 = self.llm_model(
311
+ f"""
312
+ <|im_start|>system
313
+ Given the context provided below, review the existing answer to the question to determine its accuracy and completeness. If the answer is incorrect or incomplete, update it to reflect the most accurate and relevant information based on the context. Ensure that the updated answer is clear, concise, and directly addresses the question. Your primary objective is to return only the updated answer. <|im_end|>
314
+ <|im_end|>
315
+ <|im_start|>user
316
+ <context>{context}</context>
317
+ <question>{question_processed}</question>
318
+ <answer>{answer}</answer>
319
+ <|im_end|>
320
+ <|im_start|>assistant
321
+ """
322
+ )
323
+
324
+ answer_postprocessed = QAEngine._postprocess_answer(answer_step_2)
325
  response.set_answer(answer_postprocessed)
326
  logger.info('Received answer')
327