The chat model takes a series of messages as input and returns the message generated by the model as output.
Although the chat format makes it easy to have multiple rounds of conversation, it is equally suitable for single-round tasks without any conversations. An example of an API call is as follows:
The messages parameter is the most important parameter in the createChatCompletion method, which contains multiple message objects. Each message has a role and can besystem、user、assistantAny of them.
- user: Represents the message sent by the user, that is, the question or instruction entered by the user. In the above code, both the second and fourth messages are of type user.
- assistant: Represents the answer or response given by the chatbot by calling an AI algorithm. In the above code, the third message is an assistant type message.
- system: Represents a message sent by the system or client through code. The purpose of system messages is to provide further guidance or instructions to the assistant so that it can respond better.
A chat begins with a message of type system, followed by alternating messages of type user and assistant. A message of type system can help set the behavior of the assistant and guide how it should answer the user's question, such as the system message "You are a very useful AI assistant" in the example above.
The entire list of messages can be very short, with only one message, or very long, taking up several pages.
Chat history is also important in chatbot interactions, as the user's instructions may need to reference previous message information. In the code example above, the user's last question "Who is the champion?" "It only makes sense when the 2022 World Cup is mentioned in previous news.
Since the machine learning model does not have a memory of previous requests, it must provide all relevant information through the conversation. If a dialog doesn't fit within the model token limit, some shortening is required.
|