-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(integration): Crew AI youtube video analysis and query integration #444
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# CrewAI YouTube Query Integration with uAgents | ||
|
||
This project demonstrates the integration of CrewAI's capabilities to analyze YouTube video content with uAgents, enabling automated video content analysis and reporting. The system uses CrewAI to perform detailed analysis of YouTube videos based on user queries and utilizes uAgents to facilitate communication between agents. | ||
|
||
## Project Structure | ||
|
||
- **crewai_agent.py:** Main agent script that handles the YouTube video analysis using CrewAI. | ||
- **crewagents.py:** Defines the CrewAI agents used for analyzing YouTube content. | ||
- **user.py:** User agent script to interact with the main agent and submit YouTube video queries. | ||
- **tasks.py:** Defines the tasks for analyzing YouTube content. | ||
- **requirements.txt:** Lists the dependencies required for the project. | ||
|
||
## Setup Instructions | ||
|
||
### Prerequisites | ||
- Python 3.7 or later | ||
- pip (Python package installer) | ||
|
||
## Installation | ||
|
||
1. Clone the Repository | ||
|
||
```bash | ||
git clone https://github.com/fetchai/uAgents.git | ||
cd uAgents/integrations/Crewai-youtube-integration | ||
``` | ||
|
||
2. Create a virtual environment and activate it: | ||
|
||
```bash | ||
python3 -m venv venv | ||
source venv/bin/activate # On Windows: venv\Scripts\activate | ||
``` | ||
|
||
3. Install the dependencies: | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
|
||
## Running the Agents | ||
|
||
`Before running the agent please make sure to replace your seed phrases` | ||
|
||
**Step 1:** Run the Main Agent | ||
This agent handles the YouTube video analysis using CrewAI. | ||
|
||
```bash | ||
python3 crewai_agent.py | ||
``` | ||
|
||
**Step 2:** Run the User Agent | ||
This agent interacts with the main agent and submits YouTube video queries. | ||
Once you run the main agent take the agent address from the logs and replace it in user agent's code. | ||
|
||
```bash | ||
python3 user.py | ||
``` | ||
|
||
## Interacting with the Agents | ||
|
||
1. When you run the user.py script, it will prompt you to enter the YouTube video URL and the search query: | ||
|
||
```bash | ||
Provide the YouTube video URL (leave blank for general search): | ||
https://www.youtube.com/watch?v=bBThAij8Mqk | ||
What is the search query for the YouTube video content? | ||
``` | ||
|
||
2. The user agent sends this information to the main agent, which processes the video and returns the analysis results. | ||
|
||
## Expected Output: | ||
|
||
 | ||
 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from crewai import Agent | ||
