Stumbled on to two books that are useful for someone who wants to quickly code up some apps using langchain. This blog post is a brief summary of the two books

One can use the openai library to interface with all the openai models but you will have to build out some additional tooling around it to build a good demonstrable app. LangChain fills that gap. One of the first questions that anyone might have about langchain is : What is the advantage of using langchain and What are the features of the langchain library ? One can read through the documentation around at LangChain Docs and get an overall idea. But the best way to learn is build some quick prototypes. This book talks about two apps

  • Generating title, subtitle and blog post given a topic
  • Upload a file and ask questions based on the content in the file

The code in the book is easy to follow. However this space is changing so quickly that some of the code mentioned in the book is already dated. The new way to use langchain functionality is via LCEL(LangChain Expression language) but this book is based on old syntax. LangChain recommends invoking RAG chains via LCEL. So, one might have to dig in to the latest documentation to rebuild some of these examples. Despite this, the book is useful in demonstrating the purpose of using langchain for the two mentioned apps. It can be thought of as two programs with elaborate commentary around them.

This book serves as an informal guide for those interested in developing Streamlit apps using OpenAI and LangChain. Echoing the approach of a previous book mentioned in this post, it emphasizes hands-on learning through the creation of quick, exploratory apps to understand the functionalities of these libraries. The book covers the development of several applications:

  • Creating a ChatGPT clone using Streamlit’s chat_message and chat_input components
  • Summarizing web page content
  • Summarizing short and long YouTube videos
  • Analyzing PDF content and generating relevant questions

Even though this book is written in a very casual manner and mostly looks like a series of blog posts, I found the content useful. One of the best ways to approach this book is to look at each of the app, look at the workflow mentioned in the app and then code up the app without looking at author’s solution. In the process of developing the toy apps mentioned in the book, one can learn a good amount of features around langchain and streamlit. Of course the space is moving so quickly that there are better ways to accomplish the mini tasks mentioned in the book using the latest langchain versions.

Here are some of my learnings from working through the book:

  • Various types of models from OpenAI
  • tiktoken library
  • Embedding models from OpenAI
  • OpenAI has not specified the rate limit for the usage of ChatGPT
  • langchain features covered in the apps
    • invoking LLM model
    • retrieving content from third party sources
    • storing data in a vector database
    • use of RAG chains to chat with a document
  • Use of session_state to store the history of chat messages
  • Use of various inbuilt chat elements from streamlit
  • Deploying a streamlit app to Streamlit Community cloud
  • langchain provides a ton of functionality to integrate content from third party sources
  • One can either write a prompt for a specific task OR use the built in prompts in the langchain library. There are two ways to generate prompts. One is implicitly via the usage of various chains. The second is via the explicit usage of hub.pull
  • Understanding Text Splitters and its relevance in langchain ecosystem
  • Relevance of Vector Databases in RAG
  • Use of RAG chains

Working through the apps in this book won’t make one an expert in LangChain, but it will provide enough motivation and foundational knowledge to explore other features of the library.