CrewAI#
CrewAI is a popular AI framework used to create custom agent crews designed to perform a variety of tasks using large language models (LLMs).
Using the ImagineLLM
we can use the Imagine SDK with CrewAI
agents.
Pre-requisites#
Before running the example below, make sure that you install the Imagine SDK with CrewAI support.
Basic example#
The following example combines two agents: a researcher and a writer. The researcher is tasked with explaining what are the top 5 AI models and their specific applications. The writer is tasked with using the researcher output to write a blog post about it using markdown.
import os
from crewai import LLM, Agent, Crew, Process, Task
os.environ["OTEL_SDK_DISABLED"] = "true"
llm = LLM(model="openai/Llama-3.1-8B", base_url="", api_key="", max_tokens=1024)
research = Agent(
role="researcher",
goal="the goal of this agent is to research about new AI models and their applications",
backstory="this agent is a data scientist researcher and is interested in AI models",
verbose=True,
allow_delegation=False,
llm=llm,
max_retry_limit=2,
)
writer = Agent(
role="writer",
goal="the goal of this agent is to write about AI models and their applications",
backstory="this agent is a writer for a blog and is interested in AI models",
verbose=True,
allow_delegation=False,
llm=llm,
max_retry_limit=2,
)
task1 = Task(
description="research about new AI models and their applications",
agent=research,
expected_output="give a list of the top 5 AI models and their specific applications, do a short answer",
)
task2 = Task(
description="write about AI models and their applications",
agent=writer,
expected_output="a blog post with at least 3 main parts, in markdown format, use the list given by the researcher",
)
crew = Crew(
name="AI Models Crew",
agents=[research, writer],
tasks=[task1, task2],
verbose=True,
share_crew=False,
process=Process.sequential,
)
result = crew.kickoff()
print("-----------------------------")
print("Crew execution result:")
print("-----------------------------")
print(result)
This is a sample output for that code:
==================================================
Crew execution result:
==================================================
# Top 5 AI Models and Their Applications
In recent years, Artificial Intelligence (AI) has made tremendous progress, and various
AI models have been developed to solve complex problems. In this blog post, we will
explore the top 5 AI models and their specific applications.
### 1. Generative Adversarial Networks (GANs)
GANs are a type of AI model that uses a neural network to generate new data that is
similar to a given dataset. The model consists of two neural networks: a generator and
a discriminator. The generator creates new data, while the discriminator evaluates the
generated data and tells the generator whether it is realistic or not.
Applications:
* Image generation: GANs can be used to generate realistic images of objects, such as
faces, animals, and buildings.
* Data augmentation: GANs can be used to generate new data that is similar to a given
dataset, which can be used to train machine learning models.
* Style transfer: GANs can be used to transfer the style of one image to another
image.
### 2. Recurrent Neural Networks (RNNs)
RNNs are a type of AI model that is designed to process sequential data, such as speech,
text, and time series data. The model consists of a series of neural networks that are
connected in a loop, allowing the model to keep track of the context of the input data.
Applications:
* Language translation: RNNs can be used to translate text from one language to another.
* Speech recognition: RNNs can be used to recognize spoken language and transcribe it
into text.
* Time series forecasting: RNNs can be used to forecast future values in a time series
based on past values.
### 3. Convolutional Neural Networks (CNNs)
CNNs are a type of AI model that is designed to process data that is composed of grids
of values, such as images and videos. The model consists of a series of neural networks that are connected in a convolutional manner, allowing the model to extract features from the input data.
Applications:
* Image classification: CNNs can be used to classify images into different categories,
such as objects, scenes, and actions.
* Object detection: CNNs can be used to detect objects in images and videos.
* Image segmentation: CNNs can be used to segment images into different regions, such as
objects, textures, and backgrounds.
### 4. Transformers
Transformers are a type of AI model that is designed to process sequential data, such as
text and speech. The model consists of a series of neural networks that are connected in
a loop, allowing the model to keep track of the context of the input data.
Applications:
* Language translation: Transformers can be used to translate text from one language to
another.
* Text summarization: Transformers can be used to summarize long pieces of text into shorter
summaries.
* Question answering: Transformers can be used to answer questions based on a given
piece of text.
### 5. Autoencoders
Autoencoders are a type of AI model that is designed to learn a compact representation
of the input data. The model consists of an encoder and a decoder, which are connected
in a loop. The encoder maps the input data to a lower-dimensional representation, while
the decoder maps the lower-dimensional representation back to the original input data.
Applications:
* Dimensionality reduction: Autoencoders can be used to reduce the dimensionality of
high-dimensional data, such as images and videos.
* Generative modeling: Autoencoders can be used to generate new data that is similar to
a given dataset.
* Anomaly detection: Autoencoders can be used to detect anomalies in a dataset by
identifying data points that are farthest from the mean of the dataset.
In conclusion, the top 5 AI models and their specific applications have the potential
to revolutionize many industries and fields. These models have been used in a variety
of applications, including image generation, data augmentation, style transfer, language
translation, speech recognition, time series forecasting, image classification, object
detection, image segmentation, text summarization, question answering, anomaly
detection, dimensionality reduction, and generative modeling. As AI continues to evolve,
we can expect to see even more innovative applications of these models in the future.
Agents with tools#
We can also enable the integration of various tools with your agents.
For example, you can use the Exa Search Tool or simple tools to perform several tasks. For the following example install these dependencies:
And then execute:
import os
from crewai_tools import EXASearchTool, tool
from crewai import LLM, Agent, Crew, Process, Task
os.environ["OTEL_SDK_DISABLED"] = "true"
# https://docs.crewai.com/tools/exasearchtool
# You would have to set the API Key for ExaSearchTool
llm = LLM(model="openai/Llama-3.1-8B", base_url="", api_key="", max_tokens=1024)
@tool
def AdditionTool(a: int, b: int) -> str:
"""
can perform additions
"""
return a + b
@tool
def MultiplicationTool(a: int, b: int) -> str:
"""
can perform multiplications
"""
return a * b
research = Agent(
role="professor",
goal="the goal of this agent is to give the answer of basic calculus questions and history questions",
backstory="this agent is a professor for middle school student",
verbose=True,
allow_delegation=False,
llm=llm,
cache=True,
max_retry_limit=0,
tools=[EXASearchTool(), AdditionTool, MultiplicationTool],
)
task1 = Task(
description="what is the result of 9 + 12? what is the result of 3 * 4? what's the name of the first US president? what is the result of 12 * 7?",
agent=research,
expected_output="the answer of each question",
max_retry_limit=0,
)
crew = Crew(
name="AI Models Crew",
agents=[research],
tasks=[task1],
verbose=True,
share_crew=False,
process=Process.sequential,
)
result = crew.kickoff()
print("=" * 50)
print("Crew execution result:")
print("=" * 50)
print(result)
This would generate an output similar to:
==================================================
Crew execution result:
==================================================
The result of 9 + 12 is 21.
The result of 3 * 4 is 12.
The first US president was George Washington.
The result of 12 * 7 is 84.