updated tldr chain
Browse files- app.py +9 -7
- tldr_chain.py +4 -7
app.py
CHANGED
|
@@ -49,7 +49,7 @@ Here's a quick guide to getting started with me:
|
|
| 49 |
| `/paper-synopsis <list of snippet ids>` | Generate a synopsis of the paper. |
|
| 50 |
| `/deep-dive [<list of snippet ids>] <query>` | Query me with a specific context. |
|
| 51 |
| `/summarise-section [<list of snippet ids>] <section name>` | Summarize a specific section of the paper. |
|
| 52 |
-
| `/tldr <list of snippet ids>` | Generate a tldr summary of the paper. |
|
| 53 |
|
| 54 |
|
| 55 |
<br>
|
|
@@ -79,7 +79,7 @@ def process_documents_wrapper(inputs):
|
|
| 79 |
return index_documents_wrapper(None, f"/add-papers {inputs}")
|
| 80 |
|
| 81 |
|
| 82 |
-
def index_documents_wrapper(inputs=None, arg=
|
| 83 |
response = pd.DataFrame(
|
| 84 |
st.session_state.index, columns=["id", "reference", "tokens"]
|
| 85 |
)
|
|
@@ -251,12 +251,14 @@ def synopsis_wrapper(inputs):
|
|
| 251 |
|
| 252 |
|
| 253 |
def tldr_wrapper(inputs):
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
document = "\n\n".join(
|
|
|
|
|
|
|
| 257 |
llm = ChatOpenAI(model=st.session_state.model, temperature=0)
|
| 258 |
with get_openai_callback() as cb:
|
| 259 |
-
summary = tldr_chain(llm).invoke({"paper": document})
|
| 260 |
stats = cb
|
| 261 |
st.session_state.messages.append(("/tldr", summary, "identity"))
|
| 262 |
st.session_state.costing.append(
|
|
@@ -401,7 +403,7 @@ if __name__ == "__main__":
|
|
| 401 |
("/insight-mind-map", list, insights_mind_map_wrapper),
|
| 402 |
("/paper-synopsis", list, synopsis_wrapper),
|
| 403 |
("/summarise-section", str, summarise_wrapper),
|
| 404 |
-
("/tldr",
|
| 405 |
]
|
| 406 |
command_center = CommandCenter(
|
| 407 |
default_input_type=str,
|
|
|
|
| 49 |
| `/paper-synopsis <list of snippet ids>` | Generate a synopsis of the paper. |
|
| 50 |
| `/deep-dive [<list of snippet ids>] <query>` | Query me with a specific context. |
|
| 51 |
| `/summarise-section [<list of snippet ids>] <section name>` | Summarize a specific section of the paper. |
|
| 52 |
+
| `/tldr [<list of snippet ids>] <query>` | Generate a tldr summary of the paper. |
|
| 53 |
|
| 54 |
|
| 55 |
<br>
|
|
|
|
| 79 |
return index_documents_wrapper(None, f"/add-papers {inputs}")
|
| 80 |
|
| 81 |
|
| 82 |
+
def index_documents_wrapper(inputs=None, arg="/library"):
|
| 83 |
response = pd.DataFrame(
|
| 84 |
st.session_state.index, columns=["id", "reference", "tokens"]
|
| 85 |
)
|
|
|
|
| 251 |
|
| 252 |
|
| 253 |
def tldr_wrapper(inputs):
|
| 254 |
+
print(inputs)
|
| 255 |
+
context, query = parse_context_and_question(inputs)
|
| 256 |
+
document = "\n\n".join(
|
| 257 |
+
[st.session_state.documents[c].page_content for c in context]
|
| 258 |
+
)
|
| 259 |
llm = ChatOpenAI(model=st.session_state.model, temperature=0)
|
| 260 |
with get_openai_callback() as cb:
|
| 261 |
+
summary = tldr_chain(llm).invoke({"title": query, "paper": document})
|
| 262 |
stats = cb
|
| 263 |
st.session_state.messages.append(("/tldr", summary, "identity"))
|
| 264 |
st.session_state.costing.append(
|
|
|
|
| 403 |
("/insight-mind-map", list, insights_mind_map_wrapper),
|
| 404 |
("/paper-synopsis", list, synopsis_wrapper),
|
| 405 |
("/summarise-section", str, summarise_wrapper),
|
| 406 |
+
("/tldr", str, tldr_wrapper),
|
| 407 |
]
|
| 408 |
command_center = CommandCenter(
|
| 409 |
default_input_type=str,
|
tldr_chain.py
CHANGED
|
@@ -3,12 +3,9 @@ from langchain_core.output_parsers import StrOutputParser
|
|
| 3 |
|
| 4 |
tldr_prompt_template = """
|
| 5 |
Create a mind map of the given research paper along the given lines:
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
4. Major Findings: The main findings of the study
|
| 10 |
-
5. Key Results: More details about the results of the study
|
| 11 |
-
6. Conclusion: Significance of the findings and what they mean for future research
|
| 12 |
|
| 13 |
The above sections may differ from paper to paper, hence you may need to adjust the structure accordingly by dropping / merging one or more sections.
|
| 14 |
|
|
@@ -21,6 +18,6 @@ Ensure that the outline is structured in Markdown format for clarity, facilitati
|
|
| 21 |
tldr_output_parser = StrOutputParser()
|
| 22 |
tldr_prompt = PromptTemplate(
|
| 23 |
template=tldr_prompt_template,
|
| 24 |
-
input_variables=["paper"],
|
| 25 |
)
|
| 26 |
tldr_chain = lambda model: tldr_prompt | model | tldr_output_parser
|
|
|
|
| 3 |
|
| 4 |
tldr_prompt_template = """
|
| 5 |
Create a mind map of the given research paper along the given lines:
|
| 6 |
+
what is {title}?
|
| 7 |
+
what this paper brings to the research community including how it is different from existing work?
|
| 8 |
+
what novel ideas/techniques are presented in this paper?
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
The above sections may differ from paper to paper, hence you may need to adjust the structure accordingly by dropping / merging one or more sections.
|
| 11 |
|
|
|
|
| 18 |
tldr_output_parser = StrOutputParser()
|
| 19 |
tldr_prompt = PromptTemplate(
|
| 20 |
template=tldr_prompt_template,
|
| 21 |
+
input_variables=["title", "paper"],
|
| 22 |
)
|
| 23 |
tldr_chain = lambda model: tldr_prompt | model | tldr_output_parser
|