Created
November 6, 2025 15:32
-
-
Save Suave101/25c76ebfc46e07b247811b1a7abe8258 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import asyncio | |
| import google.generativeai as genai | |
| # Load API | |
| genai.configure(api_key="YOUR_API_KEY") | |
| # In-memory "database" for the symposium | |
| ROSTER = { | |
| "Dr. Sid", | |
| "Parth", | |
| "Hafeez", | |
| "Candice" | |
| } | |
| ATTENDANCE_DB = { | |
| "present": set(), | |
| "absent": set() | |
| } | |
| def check_in(name: str): | |
| """ | |
| Marks an attendee as 'present'. | |
| Args: | |
| name: The full name of the attendee to check in. | |
| """ | |
| print(f"\n[SYSTEM: Running function check_in(name='{name}')]") | |
| if name in ROSTER: | |
| ATTENDANCE_DB["present"].add(name) | |
| if name in ATTENDANCE_DB["absent"]: | |
| ATTENDANCE_DB["absent"].remove(name) | |
| return f"Success: {name} is now marked as present." | |
| else: | |
| return f"Error: {name} is not on the official roster. Cannot check in." | |
| def mark_absent(name: str): | |
| """ | |
| Marks a known attendee as 'absent'. | |
| Args: | |
| name: The full name of the attendee to mark as absent. | |
| """ | |
| print(f"\n[SYSTEM: Running function mark_absent(name='{name}')]") | |
| if name in ROSTER: | |
| ATTENDANCE_DB["absent"].add(name) | |
| if name in ATTENDANCE_DB["present"]: | |
| ATTENDANCE_DB["present"].remove(name) | |
| return f"Success: {name} is now marked as absent." | |
| else: | |
| return f"Error: {name} is not on the official roster." | |
| def get_attendance_report(): | |
| """ | |
| Returns a full report of who is present, absent, and not yet checked in. | |
| """ | |
| print("\n[SYSTEM: Running function get_attendance_report()]") | |
| # Calculate who is still pending (on roster but not in present/absent sets) | |
| pending = ROSTER - ATTENDANCE_DB["present"] - ATTENDANCE_DB["absent"] | |
| return { | |
| "present": list(ATTENDANCE_DB["present"]), | |
| "explicitly_absent": list(ATTENDANCE_DB["absent"]), | |
| "pending_check_in": list(pending) | |
| } | |
| async def main(): | |
| """ | |
| Main function to run the chat client. | |
| """ | |
| print("--- Gemini Attendance Bot ---") | |
| print("Your Python functions are loaded as tools.") | |
| print("Type 'quit' or 'exit' to end the chat.\n") | |
| # List of all Python functions we want Gemini to control | |
| gemini_tools = [check_in, mark_absent, get_attendance_report] | |
| # Initialize the Gemini model, telling it about our tools | |
| model = genai.GenerativeModel( | |
| model_name='gemini-2.5-flash', | |
| tools=gemini_tools | |
| ) | |
| # Start a chat session with automatic function calling enabled | |
| chat_session = model.start_chat( | |
| enable_automatic_function_calling=True | |
| ) | |
| while True: | |
| try: | |
| # Get input from the user (this is the "host platform") | |
| user_message = input("You: ") | |
| if user_message.lower() in ["quit", "exit"]: | |
| print("\nBot: Goodbye!") | |
| break | |
| # Send the user's message to Gemini | |
| response = await chat_session.send_message_async(user_message) | |
| print("Bot: ", end="") | |
| # Print the final text all at once. | |
| print(response.text) | |
| print() # Add a newline | |
| except Exception as e: | |
| print(f"\nAn error occurred: {e}") | |
| break | |
| # Run the Host Server | |
| await main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment