Skier8402's picture
Update app.py
3603409 verified
"""
Blog Editor agent implemented with LLMs and crewai framework for handling autogen agents.
It uses streamlit, crewai and openai functions to execute the task of interest.
It is based on the crewai gemini demo: https://huggingface.co/spaces/eaglelandsonce/crewaiongemini
Role and backstory was created using prompt generator role from awesome gpt prompts with few shot prompting with gpt 3.5 turbo
"""
import os
import streamlit as st
from crewai import Agent, Task, Crew, Process
from langchain.tools import DuckDuckGoSearchRun
from langchain_openai import ChatOpenAI
# set page title
st.title("Blog Editor")
st.markdown(
"This is a demo of the [CrewAI](https://www.crewai.com/) framework for handling autogen agents. It is based on the [CrewAI Gemini Demo](https://huggingface.co/spaces/eaglelandsonce/crewaiongemini)."
)
st.markdown(
"The goal of this demo is to show how you can use the [CrewAI](https://crewai.co/) framework to create a blog editor agent that can help you edit your blog posts. The agent is composed of two agents: a researcher and an editor. The researcher is responsible for conducting research and fact-checking the information provided in the blog post. The editor is responsible for editing the blog post and making sure it is clear, coherent, and impactful."
)
st.write("")
st.markdown("Click on the icon 🖱️ Logs to see how the agents are making the decisions.")
# Retrieve API Key from Environment Variable
# setup sidebar: models to choose from and API key input
with st.sidebar:
st.header("OpenAI Configuration")
st.markdown(
"For more information about the models, see [here](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo)."
)
OPENAI_API_KEY = st.text_input("API Key", type="password")
# Instantiate your tools: Search engine tool duckduckgo-search
search_tool = DuckDuckGoSearchRun()
# enter blogpost article
blogpost = st.text_area("Enter blogpost article here", height=200)
# check if blogpost is empty
if blogpost == "":
st.warning("Please enter a blogpost article.")
st.stop()
else:
# Define your agents with roles and goals
editor = Agent(
role="Senior Article Editor",
goal=f"Your goal is to elevate the {blogpost} to its highest potential, ensuring that the writer's message is communicated clearly and powerfully",
backstory="""You are a seasoned article editor with extensive experience in refining written content for clarity and coherence.
Your expertise lies in enhancing the impact of blog posts while preserving the original tone and voice of the writer.
You possess a keen understanding of audience engagement and know how to structure arguments effectively to resonate with readers.
With a sharp eye for detail, you can identify areas where the flow of ideas may be improved, ensuring that each paragraph
transitions smoothly to the next. You are adept at suggesting precise word choices and rephrasing sentences to enhance readability
without altering the author's unique style. Your background in various writing genres equips you with the versatility to adapt to
different topics and tones, making you an invaluable asset in the editing process.""",
verbose=True,
allow_delegation=False,
tools=[search_tool],
llm=ChatOpenAI(model_name="gpt-4-1106-preview", api_key=OPENAI_API_KEY),
)
researcher = Agent(
role="Article Researcher",
goal='''how can I simplify the process of reviewing the editor's content to ensure its accuracy and relevance?
I will identify key areas to focus on, such as fact-checking, source credibility, and the article's overall tone,
to streamline my evaluation. For each question present the reasoning followed by the correct answer.''',
backstory="""You are a seasoned researcher with a strong background in information literacy and critical analysis.
Your expertise lies in conducting thorough research across various disciplines, ensuring that the information you
gather is accurate, relevant, and credible. You possess a keen ability to evaluate sources, distinguishing between
reliable and unreliable information, and you are skilled in fact-checking claims made in articles.
Your methodical approach includes cross-referencing multiple sources, utilizing academic databases,
and applying rigorous standards to verify the authenticity of the information. You are adept at synthesizing
complex data and presenting it in a clear and concise manner, making you an invaluable resource for anyone seeking
to ensure the integrity of the information they use. Your commitment to accuracy and credibility in research is
paramount, and you are dedicated to upholding the highest standards in information dissemination""",
verbose=True,
allow_delegation=True,
tools=[search_tool],
llm=ChatOpenAI(model_name="gpt-4-1106-preview", api_key=OPENAI_API_KEY),
)
# Create tasks for your agents
task1 = Task(
description=f"""Conduct a comprehensive analysis of the provided {blogpost}.
Your analysis should include the following:
- Give a brief overview of the article
- Identify the main points of the article
- Find grammatical errors and suggest corrections
- Identify any outdated or irrelevant details and suggest corrections
You can use the search tool to find additional information. But if there is no text do not continue to the next task.
But if there is no text do not continue to the next task.
""",
agent=editor,
)
task2 = Task(
description=f"""Review the credibility of the sources cited in the {blogpost} and trustworthiness of the information provided.
do not hesitate to use the search tool to find additional information. But if there is no text do not continue to the next task.""",
agent=researcher,
)
# Instantiate your crew with a sequential process
crew = Crew(
agents=[researcher, editor],
tasks=[task2, task1],
verbose=2, # You can set it to 1 or 2 to different logging levels
# process=Process.sequential,
)
# Get your crew to work!
result = crew.kickoff()
st.write("######################")
st.markdown(result)