most LLMs today have a large context window where you can send a history of your chat
i've built multiple chat demo apps (see anotherwrapper.com) and there what i basically did was store a full copy of the history in the DB & then in a config file i specified how many previous messages i want to include in my chat history when interacting to the API
It's a complex issue. I've seen many companies use "AI" as a buzzword, but true "AI companies" often develop novel models or algorithms, not just wrap existing APIs.
I choose to embrace it and that's why my company is literally called AnotherWrapper lol
For example I built a Tweet generator a couple of minutes ago: https://anotherwrapper.com/tools/ai-app-generator/tweetgenie
You can see from the code in the sandbox its a nextjs app, with the backend api route calling openai and frontend taking in user input