As a VC, it’s tough to keep pace with the velocity of information. This is especially true in AI. The sudden emergence of LLMs and the app layer proliferating on top of them is rapidly changing the tech stack. From vector databases (lower stack) up to prompt chaining and agents (upper stack), the way data is stored, processed, and interfaced is evolving.
I consider myself a hobbyist/opportunistic builder (just for fun/when I have time). This weekend, I started building again with two goals in mind: 1) familiarize myself with the new LLM tool chain and 2) explore ways I might leverage LLMs to increase my overall productivity. I plan to share my learnings on a fairly regular basis, so subscribe to my Substack if this series interests you. Additionally, all scripts will be available on my GitHub.
For my first project, I built a news article summarizer. There’s tons of articles published on AI everyday. On top of that, I’m not a fast reader. The ability to read a short summary and decide whether I’m interested enough to invest more time is valuable. While utility is high, summarization is one of the more basic functions of LLMs (from an implementation standpoint). So it’s a good place to start.
There are three steps to building a news summarizer:
Setup Google Colab. I like working in Colab because it’s serverless - there’s no setup other than launching the notebook from your Google Drive. After that, everything just works. Using environment variables is a bit more work in Colab, but we’ll walk through this.
Scrape articles. Scraping is outside the scope of this post, but I’ve made my code available on GitHub. While scraping is a skill worth learning, it’s not worth covering here. Also, there’s no uniform code (each source you scrape will be different), so spending time on it would not be useful. Instead, I’ll focus on the outputs from the scraper and how they become inputs to the rest of the script.
Summarize articles. The final step is to take the text we’ve scraped and have our LLM summarize the articles. I used LangChain and OpenAI. LangChain is an open source framework that allows AI developers to combine LLMs with external data. OpenAI researches and develops LLMs. They allow developers access through API and the general public through ChatGPT (a chatbot powered by their LLMs).
In the next section, we’ll walk through relevant aspects of these steps.
Setting up Colab
See my notebook for requisite library installs. I won’t waste time explaining the setup code (it’s commented inline below). However, I do want to call out how to save environment variables because it’s a little different than when using a local IDE. The point of environment variables is to avoid exposing sensitive information like API keys when making our scripts public. Here’s the steps:
Create a .env file using any text editor. I use Sublime.
Add your OpenAI API key to the .env file in the format OPEN_AI_KEY=key_string. If you don’t have an API key, you can register and get one for free use.
Upload the .env file to Google Drive (if you create a folder called “Colab Notebooks” for your project, your path will be the same as mine).
Run the following code. You should see output that confirms your environment variables are loaded and your API key is a string.
Scraping Articles
Whatever source you decide to scrape, be sure to collect four outputs - title, url, date, and text. I collect these as a list of dictionaries. Each dictionary represents an article with the four outputs. I also give the user three options for displaying results: today, yesterday, or more (which scrapes every article link on the page regardless of date). Visit my repo if you want to see the script.
Summarizing Articles
I used LangChain’s library to build a summarize_articles() function that uses three helper functions. The first helper function is a get_template() function that contains a LangChain template. It takes the article title and text as arguments and returns a message variable storing our prompt. The string stored in the template variable begins with a “system message” that tells the AI what role to assume. I put system message in quotes because there’s also a SystemMessage class you can import just like HumanMessage. However, I have simply included it as part of the HumanMessage in the structure below. The actual human message part of the template is where we pass our AI assistant the article it needs to summarize. I limit the summary to 100 words or less.
The second helper function is get_summary(). This function takes the messages variable (that stores our prompt) as an argument and returns the summary made by our AI assistant.
The third helper function is get_output(). It takes an article (dictionary) from scraper (list) output. It uses the two previous functions to get a summary, then returns an f-string that includes that particular article’s title, summary, and url.
Finally, the summarize_articles() function takes the list of dictionaries output from the scraper as an argument. It iterates over every article in the list, leveraging the get_output() function to build a list of f-strings. We then concatenate these f-strings into one long markup string we’ll use to display the news article summary results in a GUI.
It’s easy to create user-friendly GUIs in Colab. There are native markup commands that allow you to create dropdown lists, user forms, etc. I used these commands to clean up my notebook and add functionality that lets users select what date(s) for which they want to display article summaries. There’s also an IPython.display library that allows us to display generated output as markdown in our notebook. Using this, we can take the string output from our summarize_articles() function and display it in a user-friendly way. The result is the neat summaries below with links to the full articles in case we want to click through.
About Aaron Childress
Aaron is an investor at Samsung Next where he focuses on AI, robotics, and media tech. His favorite thing about VC is meeting great founders who give him a glimpse into the future. When not working, he is on a quest to find the perfect burger! 🍔