AI_Assessment_Feature_1 / chain_recommendations.py
Phoenix21's picture
Update chain_recommendations.py
6887e24 verified
raw
history blame
2.43 kB
# 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()