Error 400 on the ChatGPT while sending message to assistent

Hello there. I need help. I’m trying to make a memory (i’m making tg chat bot with openai assistent) when i use assisten. When i make one request it’s ok. But if it more than one, then i have got the follow error:

BadRequestError: Error code: 400 - {‘error’: {‘message’: “1 validation error for Request\nbody → messages → 1 → role\n value is not a valid enumeration member; permitted: ‘user’ (type=type_error.enum; enum_values=[<RoleParam.USER: ‘user’>])”, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}}

my python code:

from openai import OpenAI
import config
import time

set API key from CHAT_GPT

client = OpenAI(
api_key=config.CHAT_GPT_TOKEN
)

memory = {} # dict for answer from GPT and question from user

def ans_from_gpt(user_id, prompt):

# ckeck id_tg
if user_id not in memory:
    memory[user_id] = []
    memory[user_id].append({"role": "user", "content": prompt})

else:
    memory[user_id].append({"role": "user", "content": prompt})
print(memory[user_id])

#new thread ChatGPT
thread = client.beta.threads.create(
    messages=memory[user_id]
)
print(thread)
#  run new thread
run = client.beta.threads.runs.create(thread_id=thread.id, assistant_id=config.ASS_ID)

# answer waiting
while run.status != "completed":
    run = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)
    print(f"🏃 Run Status: {run.status}")
    time.sleep(1)
else:
    print(f"🏁 Run Completed!")

# answer from assistent
message_response = client.beta.threads.messages.list(thread_id=thread.id)
messages = message_response.data
latest_message = messages[0]
answer = latest_message.content[0].text.value
memory[user_id].append({"role": "assistant", "content": answer})


print(answer)
print('-'*50)
print(memory[user_id])

# dict clear
if len(memory[user_id]) > 10:
    del memory[user_id][0:2]

return answer