WEBVTT

00:00.120 --> 00:05.720
Messages are the fundamental units of communicating with llms.

00:05.760 --> 00:14.120
When working with chat models in Linkchain, they carry the input we want to send to the LM and the

00:14.120 --> 00:16.120
output we receive back.

00:16.560 --> 00:19.680
Every message has two essential parts.

00:19.680 --> 00:23.160
It has a role and it has content.

00:23.680 --> 00:26.680
The role tells the model who sent the message.

00:27.040 --> 00:33.200
The content holds the actual information, which is typically text, but can also include things like

00:33.200 --> 00:37.680
images, videos, or other data for multimodal models.

00:38.000 --> 00:45.400
Linkchain standardizes these messages, allowing us to work with different chat model provider using

00:45.400 --> 00:47.120
a consistent format.

00:47.240 --> 00:50.880
So this means it doesn't matter which LM we're using.

00:51.080 --> 00:55.200
We still use the same interface, which is very, very convenient.

00:55.600 --> 00:59.320
So let's take a look on the different roles messages can have.

00:59.680 --> 01:06.570
We have the system role which is used to set up the AI's behavior or to provide initial context.

01:06.610 --> 01:13.330
For instance, you might use a system message to tell the model to act as a helpful assistant or to

01:13.370 --> 01:15.970
summarize complex documents concisely.

01:16.490 --> 01:19.410
Not all models handle system message, by the way.

01:19.690 --> 01:21.970
Some use a dedicated parameter.

01:22.010 --> 01:24.770
Other integrated into the message history.

01:24.970 --> 01:27.170
And few don't support it at all.

01:27.210 --> 01:34.450
However, Linkchain tries to handle these variations for us and it's going to create one single interface.

01:35.410 --> 01:43.610
The user role represents input coming from a person or system interacting with the model in Linkchain.

01:43.650 --> 01:46.330
We'll use the human message class for this.

01:46.850 --> 01:55.050
When we send text to a chat model, like asking a question or giving an instruction, we wrap that content

01:55.050 --> 01:57.210
in a human message class.

01:57.530 --> 02:00.170
Linkchain even offers us a shortcut.

02:00.210 --> 02:06.980
If we want to invoke a model with just a string, it's automatically being treated as a human message.

02:07.860 --> 02:10.660
The assistant role is the model's response.

02:11.100 --> 02:16.220
This output is representative by the AI message class in LinkedIn.

02:16.740 --> 02:25.340
When the model answers our question or completes a task, its response comes back as an AI message object.

02:25.660 --> 02:33.860
These messages contain the main content generated by the large language model, along with other information

02:33.860 --> 02:41.300
like metadata or tool calls, token usage information, and unique identifiers to help us in debugging.

02:41.900 --> 02:46.380
Tool role will elaborate this when we talk about agents and function calling.

02:46.580 --> 02:52.380
But overall, it's a way for us to tell the AI what was the result of the tool execution.

02:52.460 --> 02:59.060
For example, if we invoked a tool that gets us the weather in somewhere, then we're going to wrap

02:59.060 --> 03:02.540
that answer in a tool message object.

03:02.540 --> 03:06.760
And that's how we're going to tell the model that that's the result of the tool call.

03:06.760 --> 03:08.840
So it can give us the final answer.

03:08.840 --> 03:11.360
But don't worry if you don't fully understand this part.

03:11.400 --> 03:15.280
We're going to elaborate a lot on this topic in the course.

03:16.200 --> 03:24.680
The order of these messages is important for a coherent conversation, and a typical flow involves alternating

03:24.680 --> 03:27.880
between user input and assistant responses.

03:28.200 --> 03:34.640
So it's going to be human message, then AI message, then human message, then AI message, and so

03:34.640 --> 03:34.920
on.

03:35.400 --> 03:42.920
If tools are involved, we probably see them in like and if tools are involved, we'll see this in human

03:42.920 --> 03:43.560
message.

03:43.600 --> 03:51.000
AI message with a tool call, then a tool message with the tool result, then an AI message using the

03:51.000 --> 03:53.160
tool result, and so on and so on.

03:53.200 --> 04:01.000
And just to conclude, link Messages object provide us with a consistent way to build these conversations,

04:01.040 --> 04:06.800
abstracting away the specific message formats required by different providers.