from crewai_tools.tools import YoutubeVideoSearchTool | ||
|
||
class Agents(): | ||
def youtube_search_agent(self, youtube_video_url=None): | ||
if youtube_video_url: | ||
tool = YoutubeVideoSearchTool(youtube_video_url=youtube_video_url) | ||
else: | ||
tool = YoutubeVideoSearchTool() | ||
|
||
return Agent( | ||
role='YouTube Researcher', | ||
goal='Analyze YouTube video content to extract insights on relevant topics.', | ||
tools=[tool], | ||
backstory='Expert in analyzing YouTube videos to identify key information and insights.', | ||
verbose=True | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from dotenv import load_dotenv | ||
load_dotenv() | ||
|
||
from crewai import Crew | ||
from crewagents import Agents | ||
from tasks import Tasks | ||
import pydantic | ||
from uagents import Agent, Protocol, Context, Model | ||
from uagents.setup import fund_agent_if_low | ||
|
||
class YoutubeQuery(Model): | ||
youtube_video_url : str | ||
search_query : str | ||
|
||
class YoutubeResponse(Model): | ||
result: str | ||
|
||
agent = Agent( | ||
name = 'Youtube Query Agent', | ||
seed = '<Replace with your seed phrase>', | ||
port = 8000, | ||
endpoint = ['http://localhost:8000/submit'] | ||
) | ||
|
||
fund_agent_if_low(agent.wallet.address()) | ||
|
||
@agent.on_event('startup') | ||
async def agent_details(ctx: Context): | ||
ctx.logger.info(f'My agent address is: {agent.address}') | ||
|
||
|
||
async def crew_ai(youtube_video_url, search_query): | ||
agents = Agents() | ||
tasks = Tasks() | ||
|
||
youtube_search_agent = agents.youtube_search_agent(youtube_video_url) | ||
research_youtube_content_task = tasks.research_youtube_content_task(youtube_search_agent, search_query, youtube_video_url) | ||
|
||
# Instantiate the crew with a single agent and task | ||
crew = Crew( | ||
agents=[youtube_search_agent], | ||
tasks=[research_youtube_content_task] | ||
) | ||
|
||
# Kick off the process | ||
result = crew.kickoff() | ||
return result | ||
|
||
youtube_protocol = Protocol('Youtube Protocol') | ||
|
||
@youtube_protocol.on_message(model =YoutubeQuery, replies = {YoutubeResponse}) | ||
async def youtube_query(ctx: Context, sender: str, msg: YoutubeQuery): | ||
ctx.logger.info(f'User youtube url {msg.youtube_video_url} and query is {msg.search_query}') | ||
result = await crew_ai(msg.youtube_video_url, msg.search_query) | ||
ctx.logger.info(result) | ||
await ctx.send(sender, YoutubeResponse(result = str(result))) | ||
|
||
agent.include(youtube_protocol, publish_manifest=True) | ||
|
||
if __name__ == "__main__": | ||
agent.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
python-dotenv==1.0.1 | ||
crewai==0.14.3 | ||
uagents==0.12.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uagents latest version is 0.14.0 |
||
crewai-tools | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. crewai-tools==0.4.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from textwrap import dedent | ||
from crewai import Task | ||
|
||
class Tasks(): | ||
def research_youtube_content_task(self, agent, search_query, youtube_video_url=None): | ||
if youtube_video_url: | ||
description = dedent(f"""\ | ||
Analyze the YouTube video at {youtube_video_url} for the search query: "{search_query}". Focus on extracting insights, key points, and relevant information presented in the video. | ||
Compile a report summarizing these insights and how they can be applied to the specific context of the job posting.""") | ||
else: | ||
description = dedent(f"""\ | ||
Perform a general search on YouTube for the query: "{search_query}". Identify relevant videos and extract key insights, points, and information from them. | ||
Compile a report summarizing these insights and how they can be applied to the specific context of the job posting.""") | ||
|
||
return Task( | ||
description=description, | ||
expected_output=dedent("""\ | ||
A comprehensive report detailing the insights, key points, and relevant information extracted from the YouTube video(s). Suggestions on incorporating these insights into the job posting should be included."""), | ||
agent=agent | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from uagents import Agent, Protocol, Context, Model | ||
from uagents.setup import fund_agent_if_low | ||
|
||
class YoutubeQuery(Model): | ||
youtube_video_url : str | ||
search_query : str | ||
|
||
class YoutubeResponse(Model): | ||
result: str | ||
|
||
agent = Agent( | ||
name = 'User Agent', | ||
seed = '<Replace with your seed phrase>', | ||
port = 8001, | ||
endpoint = ['http://localhost:8001/submit'] | ||
) | ||
|
||
fund_agent_if_low(agent.wallet.address()) | ||
|
||
address = '<Replace this with your crewai_agent>' | ||
|
||
@agent.on_event('startup') | ||
async def agent_details(ctx: Context): | ||
youtube_video_url = input("Provide the YouTube video URL (leave blank for general search):\n") | ||
search_query = input("What is the search query for the YouTube video content?\n") | ||
await ctx.send(address, YoutubeQuery(youtube_video_url=youtube_video_url,search_query=search_query )) | ||
ctx.logger.info(f'My agent address is: {agent.address}') | ||
|
||
youtube_protocol = Protocol('Youtube Protocol') | ||
|
||
@youtube_protocol.on_message(model =YoutubeResponse) | ||
async def youtube_query(ctx: Context, sender: str, msg: YoutubeResponse): | ||
ctx.logger.info(f'Results by the user {msg.result}') | ||
|
||
agent.include(youtube_protocol, publish_manifest=True) | ||
|
||
if __name__ == "__main__": | ||
agent.run() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap the YouTube query processing in a try-except block to handle any errors gracefully.