back to indexExtractive Q&A With Haystack and FastAPI in Python
Chapters
0:0
0:31 Jupiter Notebook
3:7 Create a Http Method
10:0 Query Our Data
15:55 What Is the Universe
00:00:00.000 |
Okay, so we're gonna go through putting together 00:00:07.860 |
So originally I was just gonna do the reader model 00:00:10.820 |
in this video, but I realized it's actually super easy. 00:00:19.900 |
So what we're gonna do, is wrap everything up in the API 00:00:23.980 |
and then we'll add the reader model into that. 00:00:50.500 |
for when we're putting things together and testing things, 00:00:52.860 |
but we need to switch over to actual Python files. 00:00:57.900 |
So we're gonna switch across to VS code over here. 00:01:02.900 |
So this is our project directory on the left here. 00:01:16.520 |
And I also put together this requirements text file. 00:01:31.860 |
So fast API, we're obviously using that to build our API 00:01:34.900 |
and uvicorn we're going to use to spin up the server 00:02:04.060 |
Okay, and then in here, we'll create our first Python file. 00:02:17.620 |
And now we'll start putting together our actual API. 00:02:31.800 |
And the first thing we need to do is import fast API. 00:03:05.580 |
And then whenever we want to create a HTTP method, 00:03:22.240 |
So the only one that I think we're gonna need 00:03:30.800 |
And then we also need to add path to this method. 00:03:35.800 |
And in this case, we're going to be querying our Q&A model. 00:03:51.360 |
So this is just going to be the query function. 00:04:21.960 |
So I'm opening terminal in this folder at the moment. 00:04:30.200 |
So at the moment, we're at the high level of this. 00:04:40.320 |
So we have, we want to go into the code directory. 00:04:45.480 |
And then in the code directory, it's QA service, 00:05:02.320 |
And then we want our file name, which is API. 00:05:18.360 |
So this means that whenever we edit our code, 00:05:20.720 |
we don't need to re-initialize the API instance 00:05:35.840 |
So I'm gonna copy that and open it in my browser. 00:05:49.560 |
So that's because we just went straight to the index. 00:06:15.960 |
So if we just check what we did in our Jupyter notebook, 00:06:37.160 |
And honestly, this should really be all we need. 00:06:48.440 |
Okay, so we'll copy this and take it into our code here. 00:06:56.560 |
we're going to initialize the rest of our code. 00:07:06.640 |
we initialize that, it accesses the Aurelius index. 00:07:24.080 |
we also have the reader model, which is the next step. 00:07:35.520 |
and we do from Haystack reader farm, import farm reader. 00:07:49.280 |
we're also going to use something called a pipeline. 00:07:51.680 |
And to use that, we just want to put from Haystack pipeline, 00:08:08.440 |
and we're extracting the answer from the text 00:08:12.560 |
So that's why we're using the extractive QA pipeline. 00:08:18.040 |
Now, that should be everything that we need to import. 00:08:59.240 |
And this is a, I don't know if we covered this already. 00:09:28.440 |
And then we're taking our extractive QA pipeline. 00:09:41.640 |
So that should be everything that we need to do 00:10:06.760 |
And then in here, I'm just going to put like a random query. 00:12:23.240 |
which is, it's basically just an algorithmic retriever. 00:13:06.640 |
And then we'll go with one of these, I think. 00:13:30.400 |
I kind of thought the other one would do better. 00:13:34.120 |
Maybe we need to fine tune it a bit more than what we have. 00:13:43.840 |
And we get good morals and the government of my temper, 00:13:46.840 |
which is, I think pretty exactly what I wanted it to return. 00:13:53.000 |
I see here there's like a new line character as well, 00:14:14.000 |
It's working, but we're not actually making our own queries. 00:14:20.240 |
And to do that, all we need to do is add Q in here. 00:14:28.400 |
And in here, we just make that equal to query. 00:14:51.720 |
So it allows us to send requests really easily 00:15:06.600 |
So localhost 8000, we're going to the query endpoint. 00:15:11.600 |
And then in our query, we have the Q parameter. 00:16:11.200 |
So we'll get a query and then we get answers. 00:16:17.920 |
Universe loves to make whatever it is about to be. 00:16:32.040 |
which pervades all substance and through all time 00:16:34.720 |
by fixed periods, revolutions and minuses the universe. 00:17:02.080 |
we've just done like this entire section here and the API. 00:17:08.240 |
I mean, we'll probably make changes in the future, 00:17:20.560 |
probably the most difficult bit, at least for me, 00:17:23.560 |
which is going to be the front end in Angular.