Skip to Content

How to Use the System Role in OpenAI Chat Completions API

  • The system role is a feature of OpenAI Chat Completions API that lets you instruct the chatbot on how to behave in a conversation.
  • To use the system role, you need to write a system instruction for your chatbot using the system role, and send it to the Chat Completions API along with the user’s message.
  • To write effective system instructions, you need to use simple and direct language, be specific and detailed, be consistent and coherent, be realistic and reasonable, and test and refine your system instruction.

OpenAI Chat Completions API is a powerful tool that allows you to create conversational agents that can interact with users using natural language. You can use this API to build chatbots for various purposes, such as customer service, entertainment, education, and more.

One of the features of the Chat Completions API is the system role, which lets you specify instructions for the chatbot on how to behave in a conversation. For example, you can tell the chatbot to act like a helpful assistant, a friendly companion, or a professional expert. You can also give the chatbot specific guidelines on what to say or not to say, how to handle different scenarios, and how to personalize the responses.

In this blog post, we will show you how to use the system role in OpenAI Chat Completions API to optimize your chatbot’s performance and user experience. We will also share some tips and best practices on how to write effective system instructions for your chatbot.

How to Use the System Role in OpenAI Chat Completions API

What is the system role and why is it important?

The system role is a special type of message that you can send to the Chat Completions API to instruct the chatbot on how to behave in a conversation. The system role is not visible to the user, but it influences the chatbot’s responses and actions.

The system role is important because it helps you align your chatbot’s behavior with the search intent of the user. Search intent is the reason why a user is looking for a particular topic or query. For example, if a user is searching for “how to become a wedding planner”, their search intent could be to learn the steps, the requirements, or the tips to achieve their goal.

By using the system role, you can tell the chatbot to match the search intent of the user and provide the most relevant and helpful information. For example, you can tell the chatbot to act like an expert who can guide the user through the process of becoming a wedding planner, or to act like a mentor who can share their personal experience and advice.

By matching the search intent of the user, you can improve the quality and satisfaction of the conversation, as well as the trust and credibility of your chatbot.

How to use the system role in OpenAI Chat Completions API?

To use the system role in OpenAI Chat Completions API, you need to follow these steps:

  1. Identify the target keyword or query that you want your chatbot to answer. For example, “how to become a wedding planner”.
  2. Analyze the search intent of the user by looking at the top-ranking pages for your target keyword or query. You can use tools like Ahrefs or Semrush to do this. Look for the content type, content format, and content angle of the top-ranking pages. For example, for the keyword “how to become a wedding planner”, the content type is mostly blog posts, the content format is mostly how-tos, and the content angle is varied (e.g., “according to experts”, “number of steps”, “without any experience”).
  3. Choose a suitable behavior and tone for your chatbot based on the search intent of the user. For example, for the keyword “how to become a wedding planner”, you can choose to make your chatbot act like an expert, a mentor, or a friend.
  4. Write a system instruction for your chatbot using the system role. The system instruction should be clear, concise, and specific. It should tell the chatbot what to do or not to do, how to do it, and why to do it. For example, for the keyword “how to become a wedding planner”, you can write a system instruction like this:{role: “system”, content: “You are an expert wedding planner who can teach the user how to become one. You should provide practical and actionable steps, as well as useful tips and resources. You should also be friendly and supportive, and encourage the user to pursue their dream.”}
  5. Send the system instruction to the Chat Completions API along with the user’s message. The system instruction should be the first message in the messages array. For example, for the keyword “how to become a wedding planner”, you can send a request like this:openai.ChatCompletion.create( model=“gpt-3.5-turbo”, messages=[ {role: “system”, content: “You are an expert wedding planner who can teach the user how to become one. You should provide practical and actionable steps, as well as useful tips and resources. You should also be friendly and supportive, and encourage the user to pursue their dream.”}, {role: “user”, content: “Hi, I want to become a wedding planner. How do I start?”} ] )
  6. Receive the chatbot’s response from the Chat Completions API. The chatbot’s response should be influenced by the system instruction and match the search intent of the user. For example, for the keyword “how to become a wedding planner”, you can receive a response like this:{role: “assistant”, content: “Hello, and welcome to the Wedding Planner Academy. I’m here to help you achieve your dream of becoming a wedding planner. Becoming a wedding planner is a rewarding and exciting career, but it also requires a lot of skills, knowledge, and experience. To start, you need to have a passion for weddings, a good sense of style, and excellent communication and organizational skills. You also need to learn the basics of wedding planning, such as budgeting, contracts, vendors, venues, themes, timelines, and more. There are many ways to learn these skills, such as taking online courses, reading books and blogs, watching videos, or attending workshops. One of the best resources I can recommend is the Wedding Planner Certification Course by The Bridal Society, which is the leading wedding planner certification program in the world. You can find more information about it here.”}

How to write effective system instructions for your chatbot?

Writing effective system instructions for your chatbot is not an easy task. It requires a lot of creativity, research, and testing. Here are some tips and best practices to help you write better system instructions for your chatbot:

  • Use simple and direct language. Avoid using jargon, slang, or ambiguous words. Make sure your system instruction is easy to understand and follow for the chatbot.
  • Be specific and detailed. Don’t leave anything to the chatbot’s imagination. Tell the chatbot exactly what to do or not to do, how to do it, and why to do it. Provide examples, scenarios, or templates if possible.
  • Be consistent and coherent. Make sure your system instruction matches the overall tone and style of your chatbot and your brand. Don’t switch between different behaviors or tones in the same conversation. Keep your system instruction aligned with the search intent of the user and the goal of the conversation.
  • Be realistic and reasonable. Don’t expect your chatbot to do things that are beyond its capabilities or scope. Don’t ask your chatbot to perform complex tasks, provide sensitive information, or give personal opinions. Don’t make your chatbot sound too human or too robotic. Find a balance between being natural and professional.
  • Test and refine your system instruction. Don’t rely on your intuition or assumptions. Test your system instruction with real users and see how they react and respond. Collect feedback and data, and use them to improve your system instruction. Experiment with different variations and see what works best.

Frequently Asked Questions (FAQs)

Question: What is the system role in OpenAI Chat Completions API?

Answer: The system role is a special type of message that you can send to the Chat Completions API to instruct the chatbot on how to behave in a conversation.

Question: Why is the system role important?

Answer: The system role is important because it helps you align your chatbot’s behavior with the search intent of the user and provide the most relevant and helpful information.

Question: How do I use the system role in OpenAI Chat Completions API?

Answer: To use the system role in OpenAI Chat Completions API, you need to write a system instruction for your chatbot using the system role, and send it to the Chat Completions API along with the user’s message. The system instruction should be the first message in the messages array.

Question: How do I write effective system instructions for my chatbot?

Answer: To write effective system instructions for your chatbot, you need to use simple and direct language, be specific and detailed, be consistent and coherent, be realistic and reasonable, and test and refine your system instruction.

Question: Where can I find more information and examples of the system role in OpenAI Chat Completions API?

Answer: You can find more information and examples of the system role in OpenAI Chat Completions API on the official documentation, the OpenAI developer forum, and the OpenAI blog.

Summary

In this blog post, we have learned how to use the system role in OpenAI Chat Completions API to optimize your chatbot’s performance and user experience. We have also shared some tips and best practices on how to write effective system instructions for your chatbot. We hope you have found this post useful and informative. If you have any questions or feedback, please feel free to leave a comment below.

Disclaimer: This blog post is not sponsored or endorsed by OpenAI. The opinions and views expressed in this post are solely those of the author and do not reflect the official position of OpenAI.