How to use OpenAI for a chat application?

Your architecture isn’t clear from your description. In chat completions, from my experience, chat history is used to maintain context in an ongoing conversation. Chat Completion Architechture

It sounds like, in your use case, your “chat history” is actually order history which, as you describe, is maintained in your SQL database. Chat history is, by definition, user questions and assistant responses, which you say you are storing in your SQL database as well.

In my mind, what you need is a plugin to have the AI search the SQL database for chat and/or order history rather than trying to cram a user’s history into the chat history.

This might help: A sanity check for future plugins to access private SQL databases