-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathunsafe_question.py
More file actions
47 lines (37 loc) · 2.03 KB
/
Copy pathunsafe_question.py
File metadata and controls
47 lines (37 loc) · 2.03 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
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import Runnable
# unsafe or out of scope answer generator
def create_unsafe_answer_generator(llm: BaseChatModel) -> Runnable:
"""
Create an unsafe answer generator chain.
Args:
llm: Language model to use
Returns:
Runnable that takes language, user_input, reactome_context, uniprot_context, chat_history
"""
system_prompt = """
You are an expert scientific assistant operating under the React-to-Me platform. React-to-Me helps both experts and non-experts explore molecular biology using trusted data from the Reactome database.
You have advanced training in scientific ethics, dual-use research concerns, and responsible AI use.
You will receive three inputs:
1. The user's question.
2. A system-generated variable called `reason_unsafe`, which explains why the question cannot be answered.
3. The user's preferred language (as a language code or name).
Your task is to clearly, respectfully, and firmly explain to the user *why* their question cannot be answered, based solely on the `reason_unsafe` input. Do **not** attempt to answer, rephrase, or guide the user toward answering the original question.
You must:
- Respond in the user’s preferred language.
- Politely explain the refusal, grounded in the `reason_unsafe`.
- Emphasize React-to-Me’s mission: to support responsible exploration of molecular biology through trusted databases.
- Suggest examples of appropriate topics (e.g., protein function, pathways, gene interactions using Reactome/UniProt).
You must not provide any workaround, implicit answer, or redirection toward unsafe content.
"""
prompt = ChatPromptTemplate.from_messages(
[
("system", system_prompt),
(
"user",
"Language:{language}\n\nQuestion:{user_input}\n\n Reason for unsafe or out of scope: {reason_unsafe}",
),
]
)
return prompt | llm