Chainlit / chainlit

Build Conversational AI in minutes ⚡️
https://docs.chainlit.io
Apache License 2.0
6.91k stars 912 forks source link

Message scope doesn't work with the 'page' display of Text element #15

Closed innoeduke closed 1 year ago

innoeduke commented 1 year ago

While text element in 'page' display was sent, message scope didn't work. Here're the repo steps:

Step 1: Run this sample code snippet

#code example
@cl.on_message
def main(message: str):
    elements = [
        cl.Text(message, name='side_text', display='side'),
        cl.Text(message, name='page_text', display='page'),
        cl.Text(message, name='inline_text', display='inline'),
    ]

    cl.send_message(content=f"Received: {message}", elements=elements)

Step 2: Send two messages

image

Step 3: Click the page_text link in the 2nd message.

Expected to get an output message: "2nd msg: side_text, page_text, inline_text", but still got the 1st message output.

image
willydouhard commented 1 year ago

Good catch, this is because on the page view we check for the element to display by name (as you can see in the URL) and in that case you have multiple elements with the same name.

While we fix this, you can avoid this behavior by specifying different names for page elements

willydouhard commented 1 year ago

this should be fixed with the 0.2.108 release