| | import json |
| | import os |
| |
|
| | |
| | PREFERENCES_FILE = "user_preferences.json" |
| |
|
| | |
| | def load_preferences(): |
| | if os.path.exists(PREFERENCES_FILE): |
| | with open(PREFERENCES_FILE, "r") as file: |
| | return json.load(file) |
| | return {} |
| |
|
| | def save_preferences(preferences): |
| | with open(PREFERENCES_FILE, "w") as file: |
| | json.dump(preferences, file, indent=4) |
| |
|
| | |
| | user_preferences = load_preferences() |
| |
|
| | |
| | def get_user_preferences(user_id): |
| | return user_preferences.get(user_id, {"name": None, "style": None}) |
| |
|
| | |
| | def update_user_preferences(user_id, name=None, style=None): |
| | if user_id not in user_preferences: |
| | user_preferences[user_id] = {} |
| | if name: |
| | user_preferences[user_id]["name"] = name |
| | if style: |
| | user_preferences[user_id]["style"] = style |
| | save_preferences(user_preferences) |
| |
|
| | |
| | def generate_advice(user_style, user_name): |
| | advice_pool = { |
| | "gentleness": f"{user_name}, remember that progress takes time. Be kind to yourself as you grow.", |
| | "tough love": f"Listen, {user_name}, no excuses! You’ve got what it takes—so get to it!", |
| | "words of affirmation": f"You’re amazing, {user_name}. Believe in yourself; you’re capable of incredible things.", |
| | } |
| | return advice_pool.get(user_style, "I'm here to support you in the way that works best for you!") |
| |
|
| | |
| | def wellness_bot_response(user_id, user_input): |
| | preferences = get_user_preferences(user_id) |
| | if not preferences["name"] or not preferences["style"]: |
| | |
| | if not preferences["name"]: |
| | preferences["name"] = user_input |
| | update_user_preferences(user_id, name=preferences["name"]) |
| | return f"Hi {preferences['name']}! What motivational style do you prefer? (e.g., gentleness, tough love, words of affirmation)" |
| | elif not preferences["style"]: |
| | preferences["style"] = user_input.lower() |
| | update_user_preferences(user_id, style=preferences["style"]) |
| | return f"Got it, {preferences['name']}! I’ll use a {preferences['style']} approach from now on. How can I support you today?" |
| | else: |
| | |
| | advice = generate_advice(preferences["style"], preferences["name"]) |
| | return f"{advice}\nLet me know if there’s anything specific on your mind!" |
| |
|
| | |
| | if __name__ == "__main__": |
| | user_id = "user123" |
| | print(wellness_bot_response(user_id, "Alice")) |
| | print(wellness_bot_response(user_id, "gentleness")) |
| | print(wellness_bot_response(user_id, "I need help staying motivated.")) |
| |
|