News Summarizer
Example project using the Exa Python SDK
What this doc covers
1. Generating search queries for Exa using an LLM 2. Retrieving relevant URLs and their contents using Exa 3. Summarizing webpage contents using an LLM
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 will use Exa to retrieve recent news articles and then feed the article contents to GPT-3.5 Turbo for summarization. This is a form of Retrieval Augmented Generation (RAG).
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.
To play with this code, we just need a Exa API key and an OpenAI API key. Get 1000 free Exa searches per month just for signing up!
Setup
Retrieving news with Exa
Let’s use the Exa neural search engine to search the web for relevant links to the user’s question.
First, we ask the LLM to generate a search engine query based on the question.
Looks good! Now let’s put the search query into Exa. Let’s also use start_published_date
to filter the results to pages published in the last week. Notice that we set use_autoprompt=True
which lets the Exa API further optimize our search query for best results. Essentially, there is a special way to format Exa queries for best results, which autoprompt
does automatically.
Now we’re getting somewhere! Exa gave our app a list of relevant, useful URLs based on the original question.
By the way, we might be wondering what makes Exa special. Why can’t we just search with Google? Well, let’s take a look for ourselves at the Google search results. It gives us the front page of lots of news aggregators, but not the news articles themselves. And since we used Exa’s search_and_contents
, our search also returns the webpage contents, so we can use Exa to skip writing a web crawler and access the knowledge directly!
Awesome! That’s really interesting, or it would be if we had bothered to read it all. But there’s no way we’re doing that, so let’s ask the LLM to summarize it for us.
Summarizing with GPT-3.5 Turbo
And we’re done! We built an app that translates a question into a search query, uses Exa to search for useful links, uses Exa to grab clean content from those links, and summarizes the content to effortlessly answer your question about the latest news, or whatever we want.
We can be sure that the information is fresh, we have the source in front of us, and we did all this with an Exa query and LLM call. No web scraping or crawling needed!
Through Exa, we have given our LLM access to the entire Internet. The possibilities are endless.