From the course: Level up LLM applications development with LangChain and OpenAI

Challenge: Create a custom agent with history

(peppy music) - [Instructor] Now it's time for the challenge. Previously, we have created a custom Q&A chatbot. A context aware Q&A chatbot, because what we've done is to give this chatbot access to specific data in order to make it knowledgeable and context aware so it could respond to specific questions and general inquiries about your products and services based on this list of frequently asked questions for the Red30 Shoes company. So now what we'd like to do for this challenge is to create a Q&A chatbot again, which is context aware, but also history aware that could remember the past messages. So we're going to see how to add chat history to this chatbot. And for this challenge, you're going to have access to instructions the same so that you can find on the README file. So in order to get started, set up and configure your projects, do not forget also to set up an API key. And so let's go back up. You're going to find here a link. We're going to get to it. So here you have instructions about how to add a chat history to your Q&A agents. So here you're going to find a few instructions for the setup to install the packages and dependencies. And then we're going to have one first part about how to create a chain without chat history. So you can scroll down a bit and then you're going to find this section to learn to contextualize the question. But that's going to be actually the second part of the exercise. We're going to be building this Q&A chatbot in two parts. So what we want to do first is to learn to create a chain with chat history. So that's going to be the first part. First, what we have is this contextualize_q_system prompt. So we're going to start by providing with some instructions, a prompt, to allow the chatbot to remember the past messages with chat history. That's going to be a first part. Then you're going to have another prompt, which is telling the chatbot how to generate answers based on the context. So I'm going to leave this to you. Of course, you can look at this example to find inspiration, and you'll see that for the starter project, let's go back here, you're going to have some initial setup. So first you're going to have here how to allow the chatbot to remember historical messages so it can respond to the user query. And next you're going to have this other prompts, which is used to build the full Q&A chain. So first I recommend that you start with indexing, which is always the starting point, which is to load, then split the documents into chunks to create embeddings, and then store the embeddings into a vector store. And so then you can create a retriever with this vector store. So we're going to use this context to make the chatbot context aware, but also history aware. So now I'm going to leave this to you. This is your turn, and then we're going to see the solutions together in the next couple of videos. So good luck.

Contents