File size: 2,433 Bytes
e022d18
b3d8117
 
 
 
 
e022d18
b3d8117
 
e022d18
b3d8117
6887e24
 
 
 
 
 
 
e022d18
 
 
 
 
 
 
 
6887e24
 
 
b3d8117
 
8e711d1
e022d18
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
34
35
36
37
38
# chain_recommendations.py
import json
from typing import Dict
from langchain import PromptTemplate, LLMChain
from models import chat_model

improved_recommend_prompt_template = PromptTemplate(
    input_variables=["problems"],
    template=(
        "You are a wellness recommendation assistant. Given the following problem severity percentages:\n"
        "{problems}\n\n"
        "Based on these percentages and the available wellness packages:\n"
        "1. Fitness & Mobility | Tagline: 'Enhance Mobility. Boost Fitness.'\n"
        "2. No More Insomnia | Deep Rest | Tagline: 'Reclaim Your Sleep. Restore Your Mind.'\n"
        "3. Focus Flow | Clarity Boost | Tagline: 'Stay Focused. Stay Productive.'\n"
        "4. Boost Energy | Tagline: 'Fuel Your Day. Boost Your Energy.'\n"
        "5. Chronic Care | Chronic Support | Tagline: 'Ongoing Support for Chronic Wellness.'\n"
        "6. Mental Wellness | Calm Mind | Tagline: 'Find Peace of Mind, Every Day.'\n\n"
        "Carefully analyze these percentages and consider nuanced differences between the areas. "
        "Your goal is to recommend the most appropriate wellness packages based on a detailed assessment of these numbers, "
        "not just fixed thresholds. Consider the following guidelines:\n\n"
        "- If one area is extremely high (above 70) while others are lower, prioritize a package targeting that area.\n"
        "- If multiple areas are high or near high (e.g., above 60), consider recommending multiple specialized packages or a comprehensive program.\n"
        "- If all areas are moderate (between 30 and 70), recommend a balanced wellness package that addresses overall health.\n"
        "- If all areas are low, a general wellness package might be sufficient.\n"
        "- Consider borderline cases and recommend packages that address both current issues and preventive measures.\n\n"
        "Return the recommended wellness packages in a JSON array format. "
        "Each item should be exactly one of the following package names: "
        "\"Fitness & Mobility\", \"No More Insomnia\", \"Focus Flow\", \"Boost Energy\", \"Chronic Care\", \"Mental Wellness\"."
    )
)

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

def generate_recommendations(problems: Dict[str, float]) -> str:
    recommendations = recommend_chain.run(problems=json.dumps(problems))
    return recommendations.strip()