From 0f1be80b73b4b6a8ab525ec6eab8f1b90465bdda Mon Sep 17 00:00:00 2001 From: ShubhamSaboo Date: Mon, 3 Jun 2024 15:20:19 -0500 Subject: [PATCH] Added new demo --- README.md | 4 + .../README.md | 0 .../investment_agent.py | 0 .../requirements.txt | 0 ai_journalist_agent/README.md | 40 +++++++++ ai_journalist_agent/journalist_agent.py | 88 +++++++++++++++++++ ai_journalist_agent/requirements.txt | 6 ++ 7 files changed, 138 insertions(+) rename {investment_ai_agent => ai_investment_agent}/README.md (100%) rename {investment_ai_agent => ai_investment_agent}/investment_agent.py (100%) rename {investment_ai_agent => ai_investment_agent}/requirements.txt (100%) create mode 100644 ai_journalist_agent/README.md create mode 100644 ai_journalist_agent/journalist_agent.py create mode 100644 ai_journalist_agent/requirements.txt diff --git a/README.md b/README.md index 5a6cce3..e88ca40 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ A curated collection of awesome LLM apps built with RAG and AI agents. This repo - [🎯 Generative AI Web Search Assistant](#-generative-ai-web-search-assistant) - [💬 Chat with GitHub Repo](#-chat-with-github-repo) - [📈 AI Investment Agent](#-ai-investment-agent) + - [🗞️ AI Journalist Agent](#-ai-journalist-agent) - [📰 Multi-Agent AI Researcher](#-multi-agent-ai-researcher) - [📄 Chat with PDF](#-chat-with-pdf) - [💻 Web Scraping AI Agent](#-web-scraping-ai-agent) @@ -55,6 +56,9 @@ Engage in natural conversations with your GitHub repositories using GPT-4. Uncov ### 📈 AI Investment Agent AI investment agent that compares the performance of two stocks and generates detailed stock reports with company insights, news, and analyst recommendations to help you make smart investment choices. +### 🗞️ AI Journalist Agent +AI-powered journalist agent that generates high-quality articles using OpenAI GPT-4o. It automates the process of researching, writing, and editing articles, allowing you to create compelling content on any topic with ease. + ### 📰 Multi-Agent AI Researcher Use a team of AI agents to research top HackerNews stories and users with GPT-4 to generate blog posts, reports, and social media content on autopilot. diff --git a/investment_ai_agent/README.md b/ai_investment_agent/README.md similarity index 100% rename from investment_ai_agent/README.md rename to ai_investment_agent/README.md diff --git a/investment_ai_agent/investment_agent.py b/ai_investment_agent/investment_agent.py similarity index 100% rename from investment_ai_agent/investment_agent.py rename to ai_investment_agent/investment_agent.py diff --git a/investment_ai_agent/requirements.txt b/ai_investment_agent/requirements.txt similarity index 100% rename from investment_ai_agent/requirements.txt rename to ai_investment_agent/requirements.txt diff --git a/ai_journalist_agent/README.md b/ai_journalist_agent/README.md new file mode 100644 index 0000000..76b3df7 --- /dev/null +++ b/ai_journalist_agent/README.md @@ -0,0 +1,40 @@ +## 🗞️ AI Journalist Agent +This Streamlit app is an AI-powered journalist agent that generates high-quality articles using OpenAI GPT-4o. It automates the process of researching, writing, and editing articles, allowing you to create compelling content on any topic with ease. + +### Features +- Searches the web for relevant information on a given topic +- Writes well-structured, informative, and engaging articles +- Edits and refines the generated content to meet the high standards of the New York Times + +### How to get Started? + +1. Clone the GitHub repository + +```bash +git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git +``` +2. Install the required dependencies: + +```bash +pip install -r requirements.txt +``` +3. Get your OpenAI API Key + +- Sign up for an [OpenAI account](https://platform.openai.com/) (or the LLM provider of your choice) and obtain your API key. + +4. Get your SerpAPI Key + +- Sign up for an [SerpAPI account](https://serpapi.com/) and obtain your API key. + +5. Run the Streamlit App +```bash +streamlit run journalist_agent.py +``` + +### How it Works? + +The AI Journalist Agent utilizes three main components: +- Searcher: Responsible for generating search terms based on the given topic and searching the web for relevant URLs using the SerpAPI. +- Writer: Retrieves the text from the provided URLs using the NewspaperToolkit and writes a high-quality article based on the extracted information. +- Editor: Coordinates the workflow between the Searcher and Writer, and performs final editing and refinement of the generated article. + diff --git a/ai_journalist_agent/journalist_agent.py b/ai_journalist_agent/journalist_agent.py new file mode 100644 index 0000000..39b4383 --- /dev/null +++ b/ai_journalist_agent/journalist_agent.py @@ -0,0 +1,88 @@ +# Import the required libraries +from textwrap import dedent +from phi.assistant import Assistant +from phi.tools.serpapi_tools import SerpApiTools +from phi.tools.newspaper_toolkit import NewspaperToolkit +import streamlit as st + +# Set up the Streamlit app +st.title("AI Journalist Agent 🗞️") +st.caption("Generate High-quality articles with AI Journalist by researching, wriritng and editing quality articles on autopilot using GPT-4o") + +# Get OpenAI API key from user +openai_api_key = st.text_input("Enter OpenAI API Key to access GPT-4o", type="password") + +# Get SerpAPI key from the user +serp_api_key = st.text_input("Enter Serp API Key for Search functionality", type="password") + +if openai_api_key and serp_api_key: + searcher = Assistant( + name="Searcher", + role="Searches for top URLs based on a topic", + description=dedent( + """\ + You are a world-class journalist for the New York Times. Given a topic, generate a list of 3 search terms + for writing an article on that topic. Then search the web for each term, analyse the results + and return the 10 most relevant URLs. + """ + ), + instructions=[ + "Given a topic, first generate a list of 3 search terms related to that topic.", + "For each search term, `search_google` and analyze the results." + "From the results of all searcher, return the 10 most relevant URLs to the topic.", + "Remember: you are writing for the New York Times, so the quality of the sources is important.", + ], + tools=[SerpApiTools(api_key="649ee0e7d64c6704b8ff92f3b01a424accfe6dbece128d043b17641b875e5f69")], + add_datetime_to_instructions=True, + ) + writer = Assistant( + name="Writer", + role="Retrieves text from URLs and writes a high-quality article", + description=dedent( + """\ + You are a senior writer for the New York Times. Given a topic and a list of URLs, + your goal is to write a high-quality NYT-worthy article on the topic. + """ + ), + instructions=[ + "Given a topic and a list of URLs, first read the article using `get_article_text`." + "Then write a high-quality NYT-worthy article on the topic." + "The article should be well-structured, informative, and engaging", + "Ensure the length is at least as long as a NYT cover story -- at a minimum, 15 paragraphs.", + "Ensure you provide a nuanced and balanced opinion, quoting facts where possible.", + "Remember: you are writing for the New York Times, so the quality of the article is important.", + "Focus on clarity, coherence, and overall quality.", + "Never make up facts or plagiarize. Always provide proper attribution.", + ], + tools=[NewspaperToolkit()], + add_datetime_to_instructions=True, + add_chat_history_to_prompt=True, + num_history_messages=3, + ) + + editor = Assistant( + name="Editor", + team=[searcher, writer], + description="You are a senior NYT editor. Given a topic, your goal is to write a NYT worthy article.", + instructions=[ + "Given a topic, ask the search journalist to search for the most relevant URLs for that topic.", + "Then pass a description of the topic and URLs to the writer to get a draft of the article.", + "Edit, proofread, and refine the article to ensure it meets the high standards of the New York Times.", + "The article should be extremely articulate and well written. " + "Focus on clarity, coherence, and overall quality.", + "Ensure the article is engaging and informative.", + "Remember: you are the final gatekeeper before the article is published.", + ], + add_datetime_to_instructions=True, + # debug_mode=True, + markdown=True, + ) + + # Input field for the report query + query = st.text_input("What do you want the AI journalist to write an Article on?") + + if query: + with st.spinner("Processing..."): + # Get the response from the assistant + response = editor.run(query, stream=False) + st.write(response) \ No newline at end of file diff --git a/ai_journalist_agent/requirements.txt b/ai_journalist_agent/requirements.txt new file mode 100644 index 0000000..2316761 --- /dev/null +++ b/ai_journalist_agent/requirements.txt @@ -0,0 +1,6 @@ +streamlit +phidata +openai +google-search-results +newspaper3k +lxml_html_clean \ No newline at end of file