Assistant API can't remember previous messages

Good day to everyone!
Not a long time API user, only working with Assistants at the moment. My question is - how can I make it remember previous messages? I’ve seen a few threads here where people say we should send all conversations back to Assistant. So here’s my question - if I’m only using the API through assistants, how can I code this? Maybe the code that will send all previous messages should be in the functions section? Please feel free to suggest any solution, but it needs to be accessible to all people through API, not just from my desktop.

I think using the same thread for all your messages is the easiest way to achieve this.

How can I do that? Give a little more context, think of it as a consultant bot. It needs to know previous messages to give more accurate information without repeating itself. Right now, the API works independently - each new message opens a new dialog, as best as I can understand. How will I be able to use one thread for all users?

In the Assistants documentation, this is the example code of creating a message and adding it to a threat:

message = client.beta.threads.messages.create(
  thread_id=thread.id,
  role="user",
  content="I need to solve the equation `3x + 11 = 14`. Can you help me?"
)

If you use the same thread id for all your messages, it will have the same effect as all users sending ChatGPT messages in the same conversation.

You just need to have a universal thread for all messages while your program runs.

Okay but if all the messages goes for one thread, it means messages from different people will be shuffled and GPT can’t separate one user’s messages from another.
Also how can I add code to my assistant. I didn’t run it on my pc, right now it works right from the playground by API, I didn’t code anything :slight_smile:

You can have different users on different threads.

If it’s remembering all the previous messages it can be a solution. Right now I see only one thread in the playground where I can test my assistant. How can I make everytime a new thread when a new user is interacting with assistant via API. Or how to make a new thread manually? Tried to read documentation but it’s only with code explained, and didn’t really help me

This is the Python code for creating a new thread.

thread = client.beta.threads.create()

I think you should create one for each user, and add the user’s message to it. This way it will remember the user’s past messages, but not messages sent from others. If the user’s profile in your code will be an object, then the thread id for this user can be a field of it.

I see, thank you. So you basically saying that it can’t be done without coding it in Python. I think it’s time to go deeper into coding… Anyway thank you! Btw maybe you know how to store this information on the server? Can it be openai server or only mine. If you have any helpful links by your hand, I will be appreciate if you can send it

You don’t need to go that deep into coding, but you 'll need to learn some Python basics if you want to create an Assistant. If you are now getting into coding, or starting a new programming language, I’d reccommend starting from w3schools to learn the commands you need to progress.

The messages are stored by OpenAI. For storing any other information you consider useful, you can create a database in your server. ChatGPT is great at creating databases, so you don’t need to fully understand SQL, you just need 1 or 2 messages to gpt-4o, if you haven’t used your free messages for now.

1 Like

My programming skill is very low, I’m only good at logic. Thank you I will check w3schools and learn Python a bit more. Thanks for you time once again

1 Like

You have to learn python basics…even the code posted here wont work unless you have the same variables as the code…or tou have to know enough to substitute your own…Python is the future…certainly as far as ai is concerned…and although other languages take a long time to learn…python is much better that way…so a little study is worth it…cheatsheets are pretty useful…hope this helps!!!

1 Like

Oh okay, I didn’t think this thing exists, I sure it will help me, thank you