crewai_bot / app.py
typesdigital's picture
Create app.py
763e39c verified
raw
history blame
2.46 kB
import os
import gradio as gr
from crewai import Agent, Task, Crew, Process
from langchain_groq import ChatGroq
from langchain.tools import DuckDuckGoSearchRun
# Initialize the GROQ language model
groq_llm = ChatGroq(
groq_api_key=os.environ["GROQ_API_KEY"],
model_name="mixtral-8x7b-32768"
)
# Initialize the search tool
search_tool = DuckDuckGoSearchRun()
# Create agents
researcher = Agent(
role='Senior Researcher',
goal='Conduct thorough research on given topics',
backstory='You are an experienced researcher with a keen eye for detail and the ability to find relevant information quickly.',
verbose=True,
allow_delegation=False,
llm=groq_llm,
tools=[search_tool]
)
writer = Agent(
role='Content Writer',
goal='Create engaging and informative content based on research',
backstory='You are a skilled writer capable of turning complex information into easily understandable and engaging content.',
verbose=True,
allow_delegation=False,
llm=groq_llm
)
editor = Agent(
role='Editor',
goal='Refine and improve the written content',
backstory='You are a meticulous editor with a strong command of language and an eye for clarity and coherence.',
verbose=True,
allow_delegation=False,
llm=groq_llm
)
def create_crew(query):
# Create tasks
research_task = Task(
description=f"Research the following topic thoroughly: {query}",
agent=researcher
)
writing_task = Task(
description="Write an informative article based on the research conducted",
agent=writer
)
editing_task = Task(
description="Review and refine the written article, ensuring clarity, coherence, and engagement",
agent=editor
)
# Create the crew
crew = Crew(
agents=[researcher, writer, editor],
tasks=[research_task, writing_task, editing_task],
verbose=2,
process=Process.sequential
)
return crew
def process_query(query):
crew = create_crew(query)
result = crew.kickoff()
return result
# Create Gradio interface
iface = gr.Interface(
fn=process_query,
inputs=gr.Textbox(lines=2, placeholder="Enter your query here..."),
outputs=gr.Textbox(lines=10, label="AI Agent Response"),
title="AI Agent Chatbot",
description="Ask a question or provide a topic, and our AI agents will research, write, and edit a response for you."
)
iface.launch()