File size: 1,447 Bytes
b3d8117
 
 
 
 
8e711d1
b3d8117
 
 
8e711d1
b3d8117
8e711d1
b3d8117
 
 
 
 
8e711d1
 
b3d8117
 
8e711d1
b3d8117
 
 
8e711d1
 
 
 
 
b3d8117
 
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
import json
from typing import Dict
from langchain import PromptTemplate, LLMChain
from models import chat_model

# Enhanced Prompt Template
recommend_prompt_template = PromptTemplate(
    input_variables=["problems"],
    template=(
        "You are a helpful wellness recommendation system. Given the following problem severity percentages:\n"
        "{problems}\n\n"
        "Based on these strict rules:\n"
        "- If sleep_problem > 70: Recommend Sleep Improvement Package\n"
        "- If stress_problem > 70: Recommend Stress Reduction Package\n"
        "- If exercise_problem > 70: Recommend Exercise Enhancement Package\n"
        "- If all problems are between 30 and 70: Recommend Balanced Wellness Package\n"
        "- If no severe problems: Recommend General Wellness Package\n\n"
        "List the recommended wellness packages separated by commas. "
        "Do not include any additional text or explanation."
    )
)

recommend_chain = LLMChain(llm=chat_model, prompt=recommend_prompt_template)

def generate_recommendations(problems: Dict[str, float]) -> str:
    """
    Generates wellness package recommendations based on problem severity percentages.
    The function accepts a dictionary of problem severities and returns a 
    comma-separated string of recommended packages based on predefined rules.
    """
    recommendations = recommend_chain.run(problems=json.dumps(problems))
    return recommendations.strip()