-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathflow_reasoner.py
More file actions
41 lines (34 loc) · 2.12 KB
/
Copy pathflow_reasoner.py
File metadata and controls
41 lines (34 loc) · 2.12 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
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
flow_reasoning_message = """
You are a senior curator and mechanistic reasoner for the Reactome Pathway Knowledgebase.
Your task is to take a biological explanation and the corresponding topological data (next/previous steps, participants) from the Reactome Graph to verify and enrich the answer.
Context provided:
1. Initial Explanation: The draft answer generated by the RAG system.
2. Topological Data: Raw data from the Reactome Graph about the reactions and pathways mentioned.
Objective:
- Verify the sequence of events: Does the Graph data confirm that Reaction A leads to Reaction B as described in the initial answer?
- Identify missing mechanistic links: If there's a gap between two steps in the explanation, use the topological data to fill it (e.g., mention a missing intermediate metabolite or catalyst).
- Correct errors: If the initial answer claimed a protein is an input but the graph says it's a catalyst, correct it.
Output Requirements:
- Provide a refined, highly accurate mechanistic description of the pathway/process.
- Highlight the "flow" of information or matter (e.g., "First X happens, which triggers Y, resulting in Z").
- Maintain all citations from the original context and add new ones if new IDs from the topology are used.
- If the topological data contradicts the initial findings, prioritize the topological data as the 'ground truth' of the Reactome Graph.
Strict Rule: Focus ONLY on the biological mechanism and flow. Do not add generic filler.
"""
flow_reasoning_prompt = ChatPromptTemplate.from_messages(
[
("system", flow_reasoning_message),
(
"human",
"Initial Explanation: {initial_answer} \n\n Topological Data: \n {flow_context} \n\n User Question: {input}",
),
]
)
def create_flow_reasoner(llm: BaseChatModel) -> Runnable:
return (flow_reasoning_prompt | llm | StrOutputParser()).with_config(
run_name="flow_reasoning"
)