Upload 2 files
Browse files- app.py +22 -0
- insights_mind_map_chain.py +37 -0
app.py
CHANGED
|
@@ -18,6 +18,7 @@ from chat_chains import (
|
|
| 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 synopsis_chain import synopsis_chain
|
| 22 |
from custom_exceptions import InvalidArgumentError, InvalidCommandError
|
| 23 |
from openai_configuration import openai_parser
|
|
@@ -43,6 +44,7 @@ Here's a quick guide to getting started with me:
|
|
| 43 |
| `/auto-insight <list of snippet ids>` | Automatically generate questions and answers for the paper. |
|
| 44 |
| `/condense-summary <list of snippet ids>` | Generate increasingly concise, entity-dense summaries of the paper. |
|
| 45 |
| `/insight-bullets <list of snippet ids>` | Extract and summarize key insights, methods, results, and conclusions. |
|
|
|
|
| 46 |
| `/paper-synopsis <list of snippet ids>` | Generate a synopsis of the paper. |
|
| 47 |
| `/deep-dive [<list of snippet ids>] <query>` | Query me with a specific context. |
|
| 48 |
| `/summarise-section [<list of snippet ids>] <section name>` | Summarize a specific section of the paper. |
|
|
@@ -264,6 +266,25 @@ def insights_bullet_wrapper(inputs):
|
|
| 264 |
return (insights, "identity")
|
| 265 |
|
| 266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
def auto_qa_chain_wrapper(inputs):
|
| 268 |
if inputs == []:
|
| 269 |
raise InvalidArgumentError("Please provide snippet ids")
|
|
@@ -346,6 +367,7 @@ if __name__ == "__main__":
|
|
| 346 |
("/deep-dive", str, query_llm_wrapper),
|
| 347 |
("/condense-summary", list, chain_of_density_wrapper),
|
| 348 |
("/insight-bullets", list, insights_bullet_wrapper),
|
|
|
|
| 349 |
("/paper-synopsis", list, synopsis_wrapper),
|
| 350 |
("/summarise-section", str, summarise_wrapper),
|
| 351 |
]
|
|
|
|
| 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
|
| 22 |
from synopsis_chain import synopsis_chain
|
| 23 |
from custom_exceptions import InvalidArgumentError, InvalidCommandError
|
| 24 |
from openai_configuration import openai_parser
|
|
|
|
| 44 |
| `/auto-insight <list of snippet ids>` | Automatically generate questions and answers for the paper. |
|
| 45 |
| `/condense-summary <list of snippet ids>` | Generate increasingly concise, entity-dense summaries of the paper. |
|
| 46 |
| `/insight-bullets <list of snippet ids>` | Extract and summarize key insights, methods, results, and conclusions. |
|
| 47 |
+
| `/insight-mind-map <list of snippet ids>` | Create a structured outline of the key insights in Markdown format. |
|
| 48 |
| `/paper-synopsis <list of snippet ids>` | Generate a synopsis of the paper. |
|
| 49 |
| `/deep-dive [<list of snippet ids>] <query>` | Query me with a specific context. |
|
| 50 |
| `/summarise-section [<list of snippet ids>] <section name>` | Summarize a specific section of the paper. |
|
|
|
|
| 266 |
return (insights, "identity")
|
| 267 |
|
| 268 |
|
| 269 |
+
def insights_mind_map_wrapper(inputs):
|
| 270 |
+
if inputs == []:
|
| 271 |
+
raise InvalidArgumentError("Please provide snippet ids")
|
| 272 |
+
document = "\n\n".join([st.session_state.documents[c].page_content for c in inputs])
|
| 273 |
+
llm = ChatOpenAI(model=st.session_state.model, temperature=0)
|
| 274 |
+
with get_openai_callback() as cb:
|
| 275 |
+
insights = insights_mind_map_chain(llm).invoke({"paper": document})
|
| 276 |
+
stats = cb
|
| 277 |
+
st.session_state.messages.append(("/insight-mind-map", insights, "identity"))
|
| 278 |
+
st.session_state.costing.append(
|
| 279 |
+
{
|
| 280 |
+
"prompt tokens": stats.prompt_tokens,
|
| 281 |
+
"completion tokens": stats.completion_tokens,
|
| 282 |
+
"cost": stats.total_cost,
|
| 283 |
+
}
|
| 284 |
+
)
|
| 285 |
+
return (insights, "identity")
|
| 286 |
+
|
| 287 |
+
|
| 288 |
def auto_qa_chain_wrapper(inputs):
|
| 289 |
if inputs == []:
|
| 290 |
raise InvalidArgumentError("Please provide snippet ids")
|
|
|
|
| 367 |
("/deep-dive", str, query_llm_wrapper),
|
| 368 |
("/condense-summary", list, chain_of_density_wrapper),
|
| 369 |
("/insight-bullets", list, insights_bullet_wrapper),
|
| 370 |
+
("/insight-mind-map", list, insights_mind_map_wrapper),
|
| 371 |
("/paper-synopsis", list, synopsis_wrapper),
|
| 372 |
("/summarise-section", str, summarise_wrapper),
|
| 373 |
]
|
insights_mind_map_chain.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain_core.prompts import PromptTemplate
|
| 2 |
+
from langchain_core.output_parsers import StrOutputParser
|
| 3 |
+
|
| 4 |
+
insights_mind_map_prompt_template = """
|
| 5 |
+
Based on the provided excerpt, create a detailed outline in Markdown format that organizes the content into distinct sections for the experiment setup and separate branches for each analysis mentioned.
|
| 6 |
+
This structure should provide a clear and comprehensive overview of the study, emphasizing the setup, methodologies, findings, and implications of each analysis independently.
|
| 7 |
+
Structure the outline as follows:
|
| 8 |
+
|
| 9 |
+
- **Experiment Setup**:
|
| 10 |
+
- Description of the general setup for the experiments, including any datasets and baselines used.
|
| 11 |
+
|
| 12 |
+
For each analysis mentioned in the excerpt, create individual branches as follows:
|
| 13 |
+
|
| 14 |
+
- **Analysis [Name/Number]**:
|
| 15 |
+
1. **Objectives**:
|
| 16 |
+
- The main goal or purpose of this specific analysis.
|
| 17 |
+
2. **Methods**:
|
| 18 |
+
- Detailed overview of the approach, techniques, or methodologies employed in this analysis.
|
| 19 |
+
3. **Results and Conclusions**:
|
| 20 |
+
- Key findings, data interpretation, and the implications drawn from this analysis.
|
| 21 |
+
- Combine this section if the results and conclusions are closely aligned to streamline content.
|
| 22 |
+
4. **Figures and Tables**:
|
| 23 |
+
- Mention and describe any figures or tables referenced, linking them to their corresponding insights.
|
| 24 |
+
|
| 25 |
+
Ensure that the outline is structured in Markdown format for clarity, facilitating its integration into documents or presentations. This structured approach aims to provide a comprehensive view of the experimental framework and the individual analyses, highlighting their unique contributions to the overall study."
|
| 26 |
+
|
| 27 |
+
excerpt: {paper}
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
insights_mind_map_output_parser = StrOutputParser()
|
| 31 |
+
insights_mind_map_prompt = PromptTemplate(
|
| 32 |
+
template=insights_mind_map_prompt_template,
|
| 33 |
+
input_variables=["paper"],
|
| 34 |
+
)
|
| 35 |
+
insights_mind_map_chain = (
|
| 36 |
+
lambda model: insights_mind_map_prompt | model | insights_mind_map_output_parser
|
| 37 |
+
)
|