Chainlit / cookbook

Chainlit's cookbook repo
https://github.com/Chainlit/chainlit
713 stars 270 forks source link

Example [llava] file.content missing in uploaded files #69

Closed s0l4r closed 7 months ago

s0l4r commented 7 months ago

Greetings,

I've been testing Chainlit and the Llava cookbook.

file.content is empty using the llava example from the cookbook:

    image = next(
        (
            Image.open(io.BytesIO(file.content))
            for file in message.elements or []
            if "image" in file.mime
        ),
        None,
    )

I had to change it to read the full file path instead:

async def main(message: cl.Message):
    image = next(
        (
            Image.open(file.path)
            for file in message.elements or []
            if "image" in file.mime and file.path is not None
        ),
        None,
    )

Is the file.content bytes supposed to be stored in the file object as well? If so there is an issue saving it:

element.py

@dataclass
class Element:
    # The byte content of the element.
    content: Optional[Union[bytes, str]] = None

emitter.py https://github.com/Chainlit/chainlit/blob/5f7f104bb66d7b94dfc692cd8f27bfad17bac179/backend/chainlit/emitter.py#L213

file_elements Image content is empty:

[
    Image(
        name="back.jpg",
        id="1b800a32-8bfd-4f46-ab41-aa4450d3f6d9",
        chainlit_key="1b800a32-8bfd-4f46-ab41-aa4450d3f6d9",
        url=None,
        object_key=None,
        path="cookbook/custom-frontend/.files/86e16506-67c8-4aa4-bdb4-4be5c26e4691/1b800a32-8bfd-4f46-ab41-aa4450d3f6d9.jpg",
        content=None,
        display="inline",
        size="medium",
        for_id=None,
        language=None,
        mime="image/jpeg",
    )
]

Thanks!

willydouhard commented 7 months ago

Good catch, this was changed with the latest releases. Will update the cookbook!

s0l4r commented 7 months ago

Good catch, this was changed with the latest releases. Will update the cookbook!

Great!! :)

willydouhard commented 7 months ago

Just fixed it. Thank you!