lindsay-qu
commited on
Update core/chatbot/retrieval_chatbot.py
Browse files
core/chatbot/retrieval_chatbot.py
CHANGED
@@ -39,15 +39,15 @@ class RetrievalChatbot(BaseChatbot):
|
|
39 |
print("Query: {message}".format(message=message))
|
40 |
question = self.decomposer.refine(message, None, image_paths)
|
41 |
print(question)
|
42 |
-
question = question.replace('"', "'").replace("', '", "','").lstrip("['").rstrip("']")
|
43 |
sub_questions = question.split("','")
|
44 |
print("Decomposed your query into subquestions: {sub_questions}".format(sub_questions=sub_questions))
|
45 |
tasks = []
|
46 |
time2 = time.time()
|
47 |
for sub_question in sub_questions:
|
48 |
-
print("="*20)
|
49 |
-
print(f"Subquestion: {sub_question}")
|
50 |
-
print(f"Retrieving pdf papers for references...\n")
|
51 |
task = asyncio.create_task(self.subquestion_answerer(sub_question, image_paths))
|
52 |
tasks.append(task)
|
53 |
results = await asyncio.gather(*tasks)
|
@@ -87,14 +87,16 @@ class RetrievalChatbot(BaseChatbot):
|
|
87 |
return answer
|
88 |
|
89 |
async def subquestion_answerer(self, sub_question: str, image_paths=None, return_logs=False) -> str:
|
90 |
-
time_s = time.time()
|
91 |
sub_retrieve_reference=""
|
|
|
92 |
sub_retrieve = self.retriever.retrieve(sub_question)
|
93 |
for ref in sub_retrieve:
|
94 |
sub_retrieve_reference += "Related research: {ref}\n".format(ref=ref)
|
95 |
sub_answerer_context = "Sub Question References: {sub_retrieve_reference}\nQuestion: {question}\n".format(sub_retrieve_reference=sub_retrieve_reference, question=sub_question)
|
96 |
-
|
|
|
|
|
97 |
time_e = time.time()
|
98 |
-
print(f"Time: {time_e
|
99 |
print(f"Subanswer: {sub_answer}")
|
100 |
return "Subquestion: {sub_question}\nSubanswer: {sub_answer}\n\n\n".format(sub_question=sub_question, sub_answer=sub_answer)
|
|
|
39 |
print("Query: {message}".format(message=message))
|
40 |
question = self.decomposer.refine(message, None, image_paths)
|
41 |
print(question)
|
42 |
+
question = question.replace('"', "'").replace("\n", "").replace("', '", "','").lstrip("['").rstrip("']")
|
43 |
sub_questions = question.split("','")
|
44 |
print("Decomposed your query into subquestions: {sub_questions}".format(sub_questions=sub_questions))
|
45 |
tasks = []
|
46 |
time2 = time.time()
|
47 |
for sub_question in sub_questions:
|
48 |
+
# print("="*20)
|
49 |
+
# print(f"Subquestion: {sub_question}")
|
50 |
+
# print(f"Retrieving pdf papers for references...\n")
|
51 |
task = asyncio.create_task(self.subquestion_answerer(sub_question, image_paths))
|
52 |
tasks.append(task)
|
53 |
results = await asyncio.gather(*tasks)
|
|
|
87 |
return answer
|
88 |
|
89 |
async def subquestion_answerer(self, sub_question: str, image_paths=None, return_logs=False) -> str:
|
|
|
90 |
sub_retrieve_reference=""
|
91 |
+
time_s = time.time()
|
92 |
sub_retrieve = self.retriever.retrieve(sub_question)
|
93 |
for ref in sub_retrieve:
|
94 |
sub_retrieve_reference += "Related research: {ref}\n".format(ref=ref)
|
95 |
sub_answerer_context = "Sub Question References: {sub_retrieve_reference}\nQuestion: {question}\n".format(sub_retrieve_reference=sub_retrieve_reference, question=sub_question)
|
96 |
+
refine_task = asyncio.create_task(self.answerer.refine_async(sub_answerer_context, self.memory, image_paths))
|
97 |
+
await refine_task
|
98 |
+
sub_answer = refine_task.result()
|
99 |
time_e = time.time()
|
100 |
+
print(f"Time: {time_e-time_s}")
|
101 |
print(f"Subanswer: {sub_answer}")
|
102 |
return "Subquestion: {sub_question}\nSubanswer: {sub_answer}\n\n\n".format(sub_question=sub_question, sub_answer=sub_answer)
|