chainlit icon indicating copy to clipboard operation
chainlit copied to clipboard

`AskActionMessage` does not work as expected.

Open yrobel-lima opened this issue 2 months ago • 0 comments

Hi, according to the API reference, when using AskUserAction, if the user does not answer in time (see timeout), a TimeoutError will be raised, or None will be returned, depending on the raise_on_timeout parameter. I am passing time_out=5 for testing. To my understanding, it will return None, but I see the chat print messages Timed out: no action was taken when using a while loop (see the screenshot). For AskFileMessage, the provided example seems to work. I want to wait for an answer without seeing any message. Any idea what the issue is, or is this the expected behavior?

Code snippet:

@cl.on_chat_start
async def on_chat_start():
    res = None
    while res is None:
        res = await cl.AskActionMessage(
            content="Select an option:",
            actions=[
                cl.Action(name="Name 1", value="Value 1", label="Label 1"),
                cl.Action(name="Name 2", value="Value 2", label="Label 2"),
            ],
            raise_on_timeout=False,
            timeout=5,
        ).send()

    if res:
        await cl.Message(
            content="All set!",
        ).send()
        cl.user_session.set("location", res.get("value"))

Output: image

AskFileMessage example:

@cl.on_chat_start
async def start():
    files = None

    # Wait for the user to upload a file
    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()

    # Let the user know that the system is ready
    await cl.Message(
        content=f"`{text_file.name}` uploaded, it contains {len(text)} characters!"
    ).send()

Version: 1.0.502

yrobel-lima avatar Apr 10 '24 01:04 yrobel-lima