Update chain_recommendations.py
Browse files- chain_recommendations.py +14 -17
chain_recommendations.py
CHANGED
@@ -1,32 +1,29 @@
|
|
|
|
1 |
import json
|
2 |
from typing import Dict
|
3 |
from langchain import PromptTemplate, LLMChain
|
4 |
from models import chat_model
|
5 |
|
6 |
-
|
7 |
-
recommend_prompt_template = PromptTemplate(
|
8 |
input_variables=["problems"],
|
9 |
template=(
|
10 |
-
"You are a
|
11 |
"{problems}\n\n"
|
12 |
-
"
|
13 |
-
"
|
14 |
-
"
|
15 |
-
"- If
|
16 |
-
"- If
|
17 |
-
"- If
|
18 |
-
"
|
19 |
-
"
|
|
|
20 |
)
|
21 |
)
|
22 |
|
23 |
-
|
|
|
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()
|
|
|
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 |
+
improved_recommend_prompt_template = PromptTemplate(
|
|
|
8 |
input_variables=["problems"],
|
9 |
template=(
|
10 |
+
"You are a wellness recommendation assistant. Given the following problem severity percentages:\n"
|
11 |
"{problems}\n\n"
|
12 |
+
"Carefully analyze these percentages and consider nuanced differences between the areas. "
|
13 |
+
"Your goal is to recommend the most appropriate wellness packages based on a detailed assessment of these numbers, "
|
14 |
+
"not just fixed thresholds. Consider the following guidelines:\n\n"
|
15 |
+
"- If one area is extremely high (above 70) while others are lower, prioritize a package targeting that area.\n"
|
16 |
+
"- If multiple areas are high or near high (e.g., above 60), consider recommending multiple specialized packages or a comprehensive program.\n"
|
17 |
+
"- If all areas are moderate (between 30 and 70), recommend a balanced wellness package that addresses overall health.\n"
|
18 |
+
"- If all areas are low, a general wellness package might be sufficient.\n"
|
19 |
+
"- Consider borderline cases and recommend packages that address both current issues and preventive measures.\n\n"
|
20 |
+
"Return the recommended wellness packages in a JSON array format."
|
21 |
)
|
22 |
)
|
23 |
|
24 |
+
# Initialize the improved recommendation chain
|
25 |
+
recommend_chain = LLMChain(llm=chat_model, prompt=improved_recommend_prompt_template)
|
26 |
|
27 |
def generate_recommendations(problems: Dict[str, float]) -> str:
|
|
|
|
|
|
|
|
|
|
|
28 |
recommendations = recommend_chain.run(problems=json.dumps(problems))
|
29 |
return recommendations.strip()
|