How does ChatGPT store history of chat

Hello and good time.
What I have done to remember ChatGPT chat messages is to store the last 6 messages from ChatGPT inside a database. When recalling, I read them from the database and place them inside a list or array. :grin:

Then, I put that array into the role system and send a new request.

messages: [
    { role: "system", content: "Last 6 messages from ChatGPT: ['Data']" },
    { role: "user", content: "New user message" }
],