24

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
  • 589
  • 1
  • 4
  • 17
  • Presumably the same thing it does with all other information: feed it through several very large black boxes. – user253751 Mar 30 '23 at 17:14
  • @user253751 I actually suspect that it does not go into the black box like everything else. Either it is used to change the prompt text itself - but that seems strange. Or, if it is not discarded, it must have some other way in, ifs very special entrance to the black box. – Volker Siegel Mar 31 '23 at 18:01
  • 2
    it could just be like an extra token that can't be produced by text. The first stage of processing is to split up the input text into tokens. These tokens are fed into the black box. It's trivial to add more tokens that the splitter can't generate. – user253751 Mar 31 '23 at 18:21
  • Oh yes, that makes totally sense! – Volker Siegel Apr 01 '23 at 00:30
  • 1
    I'm not sure if it applies to every GPT model, but one I found ([here](https://platform.openai.com/docs/api-reference/chat/create)) also has a fourth role called `function`. – stevec Jun 29 '23 at 10:11
  • 1
    @stevec Thanks! That seems to be a new feature. – Volker Siegel Jun 30 '23 at 08:57
  • What does "function" do? After reading the documentation I still don't understand – pete Jul 05 '23 at 05:04
  • @pete it is hard to understand what it does because it does not actually do anything. It allows the user/application programmer to do something for the model, in a formalized way. – Volker Siegel Jul 11 '23 at 00:14
  • 1
    @VolkerSiegel That was a confusing comment. Surely "does not actually do anything" is not accurate, based on your 2nd sentence (where it's still not clear to me what it does) – pete Jul 12 '23 at 05:08

1 Answers1

16

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
  • 261
  • 4
  • If I'm understanding correctly and: user assistant user are executed in order, is it possible to use the output from each of these in the next command? e.g.: `user: 'tell me a joke`, `assistant: why did the chicken cross the road`, `user: I dont know why did the chicken cross the road`, `assistant generates content into variable $response`, `user: $response is a great joke, can you make another similar one?` – timhc22 Aug 21 '23 at 17:41