Building a News Summarizer
Learn how to build an AI-powered news summarizer that searches and summarizes recent articles using Exa and GPT.
In this example, we will build an LLM-based news summarizer with the Exa API to keep us up-to-date with the latest news on a given topic. We’ll do this in three steps:
- Generate search queries for Exa using an LLM
- Retrieve relevant URLs and their contents using Exa
- Summarize webpage contents using GPT-3.5 Turbo
This is a form of Retrieval Augmented Generation (RAG), combining Exa’s search capabilities with GPT’s summarization abilities.
The Jupyter notebook for this tutorial is available on Colab for easy experimentation. You can also check it out on Github, including a plain Python version if you want to skip to the complete product.
Get Started
Pre-requisites and installation
Install the required packages:
Get your Exa API key
Set up your API keys:
Initialize the clients
Import and set up both the OpenAI and Exa clients:
Generate a search query
First, we’ll use GPT to generate an optimized search query based on the user’s question:
Search for recent articles
Now we’ll use Exa to search for recent articles, filtering by publication date:
We use use_autoprompt=True
to let Exa optimize our search query for best results, and start_published_date
to filter for recent content.
Get article contents
Exa’s search_and_contents
already retrieved the article contents for us, so we can access them directly:
Unlike traditional search engines that only return URLs, Exa gives us direct access to the webpage contents, eliminating the need for web scraping.
Generate a summary
Finally, we’ll use GPT to create a concise summary of the article:
And we’re done! We’ve built an app that translates a question into a search query, uses Exa to search for useful links and their contents, and summarizes the content to effortlessly answer questions about the latest news.
Through Exa, we have given our LLM access to the entire Internet. The possibilities are endless.