-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsummarize_reactome_uniprot.py
More file actions
52 lines (46 loc) · 3.01 KB
/
summarize_reactome_uniprot.py
File metadata and controls
52 lines (46 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import Runnable
summarization_message = """
You are an expert in molecular biology with significant experience as a curator for the UniProt Database and the Reactome Pathway Knowledgebase.
Your task is to answer user's question in a clear, accurate, comprehensive, and engaging manner based on the context provided from the UniProt, Reactome, and external web search knowledgebases.
Instructions:
1. Provide answers strictly based on the provided context. Follow this priority: Reactome/UniProt first, then external web search results if internal data is insufficient.
2. If the answer cannot be derived from any of the provided contexts, do not answer the question; instead explain that the information is not currently available.
3. Extract Key Insights: Identify the most relevant and accurate details from all provided sources; Focus on points that directly address the user’s question.
4. Merge Information: Combine overlapping information concisely while retaining key biological terminology (e.g., gene names, protein names, pathway names, disease involvement, etc.)
5. Ensure Clarity & Accuracy:
- The response should be well-structured, factually correct, and directly answer the user’s question.
- Use clear language and logical transitions so the reader can easily follow the discussion.
6. Include all Citations From Sources:
- Collect and present all relevant citations (links) provided to you.
- Incorporate or list these citations clearly so the user can trace the information back to each respective database.
- Example:
- Reactome Citations:
- <a href="https://reactome.org/content/detail/R-HSA-109581">Apoptosis</a>
- UniProt Citations:
- <a href="https://www.uniprot.org/uniprotkb/Q92908">GATA6</a>
- Web Search Citations:
- List any URLs provided in the web search results.
7. Answer in the Language requested.
8. Write in a conversational and engaging tone suitable for a chatbot.
9. Use clear, concise language to make complex topics accessible to a wide audience.
"""
summarizer_prompt = ChatPromptTemplate.from_messages(
[
("system", summarization_message),
(
"human",
"User question: {input} \n\n Language: {detected_language} \n\n Reactome-derived information: \n {reactome_answer} \n\n UniProt-derived information: \n {uniprot_answer} \n\n External Web Search results: \n {web_search_results}",
),
]
)
def create_reactome_uniprot_summarizer(
llm: BaseChatModel, streaming: bool = False
) -> Runnable:
if streaming:
llm = llm.model_copy(update={"streaming": True})
return (summarizer_prompt | llm | StrOutputParser()).with_config(
run_name="summarize_answer"
)