Crew AI LinkedIn Post Creator

parmarjatin4911@gmail.com - Jan 28 - - Dev Community

*Crew AI LinkedIn Post Creator *

pip install langchain-community langchain crewai langchain-openai langchain-core langchain-google-vertexai langchain_mistralai
export MISTRAL_API_KEY=xxxxxxx
export AZURE_OPENAI_DEPLOYMENT=xxxxx
export AZURE_OPENAI_ENDPOINT=https://.openai.azure.com/
export AZURE_OPENAI_KEY=xxxxxxxxxx

import os
from crewai import Agent, Task, Crew, Process
from langchain_mistralai.chat_models import ChatMistralAI
from langchain_google_vertexai import VertexAI
from langchain_openai import AzureChatOpenAI
from langchain.tools import DuckDuckGoSearchRun
search_tool = DuckDuckGoSearchRun()

mistral_api_key = os.environ.get("MISTRAL_API_KEY")
llm_mistral = ChatMistralAI(mistral_api_key=mistral_api_key, model="mistral-medium")
llm_vertex = VertexAI(model_name="gemini-pro")
llm_azure = AzureChatOpenAI(
openai_api_version= "2023-07-01-preview",
azure_deployment=os.environ.get("AZURE_OPENAI_DEPLOYMENT", "openai"),
azure_endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT", "https://.openai.azure.com/"),
api_key=os.environ.get("AZURE_OPENAI_KEY")
)

Create Agents

coach = Agent(
role='Senior Career Coach',
goal="Discover and examine key tech and AI career skills for 2024",
backstory="You're an expert in spotting new trends and essential skills in AI and technology.",
verbose=True,
allow_delegation=False,
tools=[search_tool],
llm=llm_vertex
)

influencer = Agent(
role='LinkedIn Influencer Writer',
goal="Write catchy, emoji-filled LinkedIn posts within 200 words",
backstory="You're a specialised writer on LinkedIn, focusing on AI and technology.",
verbose=True,
allow_delegation=True,
llm=llm_mistral
)

critic = Agent(
role='Expert Writing Critic',
goal="Give constructive feedback on post drafts",
backstory="You're skilled in offering straightforward, effective advice to tech writers. Ensure posts are concise, under 200 words, with emojis and hashtags.",
verbose=True,
allow_delegation=True,
llm=llm_azure
)

Create Tasks

task_search = Task(
description="Compile a report listing at least 5 new AI and tech skills, presented in bullet points",
agent=coach
)

task_post = Task(
description="Create a LinkedIn post with a brief headline and a maximum of 200 words, focusing on upcoming AI and tech skills",
agent=influencer
)

task_critique = Task(
description="Refine the post for brevity, ensuring an engaging headline (no more than 30 characters) and keeping within a 200-word limit",
agent=critic
)

Create Crew

crew = Crew(
agents=[coach, influencer, critic],
tasks=[task_search, task_post, task_critique],
verbose=2,
process=Process.sequential
)

Get your crew to work!

result = crew.kickoff()

print("#############")
print(result)

Categories
AI Agents
Crew AI Open Source Agents

Post author
Enter fullscreen mode Exit fullscreen mode

By praison

Post date

January 15, 2024
Enter fullscreen mode Exit fullscreen mode

pip install langchain-community langchain crewai langchain-openai duckduckgo-search

Open Source

from crewai import Agent, Task, Crew, Process
from langchain_openai import ChatOpenAI
from langchain_community.llms import Ollama
from langchain_community.tools import DuckDuckGoSearchRun
search_tool = DuckDuckGoSearchRun()

llm_lmstudio = ChatOpenAI(
openai_api_base="http://localhost:1234/v1",
openai_api_key="",

model_name="mistral"
)

llm_janai = ChatOpenAI(
openai_api_base="http://localhost:1337/v1",
openai_api_key="",

model_name="mistral-ins-7b-q4"
)

llm_ollama = Ollama(model="orca2")

llm_textgen = ChatOpenAI(
openai_api_base="http://localhost:5001/v1",
openai_api_key="",

model_name="openhermes"
)

Create a researcher agent

researcher = Agent(
role='Senior Researcher',
goal='Discover groundbreaking technologies',
backstory='A curious mind fascinated by cutting-edge innovation and the potential to change the world, you know everything about tech.',
verbose=True,
tools=[search_tool],
allow_delegation=False,
llm=llm_lmstudio
)

insight_researcher = Agent(
role='Insight Researcher',
goal='Discover Key Insights',
backstory='You are able to find key insights from the data you are given.',
verbose=True,
allow_delegation=False,
llm=llm_janai
)

writer = Agent(
role='Tech Content Strategist',
goal='Craft compelling content on tech advancements',
backstory="""You are a content strategist known for
making complex tech topics interesting and easy to understand.""",
verbose=True,
allow_delegation=False,
llm=llm_ollama
)

formater = Agent(
role='Markdown Formater',
goal='Format the text in markdown',
backstory='You are able to convert the text into markdown format',
verbose=True,
allow_delegation=False,
llm=llm_textgen
)

Tasks

research_task = Task(
description='Identify the next big trend in AI by searching internet',
agent=researcher
)

insights_task = Task(
description='Identify few key insights from the data in points format. Dont use any tool',
agent=insight_researcher
)

writer_task = Task(
description='Write a short blog post with sub headings. Dont use any tool',
agent=writer
)

format_task = Task(
description='Convert the text into markdown format. Dont use any tool',
agent=formater
)

Instantiate your crew

tech_crew = Crew(
agents=[researcher, insight_researcher, writer, formater],
tasks=[research_task, insights_task, writer_task, format_task],
process=Process.sequential # Tasks will be executed one after the other
)

Begin the task execution

result = tech_crew.kickoff()
print(result)

OpenAI

from crewai import Agent, Task, Crew, Process
from langchain_openai import ChatOpenAI
from langchain_community.llms import Ollama
from langchain_community.tools import DuckDuckGoSearchRun
search_tool = DuckDuckGoSearchRun()

Create a researcher agent

researcher = Agent(
role='Senior Researcher',
goal='Discover groundbreaking technologies',
backstory='A curious mind fascinated by cutting-edge innovation and the potential to change the world, you know everything about tech.',
verbose=True,
tools=[search_tool],
allow_delegation=False,
)

insight_researcher = Agent(
role='Insight Researcher',
goal='Discover Key Insights',
backstory='You are able to find key insights from the data you are given.',
verbose=True,
allow_delegation=False,
)

writer = Agent(
role='Tech Content Strategist',
goal='Craft compelling content on tech advancements',
backstory="""You are a content strategist known for
making complex tech topics interesting and easy to understand.""",
verbose=True,
allow_delegation=False,
)

formater = Agent(
role='Markdown Formater',
goal='Format the text in markdown',
backstory='You are able to convert the text into markdown format',
verbose=True,
allow_delegation=False,
)

Tasks

research_task = Task(
description='Identify the next big trend in AI by searching internet once',
agent=researcher
)

insight_task = Task(
description='Find key insights from the data. Dont use any tool',
agent=insight_researcher
)

write_task = Task(
description='Write a blog post. Dont use any tool',
agent=writer
)

format_task = Task(
description='convert the input to markdown format',
agent=formater
)

Instantiate a crew

tech_crew = Crew(
agents=[researcher, insight_researcher, writer, formater],
tasks=[research_task, insight_task, write_task, format_task],
process=Process.sequential # Tasks will be executed one after the other
)

Begin the task execution

result = tech_crew.kickoff()
print(result)

Text Generation Web UI

bash start_macos.sh --api --listen --extensions openai --trust-remote-code

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player