Search

Thursday 16 November 2023

SystemMessage in ChatCompletion API and it's impact

In the ChatCompletion API, the 'system' role in the 'messages' array is used to set the behavior of the assistant. The content of a system message is typically an instruction that guides the assistant's behavior throughout the conversation.

For example, consider the following 'messages' array:

"messages": [

    {"role": "system", "content": "You are a helpful assistant."},

    {"role": "user", "content": "Who won the world series in 2020?"}

]

In this case, the system message '"You are a helpful assistant."' sets the behavior of the assistant to be helpful. This instruction guides the assistant's responses to subsequent user messages. So, when the user asks '"Who won the world series in 2020?"', the assistant will try to provide a helpful response, such as looking up the information and providing a detailed answer.

System messages are especially useful for setting the tone or style of the assistant's responses. For example, a system message like '"You speak like Shakespeare."' would guide the assistant to generate responses in a Shakespearean style.

It's important to note that system messages don't directly appear in the conversation with the user. They're only used internally to guide the assistant's behavior. So, you can use system messages to set the assistant's behavior without affecting the flow of the conversation.