Let's talk about models in land change.
So when land change talks about models in the land change documentation, what are they talking about?
They are talking about the foundational models upon which LM applications are built.
So what we call foundation models, foundation LM models so long chain connects with two types of models.
So in the long chain world a long chain connects with two kinds of models.
First what they call LMS and second, what they call chat models.
LMS for long chain are models that receive text and respond with text and chat models.
For long chain a receive a chat message and respond with a chat message.
So in the code on the right side of the screen, we are going to try an example a connecting long chain
with the OpenAI LM model, and also connecting long chain with llama to an open source model.
So the first thing we do, as always, is to, uh, connect with the env file in order to load the OpenAI
key.
And after that, what we do is we load the OpenAI module, we create an instance of our LM, and we
just send any question to that instance, and we will have the response from a chat.
GPT in this case we can do the same thing for llama too.
In the case of llama too, we have two options.
We can run llama to locally, or we can use llama to in the cloud.
It's best.
The second option.
The first option.
Here you have a link to do that using a llama I.
But it's too complex and uh, I would not recommend recommend that way.
Right now this is much easier and simpler.
You know, just use an external API, uh, that you can do with replicate.
And here we provide you a link where you can get your free, uh, API token.
So once you have that, you load the replicate module, you, uh, create the, the LM, uh, llama
to lm an instance of that llama to LM, and then you can use it in the same way we have been using the
OpenAI.
What is going to be the difference?
The difference is going to be the quality of the response and the speed of the response.
Llama two is a very good model in in some cases is similar in quality than OpenAI.
In some other cases is a little bit lower in quality.
Second case.
We can use.
Well, here you have a just a quick note saying that you can achieve this same functionality with two
other alternative ways.
First, we can use instead of using this my Elm question, we can use my LM dot predict question or
dot invoke question.
This is going to generate exactly the same output.
These are different ways that long chain provide us.
In order to connect with a chat model a see that we are loading here.
The chat OpenAI module is not the OpenAI module, now is the chat OpenAI module.
And we are also need to load human message and system message.
In this case to create an instance of a.
The OpenAI chat is very easy.
And to create the content, the question is a little bit more elaborate than before.
In this case, we have the option to tell a OpenAI the chat.
We have the option to instruct about the role that he's going to play.
In this case, we are using System message to tell ChatGPT you are a helpful and concise assistant.
And here in Human Messages where we include our question.
So in this case we say name the most popular for us first ladies.
The way to get the response is very similar in this case.
But you see that the response is printed in a different way.
See the content here.
Right.
So if we print the type of the response it's very interesting because now we are getting a class.
And before if you bring the type of the response that an LM is getting is is sending is a string, okay,
this is important.
And you will see then that in this uh, scenario is where we may think about using what we call output
parsers.
We will talk about them later, but in short, output parsers allow us to format the response we get
from the LM model in a different way.
We can say, okay, instead of strings, I want to have the output in a Json dictionary, or I want
to have the output in Python list or whatever.
So.
This is how we connect with a chat model.
And here you have a link to the LMS with native integration with a long chain, and also the chat models
with native integration with long chain.