100줄의 코드로 지능형 뉴스를 생성하는 CrewAI + Command-R7B

AI 실습 튜토리얼9개월 전 업데이트 AI 공유 서클
12.4K 00

를 기준으로 CrewAI 멀티 인텔리전트 바디 협업 및 Cohere Command-R7B는 24시간 뉴스룸을 운영하는 것처럼 리서치부터 글쓰기까지 전체 프로세스를 자동화하는 대형 모델입니다.

CrewAI + Command-R7B 百行代码实现智能生成新闻

 

핵심 기능:

  1. 연구 및 분석: 첫 번째 AI 어시스턴트는 뉴스, 데이터, 전문가 의견 등 주제와 관련된 모든 정보를 검색하고 정리하는 일을 담당합니다.
  2. 콘텐츠 제작: 두 번째 AI 어시스턴트가 연구 자료를 완전한 구조의 기사로 변환하여 전문성과 가독성을 보장합니다.
  3. 원클릭 생성: 사용자가 주제를 입력하기만 하면 시스템이 모든 작업을 자동으로 수행합니다.

기술 하이라이트:

  • 멀티 AI 협업을 위한 프레임워크, 크루AI 도입
  • 코히어, Command-R7B 매크로 모델로 출력 품질 보장
  • 스트림릿을 기반으로 깔끔하고 사용하기 쉬운 웹 인터페이스를 구축하세요.

프로세스를 사용합니다:

  1. 사이드바에 알고 싶은 주제를 입력합니다.
  2. 생성 매개변수 조정 옵션(예: 창의성 정도)
  3. 생성 버튼을 클릭합니다.
  4. 시스템이 조사 및 작성을 완료할 때까지 기다리기
  5. 생성된 문서를 바로 보거나 다운로드할 수 있습니다.

 

아래 아키텍처 다이어그램은 주요 구성 요소(인텔리전스/작업/도구)와 이들이 서로 어떻게 상호 작용하는지를 보여줍니다!

각 구성 요소와 해당 코드는 다음에 자세히 설명되어 있습니다:

CrewAI + Command-R7B 百行代码实现智能生成新闻

 

대규모 언어 모델(LLM) 및 웹 검색 도구 설정하기

또한 해당 API 키를 보관할 .env 파일을 생성합니다:

CrewAI + Command-R7B 百行代码实现智能生成新闻

 

선임 연구 분석가 인텔리전스

웹 검색 인텔리전스는 사용자 쿼리를 수락한 다음 Serper 웹 검색 도구를 사용하여 인터넷에서 결과를 검색하고 통합합니다.

이것 좀 보세요!

CrewAI + Command-R7B 百行代码实现智能生成新闻

 

연구 분석가 인텔리전스 기관 작업

이것은 선임 연구 분석가 인텔리전스 기관에 할당된 연구 과제이며 과제 설명과 예상 결과물이 포함되어 있습니다.

CrewAI + Command-R7B 百行代码实现智能生成新闻

 

콘텐츠 저작 인텔리전스

콘텐츠 작성 인텔리전스의 역할은 수집된 결과를 사용하여 세련된 게시 가능한 뉴스 기사로 전환하는 것입니다.

CrewAI + Command-R7B 百行代码实现智能生成新闻

 

콘텐츠 작성 지능형 본문 작업

모든 세부 사항과 예상 결과물을 포함하여 글쓰기 과제를 설명하는 방식입니다:

CrewAI + Command-R7B 百行代码实现智能生成新闻

 

세트 크루, 완료! ✅

시작하기! 🚀

CrewAI + Command-R7B 百行代码实现智能生成新闻

 

배포 튜토리얼

AI 뉴스 생성기

이 프로젝트는 CrewAI와 Cohere의 Command-R:7B 모델을 사용하여 AI 뉴스 생성기를 구축합니다!

설치 및 설정

API 키 가져오기::

종속성 설치::
Python 3.11 이상이 설치되어 있는지 확인하세요.

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("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("""
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, and synthesize comprehensive information on {topic} from reliable web sources",
backstory="You're an expert research analyst with advanced web research skills. "
"You excel at finding, analyzing, and synthesizing information from "
"across the internet using search tools. You're skilled at "
"distinguishing reliable sources from unreliable ones, "
"fact-checking, cross-referencing information, and "
"identifying key patterns and insights. You provide "
"well-organized research briefs with proper citations "
"and source verification. Your analysis includes both "
"raw data and interpreted insights, making complex "
"information accessible and actionable.",
allow_delegation=False,
verbose=True,
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",
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 writing, "
"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,
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
- Statistical data and market insights
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="""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.""",
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
- Compelling conclusion
4. Preserves all source citations in [Source: URL] format
5. Includes a References section at the end
"""),
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
)

return crew.kickoff(inputs={"topic": topic})

# Main content area
if generate_button:
with st.spinner('Generating content... 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().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")
© 저작권 정책

관련 문서

댓글 없음

댓글에 참여하려면 로그인해야 합니다!
지금 로그인
없음
댓글 없음...