Phoenix21 commited on
Commit
e022d18
·
verified ·
1 Parent(s): 8e711d1

Update chain_recommendations.py

Browse files
Files changed (1) hide show
  1. 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
- # 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()
 
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()