on the basis of CrewAI With multi-intelligence collaboration and the Cohere Command-R7B Big Model, the system automates the entire process from research to writing, like having a 24-hour newsroom.
Core Functions:
- Research and analysis: the first AI assistant is responsible for searching and organizing all information related to the topic, including news, data and expert opinion.
- Content creation: a second AI assistant transforms the research material into fully structured articles, ensuring professionalism and readability.
- One-Click Generation: the user simply enters the topic and the system does all the work automatically.
Technical Highlights:
- Adopting crewAI, a framework for multi-AI collaboration
- Ensure output quality with cohere, Command-R7B grand modeling
- Build a clean and easy-to-use web interface based on streamlit.
Use the process:
- Enter the topic you want to know about in the sidebar
- Option to adjust generation parameters (e.g. degree of creativity)
- Click the Generate button
- Waiting for the system to complete research and writing
- Generated articles can be viewed or downloaded directly
The architecture diagram shown below illustrates some of the key components (intelligences/tasks/tools) and how they interact with each other!
Each component and its code is described in detail next:
Setting up the Large Language Model (LLM) and web search tools
Also create an .env file to hold their corresponding API keys:
Senior Research Analyst Intelligence
The Web Search Intelligence accepts user queries and then uses the Serper Web Search tool to fetch results from the Internet and consolidate them.
Look at this!
Research Analyst Intelligence Body Tasks
This is the research task we assigned to the Senior Research Analyst Intelligence Body and contains the task description and expected output.
Content authoring intelligences
The role of the Content Writing Intelligence is to use the collated results and turn them into a polished, publishable news article.
Content Writing Intelligent Body Tasks
This is how we describe the writing assignment, including all the details and expected output:
Set Crew, done! ✅
Start it up! 🚀
Deployment Tutorial
AI News Generator
The project builds an AI news generator using CrewAI and Cohere's Command-R:7B model!
Installation and Setup
Getting the API key::
Installing dependencies::
Make sure you have Python 3.11 or later installed.
pip install crewai crewai-tools
.env.example
SERPER_API_KEY=your_serper_api_key COHERE_API_KEY=your_cohere_apikey
app.py
import os import streamlit as st from crewai import Agent, Task, Crew, LLM from crewai_tools import SerperDevTool from dotenv import load_dotenv # Load environment variables load_dotenv() # Streamlit page config st.set_page_config(page_title="AI News Generator", page_icon="📰", layout="wide") # Title and description st.title("🤖 AI News Generator, powered by CrewAI and Cohere's Command R7B") st.markdown("Generate comprehensive blog posts about any topic using AI agents.") # Sidebar with st.sidebar: st.header("Settings") st.header("Content Settings") # Make the text input take up more space topic = st.text_area( "Enter your topic", height=100, placeholder="Enter the topic you want to generate content about...") ) # Add more sidebar controls if needed st.markdown("### Advanced Settings") temperature = st.slider("Temperature", 0.0, 1.0, 0.7) # Add some spacing st.markdown("----") # Make the generate button more prominent in the sidebar generate_button = st.button("Generate Content", type="primary", use_container_width=True) # Add some helpful information with st.expander("ℹ️ How to use"): st.markdown(""): st.expander("ℹ️ How to use"). st.markdown(""") 1. Enter your desired topic in the text area above 2. Adjust the temperature if needed (higher = more creative) 3. Click 'Generate Content' to start 4. Wait for the AI to generate your article 5. Download the result as a markdown file """) def generate_content(topic): llm = LLM( model="command-r", temperature=0.7 ) search_tool = SerperDevTool(n_results=10) # First Agent: Senior Research Analyst senior_research_analyst = Agent( role="Senior Research Analyst", goal=f "Research, analyze backstory="You're an expert research analyst with advanced web research skills. " "You excel at finding, analyzing, and synthesizing information from " You're skilled at " "distinguishing reliable sources from unreliable sources." "distinguishing reliable sources from unreliable ones," You're skilled at " "distinguishing reliable sources from unreliable ones," " "fact-checking, cross-referencing information, and " "identifying key patterns and insights." " "identifying key patterns and insights. " "well-organized research briefs with proper citations " "and source verification. Your analysis includes both " "raw data and interpreted insights. " "raw data and interpreted insights, making complex " "information accessible and actionable. " "information accessible and actionable.", allow_delegation=False, verbose=True, " "and source verification. verbose=True, tools=[search_tools][search_tools][search_tools], and tools=[search_tool], llm=llm ) # Second Agent: Content Writer content_writer = Agent( role="Content Writer", goal="Transform research findings into engaging blog posts while maintaining accuracy", content_writer = Agent( goal="Transform research findings into engaging blog posts while maintaining accuracy", backstory="You're a skilled content writer specialized in creating " "engaging, accessible content from technical research." "You work closely with the Senior Research Analyst and excel at maintaining the perfect " "balance between informative and entertaining content. "balance between informative and entertaining writing, " " "while ensuring all facts and citations from the research " "are properly incorporated. You have a talent for making " "complex topics approachable without oversimplifying. You have a talent for making " "complex topics approachable without oversimplifying them.", " "while ensuring all facts and citations from the research " "are properly incorporated. You have a talent for making " "complex topics approachable without oversimplifying them.", allow_delegation=False, verbose=True, verbose=True, verbose=True. You have a talent for making " "complex topics approachable without oversimplifying them. llm=llm ) # Research Task research_task = Task( description=(""" 1. Conduct comprehensive research on {topic} including. - Recent developments and news - Key industry trends and innovations - Expert opinions and analyses - Expert opinions and analyses 2. Evaluate source credibility and fact-check all information 3. Organize findings into a structured research brief 4. Include all relevant citations and sources """), expected_output="""), expected_output=""") expected_output="""A detailed research report containing. - Executive summary of key findings - Comprehensive analysis of current trends and developments - List of verified facts and statistics - All citations and links to original sources - Clear categorization of main themes and patterns Please format with clear sections and bullet points for easy reference.""",""," Please format with clear sections and bullet points for easy reference.""", agent=senior_research_analyst ) # Writing Task writing_task = Task( description=(""" Using the research brief provided, create an engaging blog post that. 1. Transforms technical information into accessible content 2. Maintains all factual accuracy and citations from the research 3. Includes. - Attention-grabbing introduction - Well-structured body sections with clear headings - Includes: Attention-grabbing introduction Well-structured body sections with clear headings 4. Preserves all source citations in [Source: URL] format 5. Includes a References section at the end Includes a References section at the end """), expected_output="""), and expected_output="""A polished blog post in markdown format that. - Engages readers while maintaining accuracy - Contains properly structured sections - Includes Inline citations hyperlinked to the original source url - Presents information in an accessible yet informative way - Follows proper markdown formatting, use H1 for the title and H3 for the sub-sections""",""," agent=content_writer ) # Create Crew crew = Crew( agents=[senior_research_analyst, content_writer], tasks=[research_task, writing_task], verbose=True verbose=True ) return crew.kickoff(inputs={"topic": topic}) # Main content area if generate_button. with st.spinner('Generating content... This may take a moment.'). This may take a moment.'): try. result = generate_content(topic) st.markdown("### Generated Content") st.markdown(result) # Add download button st.download_button( label="Download Content", data=result.raw, file_name=f"{topic.lower() file_name=f"{topic.lower().replace(' ', '_')}_article.md", mime="text/markdown" ) except Exception as e. st.error(f "An error occurred: {str(e)}") # Footer st.markdown("---") st.markdown("Built with CrewAI, Streamlit and powered by Cohere's Command R7B")