Ritvik19 commited on
Commit
7112b8c
·
verified ·
1 Parent(s): 26f9473

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +9 -18
  2. autoqa_chains.py +3 -3
app.py CHANGED
@@ -15,7 +15,7 @@ from chat_chains import (
15
  parse_context_and_question,
16
  ai_response_format,
17
  )
18
- from autoqa_chains import auto_qa_chain, auto_qa_output_parser
19
  from chain_of_density import chain_of_density_chain
20
  from insights_bullet_chain import insights_bullet_chain
21
  from insights_mind_map_chain import insights_mind_map_chain
@@ -292,23 +292,17 @@ def auto_qa_chain_wrapper(inputs):
292
  raise InvalidArgumentError("Please provide snippet ids")
293
  document = "\n\n".join([st.session_state.documents[c].page_content for c in inputs])
294
  llm = ChatOpenAI(model=st.session_state.model, temperature=0)
295
- auto_qa_conversation = []
296
  with get_openai_callback() as cb:
297
- auto_qa_response = auto_qa_chain(llm).invoke({"paper": document})
298
- auto_qa_response_parsed = auto_qa_output_parser.invoke(auto_qa_response)[
299
- "questions"
300
- ]
301
- auto_qa_conversation = [
302
- (f'/auto {qa["question"]}', qa["answer"], "identity")
303
- for qa in auto_qa_response_parsed
304
- ]
305
  stats = cb
306
  st.session_state.messages.append(
307
- (f"/auto-insight {inputs}", "Auto Convervation Generated", "identity")
308
  )
309
- for qa in auto_qa_conversation:
310
- st.session_state.messages.append((qa[0], qa[1], "identity"))
311
-
312
  st.session_state.costing.append(
313
  {
314
  "prompt tokens": stats.prompt_tokens,
@@ -317,10 +311,7 @@ def auto_qa_chain_wrapper(inputs):
317
  }
318
  )
319
  return (
320
- "\n\n".join(
321
- f"Q: {qa['question']}\n\nA: {qa['answer']}"
322
- for qa in auto_qa_response_parsed
323
- ),
324
  "identity",
325
  )
326
 
 
15
  parse_context_and_question,
16
  ai_response_format,
17
  )
18
+ from autoqa_chains import auto_qa_chain, auto_qa_output_parser, followup_qa_chain
19
  from chain_of_density import chain_of_density_chain
20
  from insights_bullet_chain import insights_bullet_chain
21
  from insights_mind_map_chain import insights_mind_map_chain
 
292
  raise InvalidArgumentError("Please provide snippet ids")
293
  document = "\n\n".join([st.session_state.documents[c].page_content for c in inputs])
294
  llm = ChatOpenAI(model=st.session_state.model, temperature=0)
 
295
  with get_openai_callback() as cb:
296
+ auto_qa_response = auto_qa_output_parser.invoke(
297
+ auto_qa_chain(llm).invoke({"paper": document})
298
+ )["questions"]
299
+ formated_response = "\n\n".join(
300
+ f"#### {qa['question']}\n\n{qa['answer']}" for qa in auto_qa_response
301
+ )
 
 
302
  stats = cb
303
  st.session_state.messages.append(
304
+ (f"/auto-insight {inputs}", formated_response, "identity")
305
  )
 
 
 
306
  st.session_state.costing.append(
307
  {
308
  "prompt tokens": stats.prompt_tokens,
 
311
  }
312
  )
313
  return (
314
+ formated_response,
 
 
 
315
  "identity",
316
  )
317
 
autoqa_chains.py CHANGED
@@ -19,7 +19,7 @@ The focus should be on the paper's objectives, methodology, key findings, and im
19
  The answers must be based on the content of the research paper, offering clear and comprehensive insights for readers.
20
  Ensure that the questions cover a broad range of topics related to the paper, including but not limited to the introduction, literature review, \
21
  methodology, results, discussion, and conclusions.
22
- The goal is to capture the essence of the paper in a way that is accessible to a broad audience.
23
  Your response should be recorded in the following json format: {format_instructions}.
24
 
25
  here is the research paper: ####{paper}####
@@ -48,10 +48,10 @@ here is the research paper: ####{paper}####
48
 
49
  followup_prompt = PromptTemplate(
50
  template=followup_prompt_template,
51
- input_variables=["paper"],
52
  partial_variables={
53
  "format_instructions": auto_qa_output_parser.get_format_instructions()
54
  },
55
  )
56
 
57
- followup_qa_chain = lambda model: qa_prompt | model
 
19
  The answers must be based on the content of the research paper, offering clear and comprehensive insights for readers.
20
  Ensure that the questions cover a broad range of topics related to the paper, including but not limited to the introduction, literature review, \
21
  methodology, results, discussion, and conclusions.
22
+ The goal is to capture the essence of the paper in a way that is accessible to an expert audience.
23
  Your response should be recorded in the following json format: {format_instructions}.
24
 
25
  here is the research paper: ####{paper}####
 
48
 
49
  followup_prompt = PromptTemplate(
50
  template=followup_prompt_template,
51
+ input_variables=["paper", "question", "answer"],
52
  partial_variables={
53
  "format_instructions": auto_qa_output_parser.get_format_instructions()
54
  },
55
  )
56
 
57
+ followup_qa_chain = lambda model: followup_prompt | model