Skip to content

Commit 3a9d0c0

Browse files
committed
Add iGraph data to prompt
1 parent 17d8580 commit 3a9d0c0

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

app/pipeline.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from app.clients import query_llama
88
from app.prompts import DETERMINE_TASK_PROMPT, GENERAL_PROMPT, \
9-
DENY_PROMPT, TASKS, GRAPH_NEEDED, FIND_SUBSTANCES_PROMPT
9+
DENY_PROMPT, TASKS, GRAPH_NEEDED, FIND_SUBSTANCES_PROMPT, GRAPH_PROMPT
1010
from app.gpraph import run_subgraph_builder
1111

1212
entities_file = "data/entity_name_mapping.json"
@@ -97,13 +97,14 @@ def process_pipeline(query: str, history: List[str]=[], graph: Optional[object]=
9797
logger.debug(f"Query received: {query}")
9898
discovered_class = determine_task(query)
9999
logger.info(f"Query: {query} -> {discovered_class}")
100-
prompt = f"{DENY_PROMPT}\n\nTask:{query}"
100+
prompt = f"{DENY_PROMPT}\n\nTask: {query}"
101101
if discovered_class in TASKS.keys():
102102

103103
if discovered_class == "help":
104-
prompt = f"{GENERAL_PROMPT}\n\n{TASKS[discovered_class]}\nTasks which you can do:{TASKS}\nQuery:{query}"
104+
prompt = f"{GENERAL_PROMPT}\n\n{TASKS[discovered_class]}\nTasks which you can do:{TASKS}\nQuery: {query}"
105105

106106
elif discovered_class in GRAPH_NEEDED:
107+
prompt = f"{GENERAL_PROMPT}\n\n{TASKS[discovered_class]}\nTask: {query}"
107108
# Prepare the graph if needed
108109
substances = find_substances_llm(query)
109110
logger.info(f"Found substances in query: {substances}")
@@ -119,9 +120,17 @@ def process_pipeline(query: str, history: List[str]=[], graph: Optional[object]=
119120
logger.info(f"Found substances by LLM: {substances}. Try to find in the DrugBank vocabulary and bulding a graph")
120121
response['graph'] = run_subgraph_builder(substances)
121122
logger.info(f"Subgraph built with {len(response['graph'].vs)} vertices and {len(response['graph'].es)} edges.")
123+
124+
if response['graph']:
125+
prompt = f"{GENERAL_PROMPT}\n\n{TASKS[discovered_class]}\n{GRAPH_PROMPT}\n{response['graph']}\nTask: {query}"
126+
122127
else:
123-
prompt = f"{GENERAL_PROMPT}\n\n{TASKS[discovered_class]}\nQuery:{query}"
128+
prompt = f"{GENERAL_PROMPT}\n\n{TASKS[discovered_class]}\nQuery: {query}"
129+
130+
# logger.debug(response['graph'])
124131
response['text'] = query_llama(prompt)
132+
logger.debug(f"Query to LLM: {prompt}")
133+
logger.debug(f"LLM response: {response['text']}")
125134
logger.info(f"Sending response: {response['text'][:120]}...")
126135
return response
127136

app/prompts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@
4545

4646
FIND_SUBSTANCES_PROMPT = """Find any substances in the query below.
4747
Return a list of original words from text separated by ',' without spaces after ','. Do not separate one substance with ',' if it takes more than one word."""
48+
49+
GRAPH_PROMPT = "Additional information below includes a subgraph displaying relations between those substances in iGraph format. Use it to form the response as a ground truth"

0 commit comments

Comments
 (0)