This project is a LINE bot that uses Google's Vertex AI Gemini models through LangChain to generate responses to both text and image inputs. The bot can answer questions in Traditional Chinese and provide detailed descriptions of images.
- Text message processing using Gemini AI in Traditional Chinese
- Image analysis with scientific detail in Traditional Chinese
- Integration with LINE Messaging API for easy mobile access
- Built with FastAPI for efficient asynchronous processing
- Python 3
- FastAPI
- LINE Messaging API
- Google Vertex AI (Gemini 2.0 Flash)
- LangChain
- Aiohttp
- PIL (Python Imaging Library)
-
Clone the repository to your local machine.
-
Set up Google Cloud:
- Create a Google Cloud project
- Enable Vertex AI API
- Set up authentication (service account or application default credentials)
-
Set the following environment variables:
ChannelSecret
: Your LINE channel secretChannelAccessToken
: Your LINE channel access tokenGOOGLE_PROJECT_ID
: Your Google Cloud Project IDGOOGLE_LOCATION
: Google Cloud region (default: us-central1)- Optional:
GOOGLE_APPLICATION_CREDENTIALS
: Path to service account key file (if running locally)
-
Install the required dependencies:
pip install -r requirements.txt
-
Start the FastAPI server:
uvicorn main:app --reload
-
Set up your LINE bot webhook URL to point to your server's endpoint.
Send any text message to the LINE bot, and it will use Vertex AI's Gemini model to generate a response in Traditional Chinese.
Send an image to the bot, and it will analyze and describe the image with scientific detail in Traditional Chinese.
Use ngrok or similar tools to expose your local server to the internet for webhook access:
-
Install the Google Cloud SDK and authenticate with your Google Cloud account.
-
Build the Docker image:
gcloud builds submit --tag gcr.io/$GOOGLE_PROJECT_ID/linebot-gemini
-
Deploy the Docker image to Cloud Run:
gcloud run deploy linebot-gemini --image gcr.io/$GOOGLE_PROJECT_ID/linebot-gemini --platform managed --region $GOOGLE_LOCATION --allow-unauthenticated
-
Set up your LINE bot webhook URL to point to the Cloud Run service URL.