Hey there.
Eden here.
And in this video, we'll be implementing the chains that will run in our graph.
So we'll be implementing the generation chain which is going to be responsible to generate and revise
our tweets until it's better and better again.
And we're going to be implementing the reflection chain.
So that chain is going to take our tweet.
And it's going to give us feedback on it.
It's going to critique it.
And it's going to give us suggestions on how to make it better and better.
And every iteration of our cycle in our graph, we're going to be feeding this critique into our generation
chain.
And we're going to be revising the prompt.
So first, before we build the graph we need to build the components that will run inside it.
So let's go and write some code.
Now it's time to create a new file and we'll call it chains.
So this file will hold all of our prompts and chains that we're going to be using in our graph graph.
So let's start with the imports.
So we'll first import chat prompt template and messages placeholder.
Just a reminder the chat prompt template is going to hold our content that we either sent to the LLM
as humans, or that we receive back from the LLM as an answer that is tagged as an AI.
And the second class is the messages placeholder, which is going to give us flexibility to put here
a placeholder for future messages that we're going to get.
The second import is going to be chat open AI.
Alrighty.
So now it's time to write our prompts and chains.
The first prompt we're going to write is going to be called the reflection prompt in our agent architecture.
Then this prompt is supposed to act as our critique.
So it's going to review the output.
And in this case is a Twitter post and it's going to criticize it.
So it's going to say how it can be better and a suggestion to improve it.
And let's have a look.
So we have here a system message.
And you can really tell the following.
You're a viral Twitter influencer.
Creating a tweet.
Generate critique and recommendation for the user's tweet.
Always provide detailed recommendations including requests for length, virality, style, etc..
Now we want to put here a placeholder for other messages.
And those are going to be the history messages that our agent is going to invoke and to criticize and
get recommendations over and over again.
So here you can see that we put a messages placeholder and the variable name is going to be messages.
So when we initialize the reflection point we're going to plug in to this prompt in the messages.
And it's going to contain a lot of messages of our history.
So this was the reflection prompt.
Now we're going to be writing the generation prompt.
And in our agent architecture, the generation prompt is going to generate the tweets that are going
to be revised over and over again after the feedback we get from the reflection prompt.
So it's going to revise the tweet until it gets the perfect tweet.
So let's paste this baby and review it.
And this is the message is the following.
You are a Twitter techie influencer assistant tasked with writing excellent Twitter posts.
Generate the best Twitter posts possible for the user's request.
If the user provides critique, respond with a revised version of your previous attempts And this is
going to be our generation prompt or creator prompt.
You can name it however you like, but it's a goal over here is to revise the tweet for it to be perfect
based on the feedback it gets.
And we also want to put here a placeholder for all the reflections and revisions that we had earlier.
So it's going to be with the messages placeholder with the key of messages that we're going to plug
in.
All right.
So let's go now and create our chains.
So for that we need to initialize an LM.
And this initialization will default to use GPT 3.5 turbo.
And let's create now two simple chains.
And we'll be using the link chain expression language for that.
So the first chain is going to be the generation chain.
And we're simply going to pipe the generation prompt into the LM.
And the second chain is going to be our reflection chain.
And we're going to pipe it into the LM as well.
So that's pretty much it for this video.
And in the next video we'll be implementing finally our land graph.
Graph.