Spaces:
Sleeping
Sleeping
Update chain_recommendations.py
Browse files- chain_recommendations.py +11 -4
chain_recommendations.py
CHANGED
@@ -1,25 +1,32 @@
|
|
1 |
-
# chain_recommendations.py
|
2 |
import json
|
3 |
from typing import Dict
|
4 |
from langchain import PromptTemplate, LLMChain
|
5 |
from models import chat_model
|
6 |
|
|
|
7 |
recommend_prompt_template = PromptTemplate(
|
8 |
input_variables=["problems"],
|
9 |
template=(
|
10 |
-
"Given the following problem severity percentages:\n"
|
11 |
"{problems}\n\n"
|
12 |
-
"
|
13 |
"- If sleep_problem > 70: Recommend Sleep Improvement Package\n"
|
14 |
"- If stress_problem > 70: Recommend Stress Reduction Package\n"
|
15 |
"- If exercise_problem > 70: Recommend Exercise Enhancement Package\n"
|
16 |
"- If all problems are between 30 and 70: Recommend Balanced Wellness Package\n"
|
17 |
"- If no severe problems: Recommend General Wellness Package\n\n"
|
18 |
-
"
|
|
|
19 |
)
|
20 |
)
|
|
|
21 |
recommend_chain = LLMChain(llm=chat_model, prompt=recommend_prompt_template)
|
22 |
|
23 |
def generate_recommendations(problems: Dict[str, float]) -> str:
|
|
|
|
|
|
|
|
|
|
|
24 |
recommendations = recommend_chain.run(problems=json.dumps(problems))
|
25 |
return recommendations.strip()
|
|
|
|
|
1 |
import json
|
2 |
from typing import Dict
|
3 |
from langchain import PromptTemplate, LLMChain
|
4 |
from models import chat_model
|
5 |
|
6 |
+
# Enhanced Prompt Template
|
7 |
recommend_prompt_template = PromptTemplate(
|
8 |
input_variables=["problems"],
|
9 |
template=(
|
10 |
+
"You are a helpful wellness recommendation system. Given the following problem severity percentages:\n"
|
11 |
"{problems}\n\n"
|
12 |
+
"Based on these strict rules:\n"
|
13 |
"- If sleep_problem > 70: Recommend Sleep Improvement Package\n"
|
14 |
"- If stress_problem > 70: Recommend Stress Reduction Package\n"
|
15 |
"- If exercise_problem > 70: Recommend Exercise Enhancement Package\n"
|
16 |
"- If all problems are between 30 and 70: Recommend Balanced Wellness Package\n"
|
17 |
"- If no severe problems: Recommend General Wellness Package\n\n"
|
18 |
+
"List the recommended wellness packages separated by commas. "
|
19 |
+
"Do not include any additional text or explanation."
|
20 |
)
|
21 |
)
|
22 |
+
|
23 |
recommend_chain = LLMChain(llm=chat_model, prompt=recommend_prompt_template)
|
24 |
|
25 |
def generate_recommendations(problems: Dict[str, float]) -> str:
|
26 |
+
"""
|
27 |
+
Generates wellness package recommendations based on problem severity percentages.
|
28 |
+
The function accepts a dictionary of problem severities and returns a
|
29 |
+
comma-separated string of recommended packages based on predefined rules.
|
30 |
+
"""
|
31 |
recommendations = recommend_chain.run(problems=json.dumps(problems))
|
32 |
return recommendations.strip()
|