<b>We can also link</b> <b>multiple chains together. </b> <b>In other words, we can take the output</b> <b>from one chain and pass it in as the</b> <b>input for the next chain. </b> <b>Let's take the scenario</b> <b>where we have two chains.
</b> <b>The first chain is a chef that will come</b> <b>up with a unique recipe</b> <b>based on the main</b> <b>ingredient that we will provide. </b> <b>That recipe will then be</b> <b>passed into the next chain</b> <b>and that chain will be a food critic</b> <b>which will write a review of that recipe. </b> <b>So let's give this chain a name of chef</b> <b>and let's also change</b> <b>the prompt template.
</b> <b>Let's open up this window</b> <b>and let's enter a text like</b> <b>"You are an experienced chef. Create a</b> <b>unique recipe using the main ingredient</b> <b>and then in curly braces let's add a</b> <b>variable called ingredient</b> <b>like so. Let's save this.
</b> <b>Now let's map the input from the chat box</b> <b>to this ingredient</b> <b>variable by clicking on</b> <b>format prompt values. Let's remove</b> <b>subject and let's add a new</b> <b>key value called ingredient. </b> <b>That is what we called it in the prompt</b> <b>template.
Let's press enter. </b> <b>Now let's click on edit. Let's click on</b> <b>this input box and let's select the</b> <b>question from the chat box.
</b> <b>Let's test this out by saving the chat</b> <b>flow and now let's test</b> <b>this by clicking on chat. </b> <b>Let's expand this and let's enter a main</b> <b>ingredient like chicken</b> <b>and indeed we are getting</b> <b>a recipe back from our chef chain. Now</b> <b>let's have a look at how we can pass the</b> <b>output of this chain</b> <b>over to a critic chain.
First let's</b> <b>create that critic chain and</b> <b>typically when we build these</b> <b>flows we build them from left to right. </b> <b>So the data flows from the</b> <b>left which receives our user</b> <b>input and these variables including the</b> <b>user input and the output from</b> <b>this chain is passed along to</b> <b>the right side of this canvas. Let's go</b> <b>ahead and add the chain for our critic.
</b> <b>So under nodes go to</b> <b>chains then let's add the LLM chain. This</b> <b>chain expects a language</b> <b>model and a prompt so let's</b> <b>add the language model first by going to</b> <b>LLMs and let's add the</b> <b>openai node like so. Then let's</b> <b>connect this node to our chain.
Let's</b> <b>also set its credentials by clicking on</b> <b>this drop down and let's</b> <b>select the credentials that we created</b> <b>earlier and that is the</b> <b>nice thing about the way that</b> <b>flowwise is managing credentials is we</b> <b>can reuse those credentials</b> <b>throughout our nodes. We can</b> <b>leave the model name and temperature as</b> <b>is. Let's also add our prompt</b> <b>template so let's go to nodes</b> <b>let's go to prompts and let's add our</b> <b>prompt template.
Let's also</b> <b>attach the prompt template</b> <b>to the chain and let's enter our prompt</b> <b>template. Let's click on</b> <b>expand and let's enter something</b> <b>like you are a food critic. In fact it</b> <b>changes to you are a harsh</b> <b>and rude food critic.
Write a</b> <b>review about the following recipe and</b> <b>then in curly braces let's</b> <b>enter a placeholder called</b> <b>recipe like so. Let's save this. Now</b> <b>let's think about what we want to do</b> <b>here.
First the Chef</b> <b>chain will execute and it will generate a</b> <b>unique recipe based on the</b> <b>ingredient that we provide</b> <b>in the chat box and it is this recipe</b> <b>that should be injected into this prompt</b> <b>template in the recipe</b> <b>variable. So if we click on format prompt</b> <b>values and next to this</b> <b>recipe field if we click on edit</b> <b>and if we click on this field we only see</b> <b>the question and chat</b> <b>history still which is not what</b> <b>we want. So how can we get the output of</b> <b>this chain and inject it into this</b> <b>prompt.
We can do that by</b> <b>changing the output from this chain to</b> <b>output prediction and now</b> <b>let's connect this chain to</b> <b>the input of this prompt template. Let's</b> <b>now click on format prompt</b> <b>values and let's click on edit</b> <b>and when we click on this field we now</b> <b>have the output of Chef</b> <b>available over here. Let's now</b> <b>close this.
Let's name this chain as well</b> <b>as critic and let's save</b> <b>this. So let's test this. </b> <b>Let's clear the previous chat and let's</b> <b>enter an ingredient like</b> <b>potatoes.
Now let's see what</b> <b>happens. So we do get a response back but</b> <b>it's not great. It seems</b> <b>like the sentence is sort of</b> <b>starting halfway through and it's not</b> <b>ending correctly either</b> <b>and this comes down to the</b> <b>quality of the model that we're using</b> <b>over here.
Clearly this GPT</b> <b>3. 5 instruct model only works</b> <b>for very simple use cases so I do want to</b> <b>show you a way more</b> <b>powerful model that will greatly</b> <b>improve the quality of the output but I</b> <b>wanted to show you the difference in</b> <b>quality in this video</b> <b>and hopefully you'll agree with me that</b> <b>the next model that I'm going</b> <b>to show you is way better to</b> <b>use going forward. Let's delete this node</b> <b>and let's add a different</b> <b>model.
So under add nodes</b> <b>instead of adding an LLM let's add a chat</b> <b>model and within chat</b> <b>models let's add the chat open</b> <b>AI model and this will give us access to</b> <b>a few powerful models like</b> <b>the GPT 4 and GPT 3. 5 turbo</b> <b>models that are currently being used by</b> <b>chat GPT. Let's set the</b> <b>credentials to flow wise tutorial.
</b> <b>Let's change the model name to the newer</b> <b>GPT 3. 5 turbo 1106 model and</b> <b>let's set the temperature to</b> <b>0. 7.
Let's save this chat flow. Let's</b> <b>test it now. I'm going to clear this</b> <b>chat.
Let's enter potatoes</b> <b>again and let's have a look at the output</b> <b>and we can already see a</b> <b>massive improvement in the</b> <b>quality of the output. The sentence</b> <b>structure and everything is just</b> <b>absolutely perfect and one thing</b> <b>to note is although we have two chains in</b> <b>our flow the sheaf chain and</b> <b>the critic chain we only see</b> <b>the output of the final chain in our flow</b> <b>which is the critic chain. </b> <b>We do not see the recipe that</b> <b>is being generated by the sheaf however</b> <b>you can see that output</b> <b>from all the different chains</b> <b>by having a look at your console.
So in</b> <b>the console we can see the</b> <b>recipe that was generated</b> <b>and then the final result which was the</b> <b>output of the final chain in our flow</b> <b>which was the critic</b> <b>chain. So having a look at the console</b> <b>could be very helpful</b> <b>for debugging these flows.