Overview:
This script automates customer support email responses for SkyeBrowse using Google Gemini and context documents from Google Drive.
- Input: Takes a customer inquiry either via a command-line argument (
-i) or through an interactive prompt if no argument is given. Typing 'q' quits the interactive prompt. - Context Preparation:
- Fetches Google Drive file IDs from environment variables (prefixed with
GDRIVE_). - If the
-dflag is used or local files are missing, it authenticates with the Google Drive API (usingcredentials.jsonandtoken.json), downloads specified files, and exports Google Docs/Sheets to text/CSV format respectively, saving them in a localdrive/directory. - If the
-dflag is not used and local files exist indrive/, it uses those files. - Uploads the prepared local files (downloaded or pre-existing) to the Google GenAI API for context.
- Fetches Google Drive file IDs from environment variables (prefixed with
- Response Generation:
- Initializes the Google GenAI client using an API key from the
.envfile. - Constructs a prompt for the Gemini model (
gemini-2.0-flashspecified in the code), including a system instruction (defining the persona as a SkyeBrowse support specialist) and the user's inquiry, along with the uploaded context files. - Sends the request to the Gemini API and streams the response back.
- Initializes the Google GenAI client using an API key from the
- Output:
- Prints the generated email response to the console in real-time as it streams.
- After generation, displays a summary including the time taken and token usage (prompt, candidates, total) if available from the API metadata.
- Looping: Continues to prompt for new inquiries until the user quits.
- Clone the repository:
git clone https://github.com/bobbyohyeah/skyebot-support cd skyebot-support - Install dependencies (tested on python 3.11):
python -m venv venv source venv/bin/activate pip install -r requirements.txt - Google Drive Credentials:
- Enable the Google Drive API in your Google Cloud Console.
- Create OAuth 2.0 Client ID credentials (Desktop app type).
- Download the credentials JSON file and save it as
credentials.jsonin the project's root directory.
- Gemini API Key:
- Obtain an API key for Google Gemini (e.g., from Google AI Studio).
- Create a file named
.envin the project's root directory. - Add your API key to the
.envfile:GEMINI_API_KEY=YOUR_API_KEY_HERE
- First Run & Authentication:
- When you run the script for the first time (
python main.py), it will attempt to authenticate with Google Drive. - Your web browser should open, prompting you to authorize the application.
- Upon successful authorization, a
token.jsonfile will be created in the root directory. This file stores your access tokens.
- When you run the script for the first time (
Options:
-i,--inquiry "Your customer inquiry text": Provide the customer inquiry directly via the command line. If omitted, the script will prompt you interactively.-d,--download: Force the script to download/update files from Google Drive. If omitted, the script will look for existing files in thedrive/directory first.
Examples:
-
Run interactively, using local files if available:
python main.py
(You will be prompted to enter the inquiry.)
-
Run interactively, forcing download from Google Drive:
python main.py -d
-
Provide inquiry directly, using local files if available:
python main.py -i "How do I reset my password?" -
Provide inquiry directly, forcing download from Google Drive:
python main.py -d -i "What are the system requirements for SkyeBrowse?"
Exiting: Type q and press Enter at the interactive prompt to quit.
The required Python packages are listed in requirements.txt. Key dependencies include:
google-api-python-clientgoogle-auth-oauthlibgoogle-genaipython-dotenv
(See requirements.txt for the complete list of dependencies and specific versions.)
credentials.json: Your downloaded Google Cloud OAuth 2.0 credentials. Required for Google Drive API access.token.json: Stores Google Drive API access and refresh tokens after successful authorization. Automatically generated/updated..env: Stores yourGEMINI_API_KEYand other files to download from Google Drive. The Google Drive files are the url of it, so the file athttps://docs.google.com/document/d/1yRAq8aqxiOcQGkZ6hHv-xdZffZ2KPIGihmekzjKsyA0/edit?tab=t.0would be reflected as1yRAq8aqxiOcQGkZ6hHv-xdZffZ2KPIGihmekzjKsyA0.drive/: Directory where Google Drive context files are downloaded (if using the-dflag or if they exist locally).