Storing voice assistant (OpenAI) history

I’m using OpenAI as Voice assistant, it works great.
One of the issues with working with the OpenAI (correct me if I’m wrong) is that there’s no history, meaning OpenAI doesn’t know I’m in a continued conversation and does not remember the previous answers or previous questions it gave and got.
So from what I’ve been reading, I need to resend the entire history of the chat to conversation.process every time I call it. So I need to store the question, store the answer I got and append it to some previous data, then use it as prefix when calling conversation.process

I naively though at first that I could use input_text but soon realized I’m limited to 255 characters. I then thought that it could be great to save and read the history from a text file. I successfully installed the File integration for notifications and I’m able to “notify” my text file and append text to it.

However, now that I’m calling the conversation.process I need to read all the text from the file and temporarily store it somewhere so I can use it as “data” for the conversation.process.

I’m totally stumped as to how to read the file. It can’t be read into a state of a sensor, it needs to be an attribute. I found some python scripts or command line scripts. Everything I find is either really old or incorrect.

I would really appreciate any assistance. It would have been truly ideal if I could just call conversation.process with the save conversation_id every time however it doesn’t seem to work for OpenAI, and so if someone has an idea as to how to approach this, please share…

Thank you!

That was actually much easier than I thought.
Added:

shell_command:
    get_ai_history: 'cat /config/ai_history/ai_history.txt'

to configuration.yaml

and then I just call this script from my automation and store the output in a variable, no need for a sensor or any other kind of helper.

1 Like

I’m running into a brick wall on this. The shell command makes perfect sense…however, can you elaborate on the rest your solution?

Thanks!

I would appreciate some additional detail as well on how to best implement this and how to interact/resume with the various chat histories. Thankyou!