9.2 KiB
How-To Guide: Setting up ARAI AI, Google Gemini, and Twitter
This guide walks you through the essential steps for installing ARAI AI Agents in a conda environment, configuring the Google Gemini API key, and authenticating a Twitter account for agent interactions. We also detail how environment variables are managed via a .env
file using python-dotenv
.
Table of Contents
- Set Up a Conda Environment
- Install ARAI AI Agents
- Obtain a Google Gemini API Key
- Get a Twitter API Key
- Authenticate Your Twitter Account
- Debug Mode
- Processing Speed & Wait Times
- Next Steps
- Troubleshooting
1. Set Up a Conda Environment
Conda environments keep dependencies isolated and help avoid conflicts with other projects on your system.
-
Install or Update Conda
-
Create a New Environment
- In your terminal or Anaconda Prompt, run:
conda create --name arai_ai_agents python=3.11
- Activate your new environment:
conda activate arai_ai_agents
- In your terminal or Anaconda Prompt, run:
You now have an isolated environment ready for ARAI AI Agents.
2. Install ARAI AI Agents
- Clone the Repository
git clone https://github.com/arai-ai/arai_ai_agents.git
- Navigate to the Project Directory
cd arai_ai_agents
- Install Dependencies
Within yourarai_ai_agents
folder, install the required packages:pip install -r requirements.txt
- Run the Main Script
This starts the primary ARAI AI Agents application, which includes agent configurations, connectors, and any prompt-chaining logic.python main.py
3. Obtain a Google Gemini API Key
(Note: The steps below are illustrative. Refer to Google’s official documentation for the most up-to-date instructions.)
-
Sign Up or Log In
- Go to Google Cloud Console.
-
Create a New Project (if needed)
- Click Select a project → New Project. Give it a name, then create it.
-
Enable the Gemini API
- Navigate to APIs & Services → Library.
- Search for Gemini API (or equivalent) and enable it.
-
Create Credentials
- Under APIs & Services → Credentials, click + CREATE CREDENTIALS → API key.
- Copy the API key (e.g.,
AIzaSyD...
).
-
Set the Environment Variable
- Either place it in your system environment:
export GEMINI_API_KEY="AIzaSyD..."
- Or place the key in your
.env
file at the root of the project:GOOGLE_GEMINI_API_KEY=AIzaSyD...
- Either place it in your system environment:
(ARAI uses python-dotenv
to automatically load variables from .env
if configured.)
4. Get a Twitter API Key
To allow ARAI AI Agents to interact with Twitter, you need developer credentials.
-
Apply for a Twitter Developer Account
- Go to the Twitter Developer Portal and apply for a Developer account.
-
Create a Project & App
- Once approved, create a Project, then create an App within that project.
-
Generate Keys & Tokens
- Under Keys and tokens, generate an API Key, API Secret Key, and Bearer Token (or OAuth 2.0 Client if required).
- Copy these values somewhere secure.
Example .env
variables:
TWITTER_API_KEY=xxxxxxxxxxxxxxxxxxx
TWITTER_API_SECRET=yyyyyyyyyyyyyyyyyyyyyyyyy
TWITTER_BEARER_TOKEN=AAAAAAAAAAAAAAAAAAAAAAA
5. Authenticate Your Twitter Account
ARAI AI Agents includes modules or scripts (e.g., twitter_app_auth.py
) to handle Twitter OAuth or token-based authentication. Below is a typical approach:
-
Load Environment Variables
Make sure you havepython-dotenv
installed and your.env
file in the project root. For example:from dotenv import load_dotenv load_dotenv() # This will load your .env variables
-
Locate the Auth File
-
In
arai_ai_agents/auth/twitter_app_auth.py
(or a similar file):import os from dotenv import load_dotenv load_dotenv() # ensures environment variables are loaded TWITTER_API_KEY = os.getenv("TWITTER_API_KEY") TWITTER_API_SECRET = os.getenv("TWITTER_API_SECRET") TWITTER_BEARER_TOKEN = os.getenv("TWITTER_BEARER_TOKEN") # Additional OAuth logic, if needed
-
-
Set Your Credentials
- Store your credentials in a
.env
file or environment variables. The code snippet above automatically pulls from your environment.
- Store your credentials in a
-
Run the App
- When you run
python main.py
, the application will attempt to initialize theTwitterConnector
(if configured), using your environment variables.
- When you run
-
Test Connectivity
-
Use the connector or a test script to verify you can post or retrieve tweets.
-
Example:
from arai_ai_agents.connectors.twitter_connector import TwitterConnector import os connector = TwitterConnector( api_key=os.getenv("TWITTER_API_KEY"), api_secret=os.getenv("TWITTER_API_SECRET"), bearer_token=os.getenv("TWITTER_BEARER_TOKEN") ) connector.test_connection()
-
-
Twitter Access Tokens
- To post on behalf of a user, you will need access tokens for the specific Twitter account.
- The
twitter_app_auth.py
file may contain a function to fetch or handle these tokens. - Save your access tokens in the
.env
file:TWITTER_ACCESS_TOKEN=XXXXXXXX TWITTER_ACCESS_TOKEN_SECRET=YYYYYYYY
-
Enable Twitter Live Mode
- Set
twitter_live = True
in themain.py
file so you can post to Twitter live:twitter_live = True
- Once successfully authenticated, your ARAI agents can interact with Twitter—posting tweets, reading mentions, or replying to DMs, depending on your configuration.
- Set
6. Debug Mode
By default, posting to Twitter is disabled so you can see generated tweets in log files without actually publishing. This is by design so that you can test AI output before using real APIs:
- Log-Only Mode
The system logs tweets to ayaml
file, typically located atconfigs/agent_folder/agentName_post_log.yaml
. - Trial Run
Check this file to verify the AI is generating appropriate, non-repetitive content. - Switch to Live
Once you’re satisfied, enabletwitter_live = True
to start posting live.
7. Processing Speed & Wait Times
Depending on your prompt complexity, ARAI AI may take a few minutes to generate a response—especially if the agent is creating long-form or multiple pieces of content. The system is waiting for the LLM (e.g., Google Gemini) to process and return a detailed answer.
- CLI Feedback
Keep an eye on your command-line interface (CLI). You’ll see logging messages that indicate whether the agent is still running or if an error occurs. - Batch Generation
If you’re generating content in batches (e.g., multiple tweets or entire episodes), expect longer wait times as the AI compiles all required context. - Crash Handling
If the CLI exits unexpectedly or logs an error, it’s likely that the model or process has crashed. You can check the logs for details and rerun once you’ve addressed the issue.
Reminder: The more context (characters, episodes, story arcs) we include, the more time the model may need to process your request.
8. Next Steps
- Using ARAI with Other Models: Check out the API Reference Documentation for integrating additional LLMs like OpenAI or Anthropic.
- Setting Up Additional Connectors: See our How-To Guides for adding Discord, Slack, or Telegram connectors.
- Managing Prompts & Templates: Explore the Prompt Reference for advanced usage of prompt chaining and template customization.
9. Troubleshooting
-
Conda Environment Not Found
Ensure you spelled the environment name correctly or re-runconda activate arai_ai_agents
. -
Credential Errors
Double-check environment variables are set in your.env
or system variables. Make sure you restart the shell if you updated.env
. -
Authentication Failures
Validate your Google or Twitter keys/tokens in their respective developer dashboards.
If you run into any issues, feel free to open an Issue.
That’s it! You’ve now set up your environment, installed ARAI AI Agents, obtained the necessary API keys, and authenticated your Twitter account. Remember that complex or large-scale AI tasks may take a bit longer to generate responses, so don’t worry if you see some delay—it’s just the model crafting detailed content.
Happy building with ARAI AI Agents!