44

In the API of GPT-4 and ChatGPT, the prompt for a chat conversation is a list of messages, each marked as one of three roles: system, user or assistant.*

I understand which information this represents - but what does the model with that information?

Is there a difference between a chain of messages with user and assistant alternating, compared to the same messages, with all the same role of either user or assistant?

To make a difference, it seems the role would need to be encoded into the prompt of the language model. Otherwise, it would be just the concatenation of the previous messages.

So, what is the effect of the roles?


  • There is also the role function since recently, but that has a specific well defined purpose, so it is not relevant here.
Volker Siegel
  • 797
  • 1
  • 6
  • 17

4 Answers4

33

I think below examples will help to understand Chat GPT roles quickly:

  1. Role "user" : It means you or who is chatting or who is asking to chat gpt.

Example: (API Request)

    {
      "model": "gpt-3.5-turbo",
      "messages": [
       {
          "role": "user",
          "content": "tell me a joke"
       }
      ]
     }
  1. Role "assistant" : It means open AI(chat gpt) server - who is replying your("user" role) questions.

Example: (API Response)

{
"id": "chatcmpl-87n798n6bv4678",
"object": "chat.completion",
"created": 1683212418,
"model": "gpt-3.5-turbo-0301",
"usage": {
    "prompt_tokens": 12,
    "completion_tokens": 18,
    "total_tokens": 30
},
"choices": [
    {
        "message": {
            "role": "assistant",
            "content": "why did the chicken cross the road"
        },
        "finish_reason": "stop",
        "index": 0
    }
 ]
}

If need to continuous chat conversation with previous context- text from both role (user + assistant) need to send to the API.

Example: (API Request)

    {
      "model": "gpt-3.5-turbo",
      "messages": [
       {
          "role": "user",
          "content": "tell me a joke"
       },
       {
          "role": "assistant",
          "content": "why did the chicken cross the road"
       },
       {
          "role": "user",
          "content": "I don't know, why did the chicken cross the road"
       }
      ]
     }
  1. Role "system" : It means the system developer who can internally give some instructions for the conversation. developer can provide option for user input also which depends on the system requirements.

Example: (API Request)

    {
      "model": "gpt-3.5-turbo",
      "messages": [
       {
          "role": "user",
          "content": "tell me a joke"
       },
       {
          "role": "system",
          "content": "You are an assistant that speaks like Shakespeare."
       }
      ]
     }

Suppose you are developing a system to generate SQL query and you internally can tell to chat gpt to generate sql based on users given instructions.

Hope this will help. Thanks.

Reference: https://help.openai.com/en/articles/7042661-chatgpt-api-transition-guide

Touhid
  • 431
  • 3
  • 4
1

Want to add more explanation on the system role. Since LLM is a versatile model capable of many general tasks, to make it adapt to a specific task, we could use the prompt added as system role. Then the LLM would follow the instructions as specified in the system prompt.

To give you an example, following is the system prompt for an AI research and writing assistant, aka AI writer.

You are Rabrain, a highly skilled research and writing assistant.
Your primary goal is to assist users in crafting clear, concise, and well-researched content.
Maintain an unbiased and professional tone in all communications.
Unless instructed otherwise, respond in the same language as the user's query.

By adding this system prompt, it tells the LLM who it's, what are its goals etc.

James
  • 111
  • 3
1

The role system in ChatGPT’s API is pretty fascinating—and it’s really what makes the whole interaction feel so human. Here’s why it’s important:

The system role is like setting the stage. Think of it as the guiding hand that tells the AI, "Here’s how you should show up in this conversation." It’s why, if you ask it to be a friendly teacher, it speaks like one. Without this, the AI could feel a lot more mechanical, like it’s just throwing out words without any personality.

Then there’s the user role—that’s you! When a message is marked as “user,” the AI knows this is your voice, your questions, your thoughts. It’s not just random text to respond to; it knows these are genuine prompts, something you’re putting out there to get a real answer.

And assistant? That’s the AI’s own responses. Labeling the AI’s past messages this way is what lets it “remember” its responses and keep up with the back-and-forth flow of a real conversation. When you see the assistant responding to your questions and sticking to the topic you care about, it’s because it can look back on its previous answers and stay on track.

Now, here’s why the roles really matter: If you stripped away these labels, if every message was just “user” or all “assistant,” the whole structure would fall apart. The AI wouldn’t know if a message is something it already responded to or something new it needs to answer. It would lose the thread of the conversation, leaving you with confusing, disjointed responses. It’s kind of like having a conversation where everyone talks over each other—you’d just end up feeling unheard.

0

In the API of GPT-4/ChatGPT, the roles—system, user, and assistant—serve specific functions in facilitating interactions between the AI and the user. Here’s a breakdown of each role:

  1. System Role • Purpose: The system role is used to set the overall behaviour and guidelines for the assistant. It can include instructions about how the assistant should respond, the context of the conversation, or any constraints on its responses. • Example Use: You might configure the system to specify that the assistant should be formal, informative, or follow specific ethical guidelines.

  2. User Role • Purpose: This role represents the input from the human user interacting with the assistant. It captures the queries, requests, or prompts given by the user. • Example Use: Any message the user types, such as a question, command, or request for information, is categorized as coming from the user role.

  3. Assistant Role • Purpose: The assistant role represents the responses generated by the AI model. It reflects the output of the model based on the input provided by the user and any system instructions. • Example Use: The messages that the AI sends back to the user in response to their prompts fall under this role.

Interaction Flow • The interaction typically follows this flow:

  1. System: Initial setup or context is provided.
  2. User: The user inputs a question or command.
  3. Assistant: The AI responds based on the user input and the guidelines set by the system.

Summary • System sets the context and behaviour. • User initiates the conversation and provides inputs. • Assistant generates responses based on user inputs and system instructions.

ChatGPT - This role structure helps to streamline interactions and ensures that the AI behaves according to the specified guidelines while responding to user queries effectively.

For more tips refer to, CHATGPT USERS GAIN DIRECT ACCESS TO GPTS IN CHAT CONVERSATIONS: https://promptengineer-1.weebly.com/ai-developments/chatgpt-users-gain-direct-access-to-gpts-in-chat-conversations