From the course: OpenAI API for Python Developers
Define a system message with instructions
- [Instructor] What is a system message? A system message is used to define the role of a chatbot, to instruct the language model on how to behave in a conversation. And it helps set the behavior of the assistant to adopt a specific tone or to act as a specialist, for example, as a senior UX designer, a professional writer, or as a software engineer. And here you notice the structure of a message object with the key value pair dictionary, with the key's role and content. And with the system message, the benefit is to guide the assistant's behavior during the interaction in order to get optimized results. So in a list of messages that you set as an input to define a prompt, the system message will be the first ever that you find in the list of messages. And this is to give the language model instructions and tell it how it should behave from the beginning, from the start. For example, the basic example is you are a helpful assistant. But it could be other personas like you are a professional writer, you are a math tutor, or any other role that you'd like the chatbot to be. So the goal in this part is to learn to create a chatbot completion, but first we want to define a prompt with a system message. So back in our project, we have this system message that we have defined here, so we're going to use it, but first let's go back to the documentation for a moment. We're going to copy from line four to 12. We're going to grab all of that and make sure that you select Python here from the dropdown. And back in the project, you're going to replace this and display this. What we want is to define a response. So we're going to get a response back from the chatbots. And the first message that we want to define is, of course, the system message. But instead we're going to use the one that we have defined here at the top, which will be an array. So we already have actually this one, the message system, and this list of messages that starts with this system message. So I'm going to replace this example with our own list of messages. Here we go. And after that, what we're going to do is to append new messages from the user and from the assistants with AI generated response. So this is going to be the next step, which is to make requests to generate chat completions.
Contents
-
-
-
-
-
Introduction to conversational AI2m 26s
-
Project setup and overview3m 11s
-
Authentication and configuration2m 38s
-
Define a system message with instructions2m 11s
-
Making requests and generating chat completions6m 6s
-
Challenge: Create a funny chatbot2m 11s
-
Solution: Create a funny chatbot - part 14m 26s
-
Solution: Create a funny chatbot - part 24m 51s
-
-
-
-
-