So these are very interesting and important chapter where we are going to explore how to a use a long
chain application and an application with an API.
So we can start communicating our application with the external world.
Right.
And to connect it and integrate it with other, other pieces of software.
So what we are going to do in this exercise is to connect a basic drag application with a fast API.
API.
So fast API is a probably the most, uh, used, uh, framework in the Python ecosystem.
Uh, you can you have different possibilities, but this one is one of the most popular in the launching
world.
So you will see that we will use the fast API module of long chain to create the API.
And we will use Uvicorn to create the local server.
The creation of the Rag application is a familiar to you, so we will start loading the dot env file
the credentials from the file in order to be able to communicate with the OpenAI API.
And then we will create the Rag application.
We will create the LM instance.
We will import the loader.
We will load a text file that is in the data directory.
This is an article an article about startups and stuff about startups.
And we uh the next thing we do is we split this document into small chunks.
Then we, uh, transform the chunks into embeddings, and we load the content into a file vector database.
Then we create a retrieval QA chain.
And with this chain we can start making questions to our private document.
So how do we connect these basic rack application with fast API.
So the first thing we need is to install.
If you don't have it to install the fast API package you know how to do it.
If you are using terminal, you just write pip install fast API and if you want to do it, you want
to do it via a Jupyter notebook.
You can write the exclamation mark before and then you execute the cell.
And that's it.
You have here the pound sign because we want to uncomment this.
We don't want to do this operation because we have done it already.
So then you import the fast API and the Http exception modules.
You create the application.
And in this case we are creating an endpoint.
It's a post endpoint.
And you see that this endpoint is using the chain we just created in order to get the uh data.
So once you have that you install you can install Uvicorn to proceed with the local server.
And once you have that, this is the way you configure it using Jupyter Notebook.
If you are using, for example, a Visual Studio Code editor instead of a Jupyter notebook, you can
use this other approach.
You have any problem with this process?
With the server, you just go to the usual places ChatGPT and Google or StackOverflow and ask about
any doubt or problem you may have in the process, and you will find, uh, the response there.
But if everything is successful, and I think it is going to be because this is quite simple to do,
uh, then you will have a situation like this where you can start the local server in this, uh, address
and here.
Vuiyasawa said this.
You will see something like this and you can click here on post and try it out and you can enter here.
Your question.
Uh, it would be like what is this article?
About in less than.
100 words.
Execute.
And here you have the response.
Okay, so the most important thing of this chapter is to understand that our LM application can end
up in an API.
So we can start plugging our LM applications with other external applications to do.
A whole lot of different things.
Remember that you can go to the documentation to know more, or to experiment further with this approach,
and to find the special use case that is, uh, best for you, the particular API, API, or approach
that works better for your use case.