Welcome to the community!
If you read on:
Including conversation history is important when user instructions refer to prior messages. In the example above, the user’s final question of “Where was it played?” only makes sense in the context of the prior messages about the World Series of 2020. Because the models have no memory of past requests, all relevant information must be supplied as part of the conversation history in each request.
not with chat completions, but you can with the Assistants API: https://platform.openai.com/docs/assistants/overview?context=with-streaming, but this is probably not what you’re asking.
tl;dr: no, you can’t “access” previous messages - you have to include previous messages in your messages array so that the final user query makes sense.
yes, you can mix and match these in the messages array in any order you wish. You don’t even need a system message, if you don’t want to include one.
This all comes down to unfortunate naming.
For your understanding, under the hood, the LLM essentially generates every new word from scratch.
This is oversimplified, but imagine that every time you say a word, we delete you, rebuild you, upload your entire life to your new brain, wait for you to generate the next word, delete you again, and start the whole process over.
The model has no real conception of whether it’s the assistant, or the user. If OpenAI didn’t prevent it through their programming, it should be possible to upload a conversation with a user message cut off somewhere in the middle, and the model would be perfectly happy to assume the user role.
With every new API request, you need to re-upload the entire conversation history in order for the model to generate the next message.
This is also incredibly powerful, because it gives you the ability to edit the model’s past and history, so to speak.
If you want to understand this better, I would urge you to play around with the base completions endpoint https://platform.openai.com/playground/complete
and simulate the conversation. you can do it like this:
This is a conversation between an AI assistant and a user:
system msg to assistant:
"You are a helpful assistant."
user msg:
"Who won the world series in 2020?"
assistant msg:
"The Los Angeles Dodgers won the World Series in 2020."
user msg:
"Where was it
and notice how the model will happily complete the user msg:
the chat completions api just enforces the json message schema. But within that, you have free reign to do what you want. The output, however, will always be in the assistant role, and is essentially guaranteed to never spill into the user role.
hope this helps!