updated chat
Browse files- bot/chat.py +12 -14
bot/chat.py
CHANGED
@@ -2,11 +2,11 @@ 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
|
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 |
|
@@ -57,18 +57,16 @@ async def chat_with_groq(message, history):
|
|
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 |
-
|
72 |
user_message = history[-1][0].lower()
|
73 |
current_year = datetime.now().year
|
74 |
print(f"Current year: {current_year}") # Debug print
|
@@ -79,20 +77,20 @@ async def bot(history):
|
|
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 =
|
83 |
elif "principles" in user_message:
|
84 |
context = "The 10 Principles of Burning Man are: " + ", ".join(burning_man_principles.keys())
|
85 |
-
bot_message =
|
86 |
elif "faq" in user_message:
|
87 |
context = "\n".join([f"Q: {q} A: {a}" for q, a in faq.items()])
|
88 |
-
bot_message =
|
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 =
|
93 |
elif "survival tips" in user_message:
|
94 |
context = "\n".join(survival_tips)
|
95 |
-
bot_message =
|
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()
|
@@ -104,7 +102,7 @@ async def bot(history):
|
|
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 =
|
108 |
|
109 |
# Apply year correction to the bot's message
|
110 |
corrected_message = correct_year(bot_message)
|
|
|
2 |
import re
|
3 |
import random
|
4 |
from groq import AsyncGroq, InternalServerError, APIError
|
5 |
+
from ..config import GROQ_API_KEY, MODEL_NAME
|
6 |
+
from .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 |
|
|
|
57 |
def correct_year(response):
|
58 |
current_year = datetime.now().year
|
59 |
print(f"Correcting year in response to {current_year}") # Debug print
|
|
|
60 |
for year in range(2020, current_year):
|
61 |
response = re.sub(r'\b' + str(year) + r'\b', str(current_year), response)
|
62 |
|
|
|
63 |
response = re.sub(r'Burning Man \d{4}', f'Burning Man {current_year}', response)
|
64 |
response = re.sub(r'this year.*?(\d{4})', f'this year ({current_year})', response)
|
65 |
|
66 |
print(f"Corrected response: {response}") # Debug print
|
67 |
return response
|
68 |
|
69 |
+
def bot(history):
|
70 |
user_message = history[-1][0].lower()
|
71 |
current_year = datetime.now().year
|
72 |
print(f"Current year: {current_year}") # Debug print
|
|
|
77 |
transportation = "car" # Default transportation
|
78 |
packing_list = generate_packing_list(duration, preferences, transportation)
|
79 |
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!"
|
80 |
+
bot_message = 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)
|
81 |
elif "principles" in user_message:
|
82 |
context = "The 10 Principles of Burning Man are: " + ", ".join(burning_man_principles.keys())
|
83 |
+
bot_message = 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)
|
84 |
elif "faq" in user_message:
|
85 |
context = "\n".join([f"Q: {q} A: {a}" for q, a in faq.items()])
|
86 |
+
bot_message = chat_with_groq(f"The user asked about Burning Man FAQs. Use this information to answer in a friendly, conversational way: {context}", history)
|
87 |
elif "weather" in user_message:
|
88 |
weather_info = get_weather()
|
89 |
context = f"Current weather in Black Rock City: {weather_info}"
|
90 |
+
bot_message = chat_with_groq(f"The user asked about the weather. Respond with this information, but add your personal touch and some advice: {context}", history)
|
91 |
elif "survival tips" in user_message:
|
92 |
context = "\n".join(survival_tips)
|
93 |
+
bot_message = chat_with_groq(f"The user asked for survival tips. Share these tips in a friendly, experienced Burner way: {context}", history)
|
94 |
elif "date of the event" in user_message or "when is burning man" in user_message or "this year" in user_message:
|
95 |
print("Fetching event dates...") # Debug print
|
96 |
event_info = get_burning_man_dates()
|
|
|
102 |
print(f"Event info: {event_info}") # Debug print
|
103 |
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!"
|
104 |
else:
|
105 |
+
bot_message = chat_with_groq(user_message, history)
|
106 |
|
107 |
# Apply year correction to the bot's message
|
108 |
corrected_message = correct_year(bot_message)
|