From the course: OpenAI API for Python Developers

Create a user interface with Streamlit

From the course: OpenAI API for Python Developers

Create a user interface with Streamlit

- [Instructor] Now this is going to be the last step. We're going to add a user interface to this custom AI assistance. And you can see that I've made a few changes. So first, we no longer have the main function. We're going to use query because we're going to call this function from the user interface. And I've decided also to separate the different actions. So first, this one, which is to load and split the documents into chunks of documents. So it's going to return the documents here. It's going to be this one. And after that we're going to create and load the embeddings into a vector store. So the same right here. In order to return this time here, the database as a retriever. So we're going to use the retriever as the source of information. So that's going to be used as a context. We're going to inform, then allow to train the language model with custom knowledge. So let's go back up here. You're going to find this new input variables. So I had explained those two all ready. So we're going to use this two and allow to give context, this time I'm going to show you as well the other new thing, which is the app.py. And this is where you're going to find the implementation for the user interface that we build with Streamlit. So let's go check this one out before we show you the next step. So I'm going to run this app with Streamlit. Run an app.py. All right, so now this is up and running. And this is going to be visible right here. So we're going to go check this one out. Okay, so let's refresh. All right, so let's make a quick test. We're going to ask, "Do you ship to the UK?" All right, so now we've got a mistake because we need to also connect a few things. So if you go back, so as I was explaining, so we're going to run this function, which is query from the main file right here. So let's go back and make a few revision. Actually, we're going to make a few fixes because we need to also pass as an argument, this user query. And same as well so when we want to retrieve here, the custom knowledge we're going to pass as well, the user query. So let's do that first and we're going to make a few changes. And actually I'm going to find a demonstration right here. So that's going to be with Runnable Pass through. We're going to have here an opportunity to use this one. I'm going to explain this to you. And basically, what we do here is to add another component, which is to use the retriever, which is the custom knowledge as context. And then we're going to pass the user query here by using this interesting feature from Lang Chain, which is Runnable Pass through. So basically what we do is to pass the user query here as an argument to invoke. And when we run the chain, which is this one, retrieval chain, it's going to be passed here as a value to question. So let's copy all of this and add it right here. So we're going to replace all of it. We're going to create a new chain with an extra component right here. So we're going to start first with the knowledge retrieval, and let's replace here with our chat from templates. And here it's going to be chat model. All right, and finally that's going to be string output parser, but we're going to replace with our own instance of the same class. Next, we're going to run and allow to generate here the outputs. And that's going to be safe to message. We're going to run it. And so we're going to pass the user query as an argument. And the way it works here is that we're going to pass here first, the user query, and we're going to use here Runnable Pass through to pass this user query to the question. So let's just make sure that this is also available in this module. So let's go back. I'm going to add it right here. All right, so that should fix it and it's going to go in sequence. So first we're going to run this chain by giving access to the retrieved data. Then we're going to pass the user inputs. It's going to be added as a new message to the list of messages. Then we're going to pass the list of messages as an input to the chat model and finally generate the response. So let's try that. Now, let's see a final demonstration. We're going to ask something specific like "What are the opening hours of your store?" We're going to see what is the outputs. And here we go. We can read that our store are open from 9:00 AM to 8:00 PM. And if you go back right here, so when we check out the FAQ, so the document based database, we can see that this is exactly the same information that we can find right here as the source of information, excellence.

Contents