Skip to content

Inserting Image in middle of text in a Message #2727

@Uranium2

Description

@Uranium2

Hello,

In the output of the stream llm, I have made some rendering Agent to check the chunk sent from the LLM, make a regex on it and replace the pattern into a citation. Then I update the message. This is working correctly.

I wanted to do that for images, so the LLM outputs something like this [!image:graph.png], the regex finds it, downloads the file on a storage to retrieve it. Then append the image to the message elements. But after the update, it always send the image to the end of the upcomming new chunks.

I think what I want to do with a single Message is not possible, since a Message will always put images on the end of the text.

Is there a way to put an image in the middle of the text of the cl.Message ?
The aim, is to make the user not scroll up and down on the message when the output text is talking about a graph.

My actual code looks like this:

image = cl.Image(
                url=image_info["url"],
                name=image_ref.filename,
                display="inline",
            )
message.elements.append(image)
message.update()

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleIssue has not had recent activity or appears to be solved. Stale issues will be automatically closed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions