Text vs System vs Message Prompts — Transcript

Transcript of the free Vue.js lesson Text vs System vs Message Promptswatch the video lesson.

Prompts are the instructions that we give to a large language model to tell it what to do. You've already seen the most basic form of a prompt in the last lesson. This is known as a text prompt, plain and simple. But there are two other types of prompts that are useful with the AISDK.

There are system prompts, and then there are also message prompts. Let's take a look at how both of those work and why they might be useful. I've created a new file in the project called 5 system and messages for us to see a system prompt in action. The system prompt with the AISDK is provided under the system key.

In this example, the value is set to you are a helpful assistant that answers questions concisely and in markdown format. Important, always be concise. So notice here, my system prompt gives some instructions on how to output the generated text and it gives some rules on what the content of that generated text should look like. It should be concise, always.

Then my user provided prompt, in this case, it's hard coded, but in your app, this could be dynamic and actually provided by the user. Well, they asked the same question about the most powerful superhero, but they tell the LLM to be verbose. Let's see which one of these instructions, always be concise versus be verbose, will actually end up winning. Run it in the terminal.

And we do certainly get more of an output than we got in the last lesson. It's a paragraph, a couple list items and another paragraph long. But notice this time we are getting marked down in response. That's our system prompt in action.

But I still can't quite tell which rule is winning. Let's remove the instructions to be concise from our system prompt here and here as well, but leave the be verbose instruction inside of the user prompt. And let's see what happens then. Run it again.

This one is certainly taking considerably longer. And would you look at that? That is a whole lot longer than before it's I'm not even going to be able to count all that multiple paragraphs still in markdown form. But now that be verbose instruction from the user carries a lot more weight.

So the idea behind the system prompt is that it's more important or weightier than whatever is passed inside of the normal text prompt. Is it foolproof and always going to protect against destructive or confusing instructions sent in the prompt? No, unfortunately, AI is a little bit more finicky than that, but it is a great step to take. The other type of prompt the AI SDK recognizes is message prompts.

Message prompts are really a special breed that are perfect for chat interfaces. Why? Well, they keep previous messages within the context sent to the LLM. Notice this array that I've provided here.

The first message in the array is a message from the user, but the next message is a message from the assistant. So in a real world application, this probably would have been generated by the LLM at a prior point in the conversation. And then in order to make our conversation stateful, we're able to pass that assistant message back in and then follow it up with another question. This lets the LLM generate a new response based on not just the last message inside the conversation, but on the entirety of the conversation.

Let's change out our system prompt to better illustrate that. Let's tell it to always address the user by name. Notice my name is mentioned in the previous messages, but not in the last one. In the terminal, we'll run our script again.

And sure enough, at the beginning of the response, it says, Hello, Daniel, that's a fantastic and endlessly debated question. To sum up, text prompts are ideal for simple generation use cases, such as generating the title of a chat session in an app like JetGBT, while system prompts are your place to define rules for the LLM that should hold a little more weight than the text prompt. Lastly, we have messages, which are great for chat interfaces as they pass the full history of the conversation.