Replace ChatGPT with Google Gemini
This commit is contained in:
46
README.md
46
README.md
@@ -1,10 +1,10 @@
|
||||
# TweetBot - AI-Powered Twitter Bot
|
||||
|
||||
An automated Twitter bot that generates and posts tweets using OpenAI's ChatGPT API. This Java application allows you to create engaging social media content with custom prompts.
|
||||
An automated Twitter bot that generates and posts tweets using Google Gemini's free API. This Java application allows you to create engaging social media content with custom prompts.
|
||||
|
||||
## Features
|
||||
|
||||
- Generate tweet content using ChatGPT (GPT-3.5-turbo)
|
||||
- Generate tweet content using Google Gemini (gemini-2.0-flash-exp) - **Free Tier**
|
||||
- **Three operation modes:**
|
||||
- Interactive mode with manual approval
|
||||
- Auto-post mode for one-time tweets
|
||||
@@ -22,17 +22,24 @@ An automated Twitter bot that generates and posts tweets using OpenAI's ChatGPT
|
||||
|
||||
- Java 17 or higher
|
||||
- Maven 3.6 or higher
|
||||
- OpenAI API key
|
||||
- Google Gemini API key (free tier available)
|
||||
- Twitter Developer Account with API credentials
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
### 1. Get OpenAI API Key
|
||||
### 1. Get Google Gemini API Key (Free)
|
||||
|
||||
1. Go to [OpenAI Platform](https://platform.openai.com/)
|
||||
2. Sign up or log in to your account
|
||||
3. Navigate to API keys section
|
||||
4. Create a new API key and save it securely
|
||||
1. Go to [Google AI Studio](https://aistudio.google.com/app/apikey)
|
||||
2. Sign in with your Google account
|
||||
3. Click "Create API Key"
|
||||
4. Select or create a Google Cloud project
|
||||
5. Copy the API key and save it securely
|
||||
|
||||
**Note:** The free tier of Google Gemini includes:
|
||||
- 15 requests per minute
|
||||
- 1 million tokens per minute
|
||||
- 1,500 requests per day
|
||||
- More than enough for a tweet bot!
|
||||
|
||||
### 2. Get Twitter API Credentials
|
||||
|
||||
@@ -44,7 +51,6 @@ An automated Twitter bot that generates and posts tweets using OpenAI's ChatGPT
|
||||
- API Secret (Consumer Secret)
|
||||
- Access Token
|
||||
- Access Token Secret
|
||||
- Bearer Token
|
||||
|
||||
**Important:** Ensure your Twitter app has **Read and Write** permissions:
|
||||
- Go to your app settings
|
||||
@@ -60,12 +66,11 @@ An automated Twitter bot that generates and posts tweets using OpenAI's ChatGPT
|
||||
|
||||
2. Edit `.env` and add your API credentials:
|
||||
```
|
||||
OPENAI_API_KEY=sk-your-openai-api-key-here
|
||||
GEMINI_API_KEY=your-gemini-api-key-here
|
||||
TWITTER_API_KEY=your-twitter-api-key
|
||||
TWITTER_API_SECRET=your-twitter-api-secret
|
||||
TWITTER_ACCESS_TOKEN=your-twitter-access-token
|
||||
TWITTER_ACCESS_TOKEN_SECRET=your-twitter-access-token-secret
|
||||
TWITTER_BEARER_TOKEN=your-twitter-bearer-token
|
||||
TWEET_PROMPT=Write a short, engaging tweet about technology trends
|
||||
IMAGE_PATH=/path/to/your/image.jpg
|
||||
```
|
||||
@@ -80,7 +85,7 @@ An automated Twitter bot that generates and posts tweets using OpenAI's ChatGPT
|
||||
- Supported formats: JPEG, PNG, GIF
|
||||
- Maximum file size: 5MB (Twitter limit)
|
||||
|
||||
### 5. Build the Project
|
||||
### 4. Build the Project
|
||||
|
||||
```bash
|
||||
mvn clean package
|
||||
@@ -216,7 +221,7 @@ tweetbot/
|
||||
│ ├── config/
|
||||
│ │ └── Config.java # Configuration loader
|
||||
│ └── service/
|
||||
│ ├── OpenAIService.java # ChatGPT integration
|
||||
│ ├── GeminiService.java # Google Gemini integration
|
||||
│ └── TwitterService.java # Twitter API integration
|
||||
└── resources/
|
||||
└── logback.xml # Logging configuration
|
||||
@@ -228,12 +233,11 @@ tweetbot/
|
||||
|
||||
| Variable | Required | Description |
|
||||
|----------|----------|-------------|
|
||||
| `OPENAI_API_KEY` | Yes | Your OpenAI API key |
|
||||
| `GEMINI_API_KEY` | Yes | Your Google Gemini API key (free tier available) |
|
||||
| `TWITTER_API_KEY` | Yes | Twitter API Key (Consumer Key) |
|
||||
| `TWITTER_API_SECRET` | Yes | Twitter API Secret (Consumer Secret) |
|
||||
| `TWITTER_ACCESS_TOKEN` | Yes | Twitter Access Token |
|
||||
| `TWITTER_ACCESS_TOKEN_SECRET` | Yes | Twitter Access Token Secret |
|
||||
| `TWITTER_BEARER_TOKEN` | Yes | Twitter Bearer Token |
|
||||
| `TWEET_PROMPT` | No | Default prompt for tweet generation |
|
||||
| `IMAGE_PATH` | No | Path to image file to attach to every tweet (jpg, png, gif) |
|
||||
|
||||
@@ -371,9 +375,10 @@ Ensure your `.env` file exists and contains all required variables.
|
||||
|
||||
### "Failed to generate tweet"
|
||||
|
||||
1. Verify your OpenAI API key is valid
|
||||
2. Check that you have sufficient API credits
|
||||
1. Verify your Gemini API key is valid
|
||||
2. Check that you're within the free tier rate limits (15 RPM, 1500 RPD)
|
||||
3. Review the error message in logs
|
||||
4. Ensure your Google Cloud project is properly configured
|
||||
|
||||
### Twitter API Rate Limits
|
||||
|
||||
@@ -385,9 +390,7 @@ Twitter API has rate limits:
|
||||
|
||||
## Dependencies
|
||||
|
||||
- **Twitter API Java SDK** (2.0.3) - Twitter API client
|
||||
- **OpenAI GPT-3 Java** (0.18.2) - OpenAI API client
|
||||
- **OkHttp** (4.12.0) - HTTP client
|
||||
- **OkHttp** (4.12.0) - HTTP client for API requests
|
||||
- **Jackson** (2.16.1) - JSON processing
|
||||
- **SLF4J & Logback** (2.0.9) - Logging
|
||||
- **Dotenv** (3.0.0) - Environment variable management
|
||||
@@ -406,7 +409,6 @@ private static final int SCHEDULE_INTERVAL_MINUTES = 30; // Change this value
|
||||
|
||||
### Other Enhancement Ideas
|
||||
|
||||
- Add support for images and media attachments
|
||||
- Implement tweet threading for longer content
|
||||
- Add sentiment analysis before posting
|
||||
- Create multiple prompt templates with rotation
|
||||
@@ -429,4 +431,4 @@ For issues or questions:
|
||||
1. Check the troubleshooting section
|
||||
2. Review application logs in `tweetbot.log`
|
||||
3. Verify API credentials and permissions
|
||||
4. Check Twitter and OpenAI API status pages
|
||||
4. Check Twitter and Google AI Studio status pages
|
||||
|
||||
Reference in New Issue
Block a user