Spaces:
Sleeping
Sleeping
Update prompts.py
Browse files- prompts.py +22 -17
prompts.py
CHANGED
|
@@ -1,48 +1,39 @@
|
|
| 1 |
-
# prompts.py
|
| 2 |
from langchain.prompts import PromptTemplate
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
classification_prompt_str = """
|
| 5 |
You are a helpful assistant that classifies user questions into three categories:
|
| 6 |
1) "Wellness" if the question involves health, nutrition, fitness, mental well-being, self-care, or research related to these.
|
| 7 |
2) "Brand" if the question specifically pertains to 'DailyWellnessAI'—its mission, disclaimers, features, policies, etc.
|
| 8 |
-
3) "OutOfScope" if it does not fall into the above two categories.
|
| 9 |
-
|
| 10 |
**Response format**:
|
| 11 |
Reply exactly with one word: "Wellness", "Brand", or "OutOfScope". Do not provide any additional explanation.
|
| 12 |
-
|
| 13 |
Question: {query}
|
| 14 |
"""
|
| 15 |
|
| 16 |
-
|
| 17 |
tailor_prompt_str = """
|
| 18 |
You are a helpful assistant for DailyWellnessAI. Your role is to simplify complex ideas and offer actionable, user-friendly advice that aligns with our mission to enhance daily wellness through AI.
|
| 19 |
-
|
| 20 |
Here's the response to tailor:
|
| 21 |
{response}
|
| 22 |
-
|
| 23 |
Tailor it to ensure:
|
| 24 |
- Simplicity and clarity.
|
| 25 |
- Practicality, with actionable recommendations where appropriate.
|
| 26 |
- Alignment with DailyWellnessAI's mission of simplifying daily wellness through AI.
|
| 27 |
-
|
| 28 |
Provide the revised, concise response below:
|
| 29 |
"""
|
| 30 |
|
| 31 |
-
|
| 32 |
cleaner_prompt_str = """
|
| 33 |
You are a helpful AI. Below, you have two sources of information:
|
| 34 |
-
|
| 35 |
1) CSV (Knowledge Base) Answer:
|
| 36 |
{kb_answer}
|
| 37 |
-
|
| 38 |
2) Web Search Result:
|
| 39 |
{web_answer}
|
| 40 |
-
|
| 41 |
Your task:
|
| 42 |
- Combine and synthesize the two into a single, clear, cohesive answer.
|
| 43 |
- Avoid duplication or irrelevant details.
|
| 44 |
- Present the final response in straightforward, user-friendly language.
|
| 45 |
-
|
| 46 |
Do not repeat content verbatim. Merge the information meaningfully and provide your synthesized answer below:
|
| 47 |
"""
|
| 48 |
|
|
@@ -54,11 +45,8 @@ It can help promote mindfulness, relaxation, balance, or focus, all of which con
|
|
| 54 |
For more wellness-related questions or to learn more about DailyWellnessAI, feel free to ask—I’m here to support your wellness journey!
|
| 55 |
"""
|
| 56 |
|
| 57 |
-
# Define the PromptTemplate
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
# Now we define the PromptTemplate objects:
|
| 62 |
classification_prompt = PromptTemplate(
|
| 63 |
template=classification_prompt_str,
|
| 64 |
input_variables=["query"]
|
|
@@ -78,3 +66,20 @@ refusal_prompt = PromptTemplate(
|
|
| 78 |
template=refusal_prompt_str,
|
| 79 |
input_variables=["topic"]
|
| 80 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from langchain.prompts import PromptTemplate
|
| 2 |
|
| 3 |
+
# Define a list of harmful or inappropriate topics to block
|
| 4 |
+
HARMFUL_TOPICS = ["kill", "suicide", "harm", "death", "murder", "violence"]
|
| 5 |
+
|
| 6 |
classification_prompt_str = """
|
| 7 |
You are a helpful assistant that classifies user questions into three categories:
|
| 8 |
1) "Wellness" if the question involves health, nutrition, fitness, mental well-being, self-care, or research related to these.
|
| 9 |
2) "Brand" if the question specifically pertains to 'DailyWellnessAI'—its mission, disclaimers, features, policies, etc.
|
| 10 |
+
3) "OutOfScope" if it does not fall into the above two categories or if the question involves harmful topics.
|
|
|
|
| 11 |
**Response format**:
|
| 12 |
Reply exactly with one word: "Wellness", "Brand", or "OutOfScope". Do not provide any additional explanation.
|
|
|
|
| 13 |
Question: {query}
|
| 14 |
"""
|
| 15 |
|
|
|
|
| 16 |
tailor_prompt_str = """
|
| 17 |
You are a helpful assistant for DailyWellnessAI. Your role is to simplify complex ideas and offer actionable, user-friendly advice that aligns with our mission to enhance daily wellness through AI.
|
|
|
|
| 18 |
Here's the response to tailor:
|
| 19 |
{response}
|
|
|
|
| 20 |
Tailor it to ensure:
|
| 21 |
- Simplicity and clarity.
|
| 22 |
- Practicality, with actionable recommendations where appropriate.
|
| 23 |
- Alignment with DailyWellnessAI's mission of simplifying daily wellness through AI.
|
|
|
|
| 24 |
Provide the revised, concise response below:
|
| 25 |
"""
|
| 26 |
|
|
|
|
| 27 |
cleaner_prompt_str = """
|
| 28 |
You are a helpful AI. Below, you have two sources of information:
|
|
|
|
| 29 |
1) CSV (Knowledge Base) Answer:
|
| 30 |
{kb_answer}
|
|
|
|
| 31 |
2) Web Search Result:
|
| 32 |
{web_answer}
|
|
|
|
| 33 |
Your task:
|
| 34 |
- Combine and synthesize the two into a single, clear, cohesive answer.
|
| 35 |
- Avoid duplication or irrelevant details.
|
| 36 |
- Present the final response in straightforward, user-friendly language.
|
|
|
|
| 37 |
Do not repeat content verbatim. Merge the information meaningfully and provide your synthesized answer below:
|
| 38 |
"""
|
| 39 |
|
|
|
|
| 45 |
For more wellness-related questions or to learn more about DailyWellnessAI, feel free to ask—I’m here to support your wellness journey!
|
| 46 |
"""
|
| 47 |
|
| 48 |
+
# Define the PromptTemplate objects:
|
| 49 |
|
|
|
|
|
|
|
|
|
|
| 50 |
classification_prompt = PromptTemplate(
|
| 51 |
template=classification_prompt_str,
|
| 52 |
input_variables=["query"]
|
|
|
|
| 66 |
template=refusal_prompt_str,
|
| 67 |
input_variables=["topic"]
|
| 68 |
)
|
| 69 |
+
|
| 70 |
+
# Define function to check if the query contains harmful topics
|
| 71 |
+
def is_harmful(query: str) -> bool:
|
| 72 |
+
# Check if the query contains any harmful topics
|
| 73 |
+
for topic in HARMFUL_TOPICS:
|
| 74 |
+
if topic.lower() in query.lower():
|
| 75 |
+
return True
|
| 76 |
+
return False
|
| 77 |
+
|
| 78 |
+
# Now modify the classification logic:
|
| 79 |
+
def classify_query(query: str) -> str:
|
| 80 |
+
if is_harmful(query):
|
| 81 |
+
return "OutOfScope"
|
| 82 |
+
# Use the classification prompt template to classify the query
|
| 83 |
+
classification = classification_prompt.invoke({"query": query}).get("text", "").strip()
|
| 84 |
+
return classification
|
| 85 |
+
|