Abhlash commited on
Commit
135e4fe
·
verified ·
1 Parent(s): c86dfa9

updated bot function

Browse files
Files changed (1) hide show
  1. bot/chat.py +38 -3
bot/chat.py CHANGED
@@ -72,13 +72,48 @@ def correct_year(response):
72
 
73
  async def bot(history):
74
  try:
75
- user_message = history[-1][0]
76
- # ... (rest of your existing code)
 
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  corrected_message = correct_year(bot_message)
79
  logger.info(f"Corrected message: {corrected_message}")
80
 
81
- # Update this line:
82
  return history + [(user_message, corrected_message)]
83
  except Exception as e:
84
  logger.error(f"Error in bot function: {str(e)}")
 
72
 
73
  async def bot(history):
74
  try:
75
+ user_message = history[-1][0].lower()
76
+ current_year = datetime.now().year
77
+ logger.info(f"Received message: {user_message}")
78
 
79
+ if "packing list" in user_message:
80
+ duration = 7 # Default duration
81
+ preferences = ["art", "music"] # Default preferences
82
+ transportation = "car" # Default transportation
83
+ packing_list = generate_packing_list(duration, preferences, transportation)
84
+ context = f"Here's a suggested packing list for your Burn: {', '.join(packing_list)}. Remember, radical self-reliance is key, but don't be afraid to ask your camp or neighbors if you forget something!"
85
+ bot_message = await chat_with_groq(f"Respond to a request for a packing list. Use this information, but phrase it in your own words and add your personal touch: {context}", history)
86
+ elif "principles" in user_message:
87
+ context = "The 10 Principles of Burning Man are: " + ", ".join(burning_man_principles.keys())
88
+ bot_message = await chat_with_groq(f"The user asked about the Burning Man principles. Explain them in a casual, friendly way, as if you're chatting at Center Camp. Use this for reference, but don't just list them: {context}", history)
89
+ elif "faq" in user_message:
90
+ context = "\n".join([f"Q: {q} A: {a}" for q, a in faq.items()])
91
+ bot_message = await chat_with_groq(f"The user asked about Burning Man FAQs. Use this information to answer in a friendly, conversational way: {context}", history)
92
+ elif "weather" in user_message:
93
+ weather_info = get_weather()
94
+ context = f"Current weather in Black Rock City: {weather_info}"
95
+ bot_message = await chat_with_groq(f"The user asked about the weather. Respond with this information, but add your personal touch and some advice: {context}", history)
96
+ elif "survival tips" in user_message:
97
+ context = "\n".join(survival_tips)
98
+ bot_message = await chat_with_groq(f"The user asked for survival tips. Share these tips in a friendly, experienced Burner way: {context}", history)
99
+ elif "date of the event" in user_message or "when is burning man" in user_message or "this year" in user_message:
100
+ logger.info("Fetching event dates...")
101
+ event_info = get_burning_man_dates()
102
+ logger.info(f"Event info: {event_info}")
103
+ bot_message = f"{event_info} It's going to be an amazing time on the playa! Are you excited?"
104
+ elif "what is this year" in user_message:
105
+ logger.info("Fetching event dates...")
106
+ event_info = get_burning_man_dates()
107
+ logger.info(f"Event info: {event_info}")
108
+ bot_message = f"Oh, dear playa pal! As far as the default world goes, it's the fabulous year of {current_year}! 🌟 And guess what? {event_info} Let's make the most of it!"
109
+ else:
110
+ bot_message = await chat_with_groq(user_message, history)
111
+
112
+ # Apply year correction to the bot's message
113
  corrected_message = correct_year(bot_message)
114
  logger.info(f"Corrected message: {corrected_message}")
115
 
116
+ # Update the history correctly
117
  return history + [(user_message, corrected_message)]
118
  except Exception as e:
119
  logger.error(f"Error in bot function: {str(e)}")