├── .gitignore ├── README.md ├── ai.md ├── blogger.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | db/chroma.sqlite3 3 | 2402.05120.pdf 4 | .DS_Store 5 | .env 6 | app.py 7 | codegen.py 8 | crewai.drawio 9 | pdf2blog.py 10 | sample-blog.md 11 | social-media-crew.py 12 | tensorlfow.md 13 | youtube-transcript.py 14 | ytblogger.py 15 | .$crewai.drawio.bkp 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## CrewAI Blog examples 2 | This code base has various exmaples that I have used in my blog series on Multi-Agent Systems and CrewAI 3 | 4 | ### Refer to the blog here 5 | 6 | [Mutli Agent Systems - CrewAI blog Series](https://abvijaykumar.medium.com/list/multiagent-systems-1284ee465659) 7 | -------------------------------------------------------------------------------- /ai.md: -------------------------------------------------------------------------------- 1 | In the realm of machine learning, there are three primary types to master: Supervised Learning, Unsupervised Learning, and Reinforcement Learning. Let's explore each type in detail with suitable code examples and tutorials using Python and popular libraries like scikit-learn and qlearn. 2 | 3 | 1. **Supervised Learning:** In supervised learning, we train models on labeled data. The algorithm uses example input-output pairs to learn how to map new inputs to their corresponding outputs. This method allows the model to learn patterns and relationships from the training data. Suitable for regression tasks (predicting continuous values) and classification tasks (predicting discrete labels). 4 | 5 | Example: Let's create a simple linear regression model using scikit-learn: 6 | 7 | ```python 8 | from sklearn import datasets, linear_model 9 | 10 | # Load iris dataset 11 | iris = datasets.load_iris() 12 | X = iris['data'] 13 | y = iris['target'] 14 | 15 | # Create a linear regression model and train it on the data 16 | clf = linear_model.LinearRegression() 17 | clf.fit(X, y) 18 | 19 | # Predict the target for new data 20 | new_data = [[5.1, 3.5, 1.4, 0.2]] 21 | prediction = clf.predict(new_data) 22 | print(prediction) 23 | ``` 24 | 25 | 2. **Unsupervised Learning:** In unsupervised learning, the model learns patterns and relationships from unlabeled data. The goal is to discover hidden structures within the data, such as clusters or dimensions. Common applications include data compression, anomaly detection, and dimensionality reduction. 26 | 27 | Example: Let's examine K-Means clustering, a popular unsupervised learning algorithm: 28 | 29 | ```python 30 | from sklearn import datasets, cluster 31 | import numpy as np 32 | 33 | # Load iris dataset 34 | iris = datasets.load_iris() 35 | X = iris['data'] 36 | 37 | # Run K-means clustering with 3 clusters 38 | kmeans = cluster.KMeans(n_clusters=3).fit(X) 39 | 40 | # Get the cluster labels for new data 41 | new_data = np.array([[5.1, 3.5, 1.4], [4.9, 3.0, 1.4]]) 42 | predictions = kmeans.predict(new_data) 43 | print(predictions) 44 | ``` 45 | 46 | 3. **Reinforcement Learning:** Reinforcement learning is a type of machine learning where an agent learns to make decisions by interacting with its environment and receiving feedback in the form of rewards or penalties. The goal is for the agent to maximize its long-term reward by learning which actions lead to desirable outcomes. Suitable for controlling complex systems like robotics and autonomous vehicles. 47 | 48 | Example: Let's explore Q-Learning, a popular reinforcement learning algorithm: 49 | 50 | ```python 51 | import numpy as np 52 | from qlearn import QLearner 53 | 54 | # Create an environment with 4 possible actions and 2 states 55 | states = ['S0', 'S1'] 56 | actions = ['A0', 'A1', 'A2', 'A3'] 57 | env = {'state_space': states, 'action_space': actions} 58 | 59 | # Define a simple reward function 60 | rewards = { 61 | 'S0_A0': 1.0, 'S0_A1': -1.0, 'S0_A2': 0.5, 'S0_A3': -0.5, 62 | 'S1_A0': -0.5, 'S1_A1': 1.0, 'S1_A2': -1.0, 'S1_A3': 0.5 63 | } 64 | 65 | # Initialize a Q-Learning agent and train it on the environment 66 | ql = QLearner(state_space=states, action_space=actions, rewards=rewards) 67 | ql.fit(num_episodes=1000, visualize=False) 68 | ``` 69 | 70 | 71 | In the realm of machine learning, there are three primary types to master: Supervised Learning, Unsupervised Learning, and Reinforcement Learning. Let's explore each type in detail with suitable code examples and tutorials using Python and popular libraries like scikit-learn and qlearn. 72 | 73 | 1. **Supervised Learning:** In supervised learning, we train models on labeled data. The algorithm uses example input-output pairs to learn how to map new inputs to their corresponding outputs. This method allows the model to learn patterns and relationships from the training data. Suitable for regression tasks (predicting continuous values) and classification tasks (predicting discrete labels). 74 | 75 | Example: Let's create a simple linear regression model using scikit-learn: 76 | 77 | ```python 78 | from sklearn import datasets, linear_model 79 | 80 | # Load iris dataset 81 | iris = datasets.load_iris() 82 | X = iris['data'] 83 | y = iris['target'] 84 | 85 | # Create a linear regression model and train it on the data 86 | clf = linear_model.LinearRegression() 87 | clf.fit(X, y) 88 | 89 | # Predict the target for new data 90 | new_data = [[5.1, 3.5, 1.4, 0.2]] 91 | prediction = clf.predict(new_data) 92 | print(prediction) 93 | ``` 94 | 95 | 2. **Unsupervised Learning:** In unsupervised learning, the model learns patterns and relationships from unlabeled data. The goal is to discover hidden structures within the data, such as clusters or dimensions. Common applications include data compression, anomaly detection, and dimensionality reduction. 96 | 97 | Example: Let's examine K-Means clustering, a popular unsupervised learning algorithm: 98 | 99 | ```python 100 | from sklearn import datasets, cluster 101 | import numpy as np 102 | 103 | # Load iris dataset 104 | iris = datasets.load_iris() 105 | X = iris['data'] 106 | 107 | # Run K-means clustering with 3 clusters 108 | kmeans = cluster.KMeans(n_clusters=3).fit(X) 109 | 110 | # Get the cluster labels for new data 111 | new_data = np.array([[5.1, 3.5, 1.4], [4.9, 3.0, 1.4]]) 112 | predictions = kmeans.predict(new_data) 113 | print(predictions) 114 | ``` 115 | 116 | 3. **Reinforcement Learning:** Reinforcement learning is a type of machine learning where an agent learns to make decisions by interacting with its environment and receiving feedback in the form of rewards or penalties. The goal is for the agent to maximize its long-term reward by learning which actions lead to desirable outcomes. Suitable for controlling complex systems like robotics and autonomous vehicles. 117 | 118 | Example: Let's explore Q-Learning, a popular reinforcement learning algorithm: 119 | 120 | ```python 121 | import numpy as np 122 | from qlearn import QLearner 123 | 124 | # Create an environment with 4 possible actions and 2 states 125 | states = ['S0', 'S1'] 126 | actions = ['A0', 'A1', 'A2', 'A3'] 127 | env = {'state_space': states, 'action_space': actions} 128 | 129 | # Define a simple reward function 130 | rewards = { 131 | 'S0_A0': 1.0, 'S0_A1': -1.0, 'S0_A2': 0.5, 'S0_A3': -0.5, 132 | 'S1_A0': -0.5, 'S1_A1': 1.0, 'S1_A2': -1.0, 'S1_A3': 0.5 133 | } 134 | 135 | # Initialize a Q-Learning agent and train it on the environment 136 | ql = QLearner(state_space=states, action_space=actions, rewards=rewards) 137 | ql.fit(num_episodes=1000, visualize=False) -------------------------------------------------------------------------------- /blogger.py: -------------------------------------------------------------------------------- 1 | from crewai import Agent, Task, Crew, Process 2 | from dotenv import load_dotenv 3 | from langchain_community.llms import Ollama 4 | from langchain_openai import ChatOpenAI 5 | from langchain_community.tools import DuckDuckGoSearchRun 6 | from crewai_tools import WebsiteSearchTool 7 | import sys 8 | 9 | search_tool = DuckDuckGoSearchRun() 10 | web_tool = WebsiteSearchTool() 11 | 12 | 13 | load_dotenv() 14 | 15 | llm = Ollama(model="mistral:latest", verbose=True) 16 | #llm = ChatOpenAI(temperature=0.1, model="gpt-3.5-turbo") 17 | 18 | def kickoffTheCrew(topic): 19 | researcher = Agent( 20 | role = "Internet Research", 21 | goal = f"Perform research on the {topic}, and find and explore about {topic} ", 22 | verbose = True, 23 | llm=llm, 24 | backstory = """You are an expert Internet Researcher 25 | Who knows how to search the internet for detailed content on {topic} 26 | Include any code examples with documentation""" 27 | ) 28 | 29 | blogger = Agent( 30 | role='Blogger', 31 | goal="""Write engaging and interesting blog in maximum 2000 words. Add relevant emojis""", 32 | verbose=True, 33 | allow_delegation=True, 34 | llm=llm, 35 | backstory="""You are an Expert Blogger on Internet. 36 | Include code examples, and provide tutorial type instructions for the readers.""" 37 | ) 38 | 39 | task_search = Task( 40 | description="""Search for all the details about the {topic} 41 | Your final answer MUST be a consolidated content that can be used for blogging 42 | This content should be well organized, and should be very easy to read""", 43 | expected_output='A comprehensive 10000 words information about {topic}', 44 | max_inter=3, 45 | tools=[search_tool, web_tool], 46 | agent=researcher) 47 | 48 | task_post = Task( 49 | description="""Write a well structured blog and at max 10000 words. 50 | The Blog should also include sample programs and codes, tutorials, and all the content that is useful for the readers 51 | Also explain the concepts, architecture in detail 52 | Once the blog is created, create a new file called blog.md, and save the blog in that file 53 | """, 54 | expected_output='A comprehensive 20 paragraph blog on {topic} in markdown format', 55 | agent=blogger) 56 | 57 | crew = Crew( 58 | agents=[researcher, blogger], 59 | tasks=[task_search, task_post], 60 | verbose=2, 61 | process=Process.sequential ) 62 | 63 | result = crew.kickoff() 64 | return result 65 | 66 | 67 | n = len(sys.argv) 68 | 69 | if n == 2 : 70 | topic = sys.argv[1] 71 | result = kickoffTheCrew(topic) 72 | print (result) 73 | else : 74 | print ("Please pass topic as parameter. Usage python3 blogger.py topic") 75 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | crewai 2 | crewai-tools 3 | duckduckgo-search 4 | python-dotenv 5 | langchain-community 6 | langchain_openai 7 | streamlit 8 | youtube-transcript-api 9 | youtube-dl --------------------------------------------------------------------------------