diff --git a/python/examples/quickstarters/content_hook_generator_agent/.env.example b/python/examples/quickstarters/content_hook_generator_agent/.env.example new file mode 100644 index 00000000000..a023b4614a7 --- /dev/null +++ b/python/examples/quickstarters/content_hook_generator_agent/.env.example @@ -0,0 +1,3 @@ +COMPOSIO_API_KEY=KEY +GROQ_API_KEY=KEY +OPENAI_API_KEY=KEY \ No newline at end of file diff --git a/python/examples/quickstarters/content_hook_generator_agent/main.py b/python/examples/quickstarters/content_hook_generator_agent/main.py new file mode 100644 index 00000000000..75c2d0863e1 --- /dev/null +++ b/python/examples/quickstarters/content_hook_generator_agent/main.py @@ -0,0 +1,46 @@ +import os +import dotenv +from composio_llamaindex import App, ComposioToolSet +from llama_index.core.agent import FunctionCallingAgentWorker +from llama_index.core.llms import ChatMessage +from llama_index.llms.openai import OpenAI +from llama_index.llms.groq import Groq + +dotenv.load_dotenv() +composio_toolset = ComposioToolSet() +tools = composio_toolset.get_tools(apps=[App.GOOGLESHEETS]) + +sheet_id = '1fVAkbBVeocPIPRMgaH-rO2kkswXWLUBVSZ8jf-xputs' +#llm = Groq(model="llama3-70b-8192", api_key=os.environ['GROQ_API_KEY']) +llm = Groq( + +) + +prefix_messages = [ + ChatMessage( + role="system", + content=( + "You are an Content Hook Generator Agent." + "First scrape the google spreadsheet info" + "You have access to a google sheet that is a database of Hook Lines with metrics and categories" + "The user will describe their content to you and you'll look at this sheet to find the perfect hookline and tailor it to the usecase." + ), + ) +] + +while True: + main_task = input("Describe your content (or type 'exit' to quit): ") + if main_task.lower() == 'exit': + break + + agent = FunctionCallingAgentWorker( + tools=tools, + llm=llm, + prefix_messages=prefix_messages, + max_function_calls=10, + allow_parallel_tool_calls=False, + verbose=True, + ).as_agent() + + response = agent.chat(f"This is the content: {main_task}, the sheet id is {sheet_id}. Figure out the best hookline by using the tools available to you. Rephrase the content idea to match the spreadsheet content.") + print("Response:", response) \ No newline at end of file diff --git a/python/examples/quickstarters/content_hook_generator_agent/readme.md b/python/examples/quickstarters/content_hook_generator_agent/readme.md new file mode 100644 index 00000000000..a31c7c87554 --- /dev/null +++ b/python/examples/quickstarters/content_hook_generator_agent/readme.md @@ -0,0 +1,30 @@ +# Perplexity for Hackernews Agent Guide + +This guide provides detailed steps to create an agent that searches relevant hackernews posts, it leverages LlamaIndex, Composio, and Groq to perform searches. Ensure you have Python 3.8 or higher installed. + +## Steps to Run +**Navigate to the Project Directory:** +Change to the directory where the `setup.sh`, `main.py`, `requirements.txt`, and `README.md` files are located. For example: +```sh +cd path/to/project/directory +``` + +### 1. Run the Setup File +Make the setup.sh Script Executable (if necessary): +On Linux or macOS, you might need to make the setup.sh script executable: +```shell +chmod +x setup.sh +``` +Execute the setup.sh script to set up the environment, install dependencies, login to composio and +add necessary tools: +```shell +./setup.sh +``` +Now, Fill in the .env file with your secrets. +### 2. Run the python script +```shell +python cookbook/examples/quickstarters/perplexity_for_hackernews/main.py +``` + + + diff --git a/python/examples/quickstarters/content_hook_generator_agent/requirements.txt b/python/examples/quickstarters/content_hook_generator_agent/requirements.txt new file mode 100644 index 00000000000..0c7e783094f --- /dev/null +++ b/python/examples/quickstarters/content_hook_generator_agent/requirements.txt @@ -0,0 +1,2 @@ +composio-llamaindex +llama-index-llms-groq diff --git a/python/examples/quickstarters/content_hook_generator_agent/setup.sh b/python/examples/quickstarters/content_hook_generator_agent/setup.sh new file mode 100644 index 00000000000..a9294ac88c1 --- /dev/null +++ b/python/examples/quickstarters/content_hook_generator_agent/setup.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Create a virtual environment +echo "Creating virtual environment..." +python3 -m venv ~/.venvs/content + +# Activate the virtual environment +echo "Activating virtual environment..." +source ~/.venvs/content/bin/activate + +# Install libraries from requirements.txt +echo "Installing libraries from requirements.txt..." +pip install -r requirements.txt + +# Copy env backup to .env file +if [ -f ".env.example" ]; then + echo "Copying .env.example to .env..." + cp .env.example .env +else + echo "No .env.example file found. Creating a new .env file..." + touch .env +fi + +# Prompt user to fill the .env file +echo "Please fill in the .env file with the necessary environment variables." + +echo "Setup completed successfully!" \ No newline at end of file