openai / openai-realtime-console

React app for inspecting, building and debugging with the Realtime API
MIT License
2.12k stars 779 forks source link

How to set a message history? #56

Open ClemB-Dev opened 1 month ago

ClemB-Dev commented 1 month ago

I was wondering how I could populate the RealTime Client with a conversation history.

The idea is that users can continue a conversation from where it left off after being disconnected. I am already able to retrieve the history, as I have saved it in a database. Now, I would like to configure the client with the updated history.

Is this possible? If so, how does it work?

josancamon19 commented 3 weeks ago

In theory you should be able to call response.create.item with each one of the previous messages, but I couldn't make it work, I'm creating an issue about it in a sec.

So what I did was:

let instructionsCopy = instructions;
    if (messageList.length > 0) {
      instructionsCopy = instructionsCopy + `\n\nThe following is a history of our previous conversation:\n${messageList.map(message => `${message.sender}: ${message.message}`).join('\n')}`;
    }
ClemB-Dev commented 3 weeks ago

Thank you for answering. That's also what I did on my side.