chainlit icon indicating copy to clipboard operation
chainlit copied to clipboard

When cl.AskFileMessage is used inside a cl.action_callback, the chat cannot continue after the file is uploaded.

Open KenyaSaitoh opened this issue 7 months ago • 0 comments
trafficstars

Dear Chainlit team,

Thank you very much for providing such an excellent piece of software. I'm a passionate user and a big fan of Chainlit.

However, I would like to report a possible issue I encountered with the latest version 2.5.5 (as of April 20). I’d really appreciate your help in investigating this.

The issue occurs under the following conditions: I display an action button via cl.on_chat_start, and when it is clicked, I handle the action using cl.action_callback. Inside this callback, I prompt the user to upload a file using cl.AskFileMessage.

The file upload itself completes successfully. However, after the file is uploaded, the chat input panel becomes unresponsive. It only becomes usable again after I manually stop the task using the stop button (■) in the upper-right corner of the UI.

Here is a minimal reproducible example:

import chainlit as cl

@cl.on_chat_start
async def start():
    actions = [
        cl.Action(name="action_button", payload={"value": "example_value"}, label="Click me!")
    ]
    await cl.Message(content="Interact with this action button:", actions=actions).send()
    print("Action button sent!")

@cl.action_callback("action_button")
async def action_callback(action: cl.Action):
    await action.remove()
    files = None
    while files == None:
        files = await cl.AskFileMessage(
            content="Please upload a text file to begin!", accept=["text/plain"]
        ).send()

    text_file = files[0]
    with open(text_file.path, "r", encoding="utf-8") as f:
        text = f.read()

    await cl.Message(
        content=f"`{text_file.name}` uploaded, it contains {len(text)} characters!"
    ).send()

Could you please confirm if this is a known bug? Also, if there’s any workaround or recommended approach, I would greatly appreciate your guidance.

Thank you again for your outstanding work!

Best regards, Kenya Saitoh

KenyaSaitoh avatar Apr 20 '25 04:04 KenyaSaitoh