diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..486aa50 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,33 @@ +{ + "name": "Python 3", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm", + "customizations": { + "codespaces": { + "openFiles": [ + "README.md", + "sessions/session-01-ai-chatbots/starter-template/chatbot.py" + ] + }, + "vscode": { + "settings": {}, + "extensions": [ + "ms-python.python", + "ms-python.vscode-pylance" + ] + } + }, + "updateContentCommand": "[ -f packages.txt ] && sudo apt update && sudo apt upgrade -y && sudo xargs apt install -y =0.3.0 +google-cloud-aiplatform>=1.26.0 +vertexai>=0.1.0 python-dotenv>=1.0.0 streamlit>=1.28.0 +requests>=2.31.0 # ============================================================================ # Optional: Alternative Platforms (Uncomment to use) diff --git a/sessions/session-01-ai-chatbots/starter-template/app.py b/sessions/session-01-ai-chatbots/starter-template/app.py new file mode 100644 index 0000000..4d4666c --- /dev/null +++ b/sessions/session-01-ai-chatbots/starter-template/app.py @@ -0,0 +1,45 @@ +import streamlit as st +import json +from chatbot import SimpleBot + +st.set_page_config(page_title="WCC Info Bot", page_icon="🤖") + +st.title("🤖 WCC Info Bot") +st.markdown("Ask me anything about Women Coding Community!") + +# Load FAQs +with open("wcc_faqs.json") as f: + wcc_data = json.load(f) + +faq_text = "\n".join([ + f"Q: {faq['question']}\nA: {faq['answer']}" + for faq in wcc_data["faqs"] +]) + +system_prompt = f"""You are a friendly WCC assistant... +{faq_text}""" + +# Initialize bot +if "bot" not in st.session_state: + st.session_state.bot = SimpleBot(system_prompt=system_prompt) + +if "messages" not in st.session_state: + st.session_state.messages = [] + +# Display chat history +for message in st.session_state.messages: + with st.chat_message(message["role"]): + st.markdown(message["content"]) + +# Chat input +if user_input := st.chat_input("Ask me about WCC..."): + st.session_state.messages.append({"role": "user", "content": user_input}) + + with st.chat_message("user"): + st.markdown(user_input) + + response = st.session_state.bot.chat(user_input) + st.session_state.messages.append({"role": "assistant", "content": response}) + + with st.chat_message("assistant"): + st.markdown(response) \ No newline at end of file diff --git a/sessions/session-01-ai-chatbots/starter-template/chatbot.py b/sessions/session-01-ai-chatbots/starter-template/chatbot.py index 09cc5fa..f2e845b 100644 --- a/sessions/session-01-ai-chatbots/starter-template/chatbot.py +++ b/sessions/session-01-ai-chatbots/starter-template/chatbot.py @@ -11,7 +11,7 @@ load_dotenv() # Configure Gemini API -API_KEY = os.getenv("GEMINI_API_KEY") +API_KEY ="AIzaSyBbKBVBiiMuQzfI8CSiIqC02bNXJ_1-nI0" if not API_KEY: raise ValueError( "GEMINI_API_KEY not found in environment variables. " @@ -115,3 +115,37 @@ def main(): if __name__ == "__main__": main() +import json + +# Load WCC FAQs +with open("wcc_faqs.json") as f: + wcc_data = json.load(f) + +# Create FAQ context +faq_text = "\n".join([ + f"Q: {faq['question']}\nA: {faq['answer']}" + for faq in wcc_data["faqs"] +]) + +# Create system prompt with WCC knowledge +system_prompt = f"""You are Maya, the enthusiastic WCC assistant! +You love helping women in tech and are passionate about community. +Always be encouraging and supportive. +Use emojis occasionally to add warmth and supportiveness. +Also be kind and inclusive in your responses. + +Here are the FAQs you should reference: +{faq_text} + +Be warm, encouraging, and inclusive. If you don't know something, suggest they contact the WCC team. +""" + +import logging + +logging.basicConfig(filename='chatbot.log', level=logging.INFO) + +def log_conversation(user_msg, bot_response): + logging.info(f"User: {user_msg}") + logging.info(f"Bot: {bot_response}") + +bot = SimpleBot(system_prompt=system_prompt) \ No newline at end of file diff --git a/sessions/session-01-ai-chatbots/starter-template/scraper.py b/sessions/session-01-ai-chatbots/starter-template/scraper.py new file mode 100644 index 0000000..2c8f31c --- /dev/null +++ b/sessions/session-01-ai-chatbots/starter-template/scraper.py @@ -0,0 +1,37 @@ +import requests +from bs4 import BeautifulSoup +import json + +def scrape_wcc_events(): + """Scrape upcoming events from WCC website""" + # Replace with actual WCC website URL + url = "https://womencoding.community/events" + + try: + response = requests.get(url) + soup = BeautifulSoup(response.content, 'html.parser') + + events = [] + for event in soup.find_all('div', class_='event'): + events.append({ + "title": event.find('h3').text, + "date": event.find('span', class_='date').text, + "description": event.find('p').text + }) + + return events + except Exception as e: + print(f"Error scraping: {e}") + return [] + +# Use in chatbot +events = scrape_wcc_events() +events_text = "\n".join([ + f"- {e['title']} on {e['date']}: {e['description']}" + for e in events +]) + +system_prompt = f"""You are a WCC assistant. +Upcoming events: +{events_text} +""" \ No newline at end of file diff --git a/sessions/session-01-ai-chatbots/starter-template/test_bot.py b/sessions/session-01-ai-chatbots/starter-template/test_bot.py new file mode 100644 index 0000000..46bea86 --- /dev/null +++ b/sessions/session-01-ai-chatbots/starter-template/test_bot.py @@ -0,0 +1,18 @@ +from chatbot import SimpleBot + +def test_wcc_bot(): + bot = SimpleBot(system_prompt="You are a WCC assistant.") + + # Test basic response + response = bot.chat("What is WCC?") + assert len(response) > 0 + + # Test conversation memory + bot.chat("I'm interested in AI") + response = bot.chat("Can you recommend a session?") + assert "AI" in response or "session" in response.lower() + + print("✅ All tests passed!") + +if __name__ == "__main__": + test_wcc_bot() \ No newline at end of file diff --git a/sessions/session-01-ai-chatbots/starter-template/wcc_faqs.json b/sessions/session-01-ai-chatbots/starter-template/wcc_faqs.json new file mode 100644 index 0000000..0bf8996 --- /dev/null +++ b/sessions/session-01-ai-chatbots/starter-template/wcc_faqs.json @@ -0,0 +1,20 @@ +{ + "faqs": [ + { + "question": "What is WCC?", + "answer": "Women Coding Community is a global community of women in tech..." + }, + { + "question": "How do I join WCC?", + "answer": "Visit our website and sign up for free..." + }, + { + "question": "When are the sessions?", + "answer": "Sessions are held every other Wednesday at 7 PM EST..." + }, + { + "question": "Can I volunteer?", + "answer": "Absolutely! We're always looking for volunteers..." + } + ] +} \ No newline at end of file