import streamlit as st from crewai import Crew from langchain_groq import ChatGroq import os from textwrap import dedent from crewai import Agent from crewai_tools import ScrapeWebsiteTool, SerperDevTool from crewai import Task # Initialize the LLM llm = ChatGroq( api_key="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", verbose=True, model="llama3-8b-8192" ) # Set environment variable for API key os.environ["SERPER_API_KEY"] = "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" # Define the agents and tasks def web_researcher_agent(topic): return Agent( role="Expert web researcher", goal=dedent(f"""Your goal is to search on the web and scrape websites for relevant high-quality content about the given topic. Use the tools provided to search on web and scrape website. Topic: {topic}"""), tools=[ScrapeWebsiteTool(), SerperDevTool()], backstory=dedent("""You are proficient at searching for specific topics on the web, selecting those that provide best value and information."""), verbose=True, allow_delegation=False, llm=llm ) def writer_agent(topic): return Agent( role="Expert Writer", goal=dedent(f"""Your goal is to write high-quality content about the given topic. Topic: {topic}"""), tools=[ScrapeWebsiteTool(), SerperDevTool()], backstory=dedent("""You are proficient at writing high-quality content about the given topic."""), verbose=True, allow_delegation=False, llm=llm ) def web_researcher_task(topic): return Task( description=dedent(f"""Get valuable and high-quality information from the web about a given topic. Your goal is to extract high-quality information from the web about a given topic. Topic: {topic}"""), expected_output=dedent(f"""The expected output should be well-formatted information about the given topic, only high-quality information related to the topic. Topic: {topic}"""), agent=web_researcher_agent(topic) ) def writer_task(topic): return Task( description=dedent(f"""Using information extracted by the web researcher agent, your task is to write very detailed and lengthy content on the given topic. Topic: {topic}"""), expected_output=dedent(f"""The expected output should be well-formatted and flawless content on the given topic. Topic: {topic}"""), agent=writer_agent(topic) ) # Streamlit UI st.header("Multi-Agent Chat System") # Initialize chat history if 'chat_history' not in st.session_state: st.session_state.chat_history = [] # Function to format messages with HTML def format_message(role, message): if role == 'User': return f"