33
$\begingroup$

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.
$\endgroup$
9
  • $\begingroup$ Presumably the same thing it does with all other information: feed it through several very large black boxes. $\endgroup$
    – user253751
    Mar 30, 2023 at 17:14
  • 2
    $\begingroup$ 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. $\endgroup$
    – user253751
    Mar 31, 2023 at 18:21
  • 1
    $\begingroup$ I'm not sure if it applies to every GPT model, but one I found (here) also has a fourth role called function. $\endgroup$
    – stevec
    Jun 29, 2023 at 10:11
  • 1
    $\begingroup$ @stevec Thanks! That seems to be a new feature. $\endgroup$ Jun 30, 2023 at 8:57
  • 1
    $\begingroup$ @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) $\endgroup$
    – pete
    Jul 12, 2023 at 5:08

1 Answer 1

27
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ 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? $\endgroup$
    – timhc22
    Aug 21, 2023 at 17:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .