WEBVTT

00:00.360 --> 00:02.337
-: This is a quick video showing you how you can

00:02.337 --> 00:05.790
actually chain multiple LLM requests together.

00:05.790 --> 00:07.980
So we've got our from item getter,

00:07.980 --> 00:09.420
we also import ChatOpen AI,

00:09.420 --> 00:12.570
chat prompt template, and a string output passer.

00:12.570 --> 00:15.120
Now we have two prompts that we're setting up.

00:15.120 --> 00:18.298
Firstly, we have the what is the city person is from,

00:18.298 --> 00:22.590
and we also have the what country is the city?

00:22.590 --> 00:24.660
City in respond in language.

00:24.660 --> 00:26.730
We set up our LLM model,

00:26.730 --> 00:29.010
which in this case is a ChatOpen AI.

00:29.010 --> 00:31.300
We then have the first chain, which is prompt one,

00:31.300 --> 00:34.980
pipe model, pipe string output passer.

00:34.980 --> 00:36.990
And then that gets associated

00:36.990 --> 00:40.290
with a key inside of chain two.

00:40.290 --> 00:42.570
So you can see the result of chain one

00:42.570 --> 00:44.718
will be under the city key, right?

00:44.718 --> 00:49.650
And then the language we are getting from the item getter.

00:49.650 --> 00:53.010
That will then get piped into prompt two.

00:53.010 --> 00:55.680
So that's how we're getting this citY in curly braces,

00:55.680 --> 01:00.210
it says its from our first chain that you can see here.

01:00.210 --> 01:01.650
That then gets piped into the model,

01:01.650 --> 01:04.980
which then also gets piped into a string output passer.

01:04.980 --> 01:07.470
So let's do the invoke on the second chain,

01:07.470 --> 01:09.060
which we'll use the first chain.

01:09.060 --> 01:10.881
So we invoke with a person

01:10.881 --> 01:13.440
and then the language in Spanish.

01:13.440 --> 01:14.820
And then what you'll see is

01:14.820 --> 01:18.510
we're basically saying, what is the city person?

01:18.510 --> 01:21.570
So that'll be what is the city Obama is from.

01:21.570 --> 01:25.170
And then basically when we get the city,

01:25.170 --> 01:28.050
we're then asking what country is the city in?

01:28.050 --> 01:30.270
And then we're asking it to respond in Spanish.

01:30.270 --> 01:31.650
So this is an example of

01:31.650 --> 01:34.509
where you have more than one LLM request.

01:34.509 --> 01:37.770
You've got a chain here, and you've got a chain here,

01:37.770 --> 01:40.048
and you are using the output of chain one

01:40.048 --> 01:43.530
and assigning it to a key of city,

01:43.530 --> 01:44.670
which will then be used

01:44.670 --> 01:46.800
in the prompt template, prompt two.

01:46.800 --> 01:48.570
So the best way that I would recommend thinking

01:48.570 --> 01:50.490
about this is always working backwards.

01:50.490 --> 01:51.738
Like where is the last prompt?

01:51.738 --> 01:53.997
Like what kind of keys does it require?

01:53.997 --> 01:56.010
Oh, okay. It requires a city key.

01:56.010 --> 01:57.610
Oh, that comes from this prompt chain.

01:57.610 --> 02:00.330
The other interesting thing to be thinking about

02:00.330 --> 02:02.907
is you can't just do prompt pipe model

02:02.907 --> 02:06.060
because you can't pass, you know,

02:06.060 --> 02:09.870
an open AI or a lang chain class

02:09.870 --> 02:13.470
into the next as a prompt value.

02:13.470 --> 02:15.180
So what you really need to do is make sure

02:15.180 --> 02:16.830
that you use these string output passes

02:16.830 --> 02:18.960
so the output of chain one

02:18.960 --> 02:20.970
gets associated with a string,

02:20.970 --> 02:22.680
which can then be injected into

02:22.680 --> 02:24.990
the prompt template for prompt two.

02:24.990 --> 02:27.963
Cool. So that was a little bit on making some chains.
