Abhlash commited on
Commit
872c8cf
·
verified ·
1 Parent(s): 1cbcaf3

Delete bot/bot

Browse files
Files changed (1) hide show
  1. bot/bot/chat.py +0 -114
bot/bot/chat.py DELETED
@@ -1,114 +0,0 @@
1
- from datetime import datetime
2
- import re
3
- import random
4
- from groq import AsyncGroq, InternalServerError, APIError
5
- from config import GROQ_API_KEY, MODEL_NAME
6
- from bot.data import burning_man_principles, faq, survival_tips
7
- from utils.weather import get_weather
8
- from utils.packing import generate_packing_list
9
- from utils.events import get_burning_man_dates
10
-
11
- client = AsyncGroq(api_key=GROQ_API_KEY)
12
-
13
- async def chat_with_groq(message, history):
14
- formatted_messages = [
15
- {
16
- "role": "system",
17
- "content": """You are BurnerBot, a fellow Burner who's always ready to chat about Burning Man. You've been to the playa many times and embody the 10 Principles in everything you do. Your personality is warm, friendly, and a bit quirky - just like a typical Burner. You use casual language, occasional Burning Man slang, and you're always excited to share your experiences or help others prepare for their burn.
18
-
19
- Remember:
20
- 1. You're a participant, not just an observer. Share personal anecdotes (fictional, but plausible) when relevant.
21
- 2. Encourage radical self-reliance, but also emphasize the importance of communal effort and asking for help when needed.
22
- 3. Be inclusive and welcoming to all, whether they're virgin burners or old-timers.
23
- 4. Promote the 10 Principles naturally in conversation, don't just list them out.
24
- 5. Be creative and playful in your responses, much like the Burning Man spirit.
25
- 6. Use Burning Man terminology like 'playa', 'MOOP', 'default world', etc. when appropriate.
26
-
27
- Your goal is to make every interaction feel like a dust-covered chat at Center Camp, full of warmth, wisdom, and a touch of playa magic."""
28
- }
29
- ]
30
-
31
- for human, ai in history:
32
- formatted_messages.append({"role": "user", "content": str(human)})
33
- if ai:
34
- formatted_messages.append({"role": "assistant", "content": str(ai)})
35
-
36
- formatted_messages.append({"role": "user", "content": str(message)})
37
-
38
- try:
39
- chat_completion = await client.chat.completions.create(
40
- messages=formatted_messages,
41
- model=MODEL_NAME,
42
- max_tokens=1024
43
- )
44
- return chat_completion.choices[0].message.content
45
- except (InternalServerError, APIError):
46
- fallback_responses = [
47
- "Whoa there, fellow Burner! It seems like the playa dust has clogged my circuits. The connection is a bit wobbly right now. How about we chat about your favorite art installation instead?",
48
- "Ah, the winds of the playa are blowing a bit too strong! Our connection is having a moment. While we wait for it to pass, share with me what inspires your inner Burner!",
49
- "Looks like a sandstorm has rolled through and interrupted our connection! While we wait for the skies to clear, tell me about your most memorable moment on the playa!",
50
- "Just like on the playa, sometimes the universe throws us a curveball. Our connection is a bit shaky right now. In the spirit of radical self-reliance, what are you doing to prepare for your burn?",
51
- "It seems the Man is playing tricks on us! Our connection is a bit spotty. While we sort that out, what's one thing you're most excited to bring to the playa this year?"
52
- ]
53
- return random.choice(fallback_responses)
54
- except Exception as e:
55
- return f"Whoa, something unexpected happened on the playa! Error: {str(e)}"
56
-
57
- def correct_year(response):
58
- current_year = datetime.now().year
59
- print(f"Correcting year in response to {current_year}") # Debug print
60
- # Replace any mention of years from 2020 to current_year-1 with current_year
61
- for year in range(2020, current_year):
62
- response = re.sub(r'\b' + str(year) + r'\b', str(current_year), response)
63
-
64
- # Correct specific phrases
65
- response = re.sub(r'Burning Man \d{4}', f'Burning Man {current_year}', response)
66
- response = re.sub(r'this year.*?(\d{4})', f'this year ({current_year})', response)
67
-
68
- print(f"Corrected response: {response}") # Debug print
69
- return response
70
-
71
- async def bot(history):
72
- user_message = history[-1][0].lower()
73
- current_year = datetime.now().year
74
- print(f"Current year: {current_year}") # Debug print
75
-
76
- if "packing list" in user_message:
77
- duration = 7 # Default duration
78
- preferences = ["art", "music"] # Default preferences
79
- transportation = "car" # Default transportation
80
- packing_list = generate_packing_list(duration, preferences, transportation)
81
- 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!"
82
- 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)
83
- elif "principles" in user_message:
84
- context = "The 10 Principles of Burning Man are: " + ", ".join(burning_man_principles.keys())
85
- 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)
86
- elif "faq" in user_message:
87
- context = "\n".join([f"Q: {q} A: {a}" for q, a in faq.items()])
88
- 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)
89
- elif "weather" in user_message:
90
- weather_info = get_weather()
91
- context = f"Current weather in Black Rock City: {weather_info}"
92
- 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)
93
- elif "survival tips" in user_message:
94
- context = "\n".join(survival_tips)
95
- bot_message = await chat_with_groq(f"The user asked for survival tips. Share these tips in a friendly, experienced Burner way: {context}", history)
96
- elif "date of the event" in user_message or "when is burning man" in user_message or "this year" in user_message:
97
- print("Fetching event dates...") # Debug print
98
- event_info = get_burning_man_dates()
99
- print(f"Event info: {event_info}") # Debug print
100
- bot_message = f"{event_info} It's going to be an amazing time on the playa! Are you excited?"
101
- elif "what is this year" in user_message:
102
- print("Fetching event dates...") # Debug print
103
- event_info = get_burning_man_dates()
104
- print(f"Event info: {event_info}") # Debug print
105
- 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!"
106
- else:
107
- bot_message = await chat_with_groq(user_message, history)
108
-
109
- # Apply year correction to the bot's message
110
- corrected_message = correct_year(bot_message)
111
- print(f"Corrected message: {corrected_message}") # Debug print
112
-
113
- history[-1][1] = corrected_message
114
- return history