How can I check when a file is available within thread?

When I upload a file to a thread and run the assistant on it in one script, the assistant often can’t find the file until I wait a little.

Any ideas, how I can check when the file becomes available to the assistant in the thread?

def create_thread():
    thread = client.beta.threads.create()
    return thread.id


def upload_file(file_path):
    file = client.files.create(
    file=open(file_path, "rb"),
    purpose='assistants'
    )
    print(file)
    return file


def add_message_to_thread(thread_id, file_id, message_content):
    message = client.beta.threads.messages.create(
    thread_id=thread_id,
    role="user",
    file_ids=[file_id],
    content=message_content
    )
    message_id = message.id
    return message, message_id

def run_assistant_on_thread(thread_id, assistant_id, assistant_instruction):
    run = client.beta.threads.runs.create(
    thread_id=thread_id,
    assistant_id=assistant_id,
    model="gpt-3.5-turbo",
    instructions=assistant_instruction,
    tools=[{"type": "retrieval"}]
    )

    while True:
        if run.status == 'queued':
            print(run.status)
            time.sleep(3)
            run = client.beta.threads.runs.retrieve(run_id=run.id, thread_id=thread_id)
        else:
            return run


def get_assistant_response(thread_id):
    thread_response_list = client.beta.threads.messages.list(thread_id=thread_id, order='desc', limit=1)
    response = thread_response_list.data[0].content[0].text.value
    return response