8 Creating LLM-based Applications using LangChain and LlamaIndex

 

This chapter covers:

  • Introducing Large Language Models (LLM)
  • Creating LLM Applications using LangChain
  • Connecting LLMs to Your Private Data using LlamaIndex
  • Running Local Models for Vector Embedding

In chapter 3, you learned how to employ transformers pipeline to access diverse pre-trained models for various Natural Language Processing (NLP) tasks, including sentiment classification, named entity extraction, and text summarization. However, in practical scenarios, the goal is to seamlessly integrate various models, encompassing those from Hugging Face and OpenAI, into custom applications. Enter LangChain, a solution that facilitates the customization of NLP applications by linking different components based on specific requirements.

While pre-trained models prove beneficial, it's important to note that they were trained on external data, not your own. Often, there arises a requirement to utilize a model for answering questions pertinent to your unique dataset. For instance, imagine possessing a dataset with numerous receipts and invoices. Leveraging a pre-trained model, you would want it to summarize your purchases or identify vendors associated with specific items. This is where LlamaIndex becomes indispensable. With LlamaIndex, you gain the ability to connect an LLM to your proprietary data, empowering it to address queries tailored to your dataset.

8.1 Introduction to Large Language Models (LLM)

8.2 Introduction to LangChain

8.2.1 Installing LangChain

8.2.2 Creating a Prompt Template

8.2.3 Specifying an LLM

8.2.4 Creating an LLM Chain

8.2.5 Running the Chain

8.2.6 Maintaining a Conversation

8.2.7 Using the RunnableWithMessageHistory class

8.2.8 Using Other LLMs

8.3 Connecting LLMs to Your Private Data using LlamaIndex

8.3.1 Installing the Packages

8.3.2 Preparing the Documents

8.3.3 Loading the Documents

8.3.4 Using an Embedding Model

8.3.5 Indexing the Document

8.3.6 Loading the Embeddings

8.3.7 Using an LLM for Querying

8.3.8 Asking Questions

8.3.9 Using LlamaIndex with OpenAI

8.3.10 Creating a Web Frontend for the App

8.3.11 Holding a conversation

8.3.12 Creating a Chatbot UI

8.4 Summary