Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OPENAI_API_KEY=your_openai_api_key_here
ELEVENLABS_API_KEY=your_elevenlabs_api_key_here
TWITTER_CONSUMER_KEY=your_twitter_consumer_key_here
TWITTER_CONSUMER_SECRET=your_twitter_consumer_secret_here
TWITTER_ACCESS_TOKEN=your_twitter_access_token_here
TWITTER_ACCESS_TOKEN_SECRET=your_twitter_access_token_secret_here
ZAPIER_NLA_API_KEY=your_zapier_api_key_here
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,33 @@ You need to obtain API keys for the following services:
1. Twitter Developer Account (for Tweepy)
2. OpenAI API key
3. Zapier NLA API key
4. ElevenLabs API key

Replace the placeholders in the code with the respective API keys:
Copy the `.env.example` file to `.env` and fill in your API keys:

```python
consumer_key = "<CONSUMER_KEY>"
consumer_secret = "<CONSUMER_SECRET>"
access_token = "<ACCESS_TOKEN>"
access_token_secret = "<ACCESS_TOKEN_SECRET>"
```bash
OPENAI_API_KEY=your_openai_api_key_here
ELEVENLABS_API_KEY=your_elevenlabs_api_key_here
TWITTER_CONSUMER_KEY=your_twitter_consumer_key_here
TWITTER_CONSUMER_SECRET=your_twitter_consumer_secret_here
TWITTER_ACCESS_TOKEN=your_twitter_access_token_here
TWITTER_ACCESS_TOKEN_SECRET=your_twitter_access_token_secret_here
ZAPIER_NLA_API_KEY=your_zapier_api_key_here
```

```python
set_api_key("<11LABS_API_KEY>")
openai.api_key = "<OPENAI_API_KEY>"
```
Replace `your_*_api_key_here` with your actual API keys.

```python
zapier = ZapierNLAWrapper(zapier_nla_api_key="<ZAPIER_NLA_API_KEY>")
```
**Important**:
1. Never commit your API keys to version control. The `.env` file is already in `.gitignore` to prevent accidental commits.
2. If you see an error like "Did not find openai_api_key", it means your environment variables are not properly set. Make sure you've created the `.env` file and filled in all the required API keys.

## Running the program

1. Save the provided code in a file named `main.py`.
1. Copy the example environment file and fill in your API keys:
```bash
cp .env.example .env
# Edit .env with your actual API keys
```
2. Open a terminal or command prompt and navigate to the folder containing `main.py`.
3. Run the program using the following command:

Expand Down
57 changes: 39 additions & 18 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@
from elevenlabs import generate, play, set_api_key
from langchain.agents import initialize_agent, load_tools
from langchain.agents.agent_toolkits import ZapierToolkit
from langchain.llms import OpenAI
from langchain_openai import OpenAI
from langchain.memory import ConversationBufferMemory
from langchain.tools import BaseTool
from langchain.utilities.zapier import ZapierNLAWrapper


set_api_key("<11LABS_API_KEY>")
openai.api_key = "<OPENAI_API_KEY>"
from dotenv import load_dotenv
load_dotenv()

elevenlabs_api_key = os.getenv('ELEVENLABS_API_KEY')
if not elevenlabs_api_key:
raise ValueError("Please set ELEVENLABS_API_KEY environment variable")
set_api_key(elevenlabs_api_key)

openai.api_key = os.getenv('OPENAI_API_KEY')
if not openai.api_key:
raise ValueError("Please set OPENAI_API_KEY environment variable")

# Set recording parameters
duration = 5 # duration of each recording in seconds
Expand Down Expand Up @@ -49,16 +58,19 @@ def play_generated_audio(text, voice="Bella", model="eleven_monolingual_v1"):
play(audio)


# Replace with your API keys
consumer_key = "<CONSUMER_KEY>"
consumer_secret = "<CONSUMER_SECRET>"
access_token = "<ACCESS_TOKEN>"
access_token_secret = "<ACCESS_TOKEN_SECRET>"
# Get Twitter API credentials from environment variables
consumer_key = os.getenv('TWITTER_CONSUMER_KEY')
consumer_secret = os.getenv('TWITTER_CONSUMER_SECRET')
access_token = os.getenv('TWITTER_ACCESS_TOKEN')
access_token_secret = os.getenv('TWITTER_ACCESS_TOKEN_SECRET')

client = tweepy.Client(
consumer_key=consumer_key, consumer_secret=consumer_secret,
access_token=access_token, access_token_secret=access_token_secret
)
if all([consumer_key, consumer_secret, access_token, access_token_secret]):
client = tweepy.Client(
consumer_key=consumer_key, consumer_secret=consumer_secret,
access_token=access_token, access_token_secret=access_token_secret
)
else:
print("Warning: Twitter API credentials not fully configured. Twitter posting will not be available.")


class TweeterPostTool(BaseTool):
Expand All @@ -79,12 +91,21 @@ async def _arun(self, query: str) -> str:
llm = OpenAI(temperature=0)
memory = ConversationBufferMemory(memory_key="chat_history")

zapier = ZapierNLAWrapper(zapier_nla_api_key="<ZAPIER_NLA_API_KEY>")
toolkit = ZapierToolkit.from_zapier_nla_wrapper(zapier)

# tools = [TweeterPostTool()] + toolkit.get_tools() + load_tools(["human"])

tools = toolkit.get_tools() + load_tools(["human"])
zapier_api_key = os.getenv('ZAPIER_NLA_API_KEY')
if zapier_api_key:
zapier = ZapierNLAWrapper(zapier_nla_api_key=zapier_api_key)
toolkit = ZapierToolkit.from_zapier_nla_wrapper(zapier)
tools = toolkit.get_tools()
else:
print("Warning: Zapier NLA API key not configured. Zapier integration will not be available.")
tools = []

# Add Twitter tool if credentials are configured
if all([consumer_key, consumer_secret, access_token, access_token_secret]):
tools.append(TweeterPostTool())

# Always add human tools
tools.extend(load_tools(["human"]))

agent = initialize_agent(tools, llm, memory=memory, agent="conversational-react-description", verbose=True)

Expand Down
16 changes: 16 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from dotenv import load_dotenv
from langchain_openai import OpenAI
import os

load_dotenv()

# Verify API key is loaded
api_key = os.getenv('OPENAI_API_KEY')
if not api_key:
raise ValueError("OPENAI_API_KEY not found in environment variables")
print(f"API key found: {api_key[:5]}...")

# Test OpenAI integration
llm = OpenAI(temperature=0)
result = llm.invoke("Say hello!")
print(f"OpenAI response: {result}")