WEBVTT

00:00.160 --> 00:00.760
Hey there.

00:00.800 --> 00:01.440
Eden here.

00:01.440 --> 00:06.440
And in this video, we'll be implementing the chains that will run in our graph.

00:06.720 --> 00:12.640
So we'll be implementing the generation chain which is going to be responsible to generate and revise

00:12.680 --> 00:15.200
our tweets until it's better and better again.

00:15.360 --> 00:18.040
And we're going to be implementing the reflection chain.

00:18.040 --> 00:21.040
So that chain is going to take our tweet.

00:21.040 --> 00:22.760
And it's going to give us feedback on it.

00:22.800 --> 00:24.000
It's going to critique it.

00:24.000 --> 00:28.480
And it's going to give us suggestions on how to make it better and better.

00:28.720 --> 00:35.960
And every iteration of our cycle in our graph, we're going to be feeding this critique into our generation

00:35.960 --> 00:36.360
chain.

00:36.360 --> 00:38.680
And we're going to be revising the prompt.

00:38.720 --> 00:44.120
So first, before we build the graph we need to build the components that will run inside it.

00:44.440 --> 00:46.160
So let's go and write some code.

00:47.440 --> 00:51.520
Now it's time to create a new file and we'll call it chains.

00:52.160 --> 00:58.840
So this file will hold all of our prompts and chains that we're going to be using in our graph graph.

01:00.080 --> 01:01.880
So let's start with the imports.

01:01.920 --> 01:06.560
So we'll first import chat prompt template and messages placeholder.

01:06.960 --> 01:12.900
Just a reminder the chat prompt template is going to hold our content that we either sent to the LLM

01:12.940 --> 01:19.220
as humans, or that we receive back from the LLM as an answer that is tagged as an AI.

01:21.020 --> 01:28.380
And the second class is the messages placeholder, which is going to give us flexibility to put here

01:28.380 --> 01:31.820
a placeholder for future messages that we're going to get.

01:33.740 --> 01:36.300
The second import is going to be chat open AI.

01:37.140 --> 01:37.780
Alrighty.

01:37.780 --> 01:41.700
So now it's time to write our prompts and chains.

01:42.100 --> 01:48.140
The first prompt we're going to write is going to be called the reflection prompt in our agent architecture.

01:48.420 --> 01:51.500
Then this prompt is supposed to act as our critique.

01:51.740 --> 01:53.980
So it's going to review the output.

01:53.980 --> 01:58.660
And in this case is a Twitter post and it's going to criticize it.

01:58.660 --> 02:03.460
So it's going to say how it can be better and a suggestion to improve it.

02:04.020 --> 02:04.900
And let's have a look.

02:04.900 --> 02:06.620
So we have here a system message.

02:07.020 --> 02:09.060
And you can really tell the following.

02:09.580 --> 02:11.700
You're a viral Twitter influencer.

02:11.740 --> 02:12.740
Creating a tweet.

02:12.740 --> 02:16.220
Generate critique and recommendation for the user's tweet.

02:16.380 --> 02:22.140
Always provide detailed recommendations including requests for length, virality, style, etc..

02:22.980 --> 02:26.650
Now we want to put here a placeholder for other messages.

02:26.650 --> 02:32.170
And those are going to be the history messages that our agent is going to invoke and to criticize and

02:32.170 --> 02:34.370
get recommendations over and over again.

02:34.650 --> 02:40.210
So here you can see that we put a messages placeholder and the variable name is going to be messages.

02:40.210 --> 02:46.690
So when we initialize the reflection point we're going to plug in to this prompt in the messages.

02:46.690 --> 02:49.810
And it's going to contain a lot of messages of our history.

02:50.250 --> 02:52.730
So this was the reflection prompt.

02:52.770 --> 02:55.490
Now we're going to be writing the generation prompt.

02:55.930 --> 03:02.450
And in our agent architecture, the generation prompt is going to generate the tweets that are going

03:02.450 --> 03:08.370
to be revised over and over again after the feedback we get from the reflection prompt.

03:08.570 --> 03:12.890
So it's going to revise the tweet until it gets the perfect tweet.

03:13.610 --> 03:16.370
So let's paste this baby and review it.

03:16.890 --> 03:19.010
And this is the message is the following.

03:19.250 --> 03:24.890
You are a Twitter techie influencer assistant tasked with writing excellent Twitter posts.

03:24.930 --> 03:28.570
Generate the best Twitter posts possible for the user's request.

03:28.610 --> 03:36.230
If the user provides critique, respond with a revised version of your previous attempts And this is

03:36.230 --> 03:39.470
going to be our generation prompt or creator prompt.

03:39.470 --> 03:46.390
You can name it however you like, but it's a goal over here is to revise the tweet for it to be perfect

03:46.390 --> 03:48.230
based on the feedback it gets.

03:48.830 --> 03:55.430
And we also want to put here a placeholder for all the reflections and revisions that we had earlier.

03:55.430 --> 04:00.510
So it's going to be with the messages placeholder with the key of messages that we're going to plug

04:00.510 --> 04:00.750
in.

04:02.190 --> 04:02.830
All right.

04:02.830 --> 04:04.870
So let's go now and create our chains.

04:04.870 --> 04:07.310
So for that we need to initialize an LM.

04:07.550 --> 04:12.110
And this initialization will default to use GPT 3.5 turbo.

04:13.110 --> 04:15.830
And let's create now two simple chains.

04:15.830 --> 04:18.870
And we'll be using the link chain expression language for that.

04:19.590 --> 04:22.470
So the first chain is going to be the generation chain.

04:22.750 --> 04:26.670
And we're simply going to pipe the generation prompt into the LM.

04:27.350 --> 04:30.630
And the second chain is going to be our reflection chain.

04:30.630 --> 04:33.630
And we're going to pipe it into the LM as well.

04:34.310 --> 04:36.350
So that's pretty much it for this video.

04:36.350 --> 04:40.990
And in the next video we'll be implementing finally our land graph.

04:40.990 --> 04:41.590
Graph.
