vercel / ai-chatbot

A full-featured, hackable Next.js AI chatbot built by Vercel
https://chat.vercel.ai
Other
9.96k stars 2.51k forks source link

fix: image preview on chat messages #484

Open thiagobarbosa opened 3 weeks ago

thiagobarbosa commented 3 weeks ago

Fixes #475

Ideally I would keep the array of Attachment on the chat history so the attachments would be rendered by the PreviewAttachment component, but I noticed that doing that results in a overuse of tokens. Apparently the models keep processing those attachments for every follow up message, even when the follow up user messages only has texts (I only tested this with OpenAI's models but I believe this behaviour is not model-specific).

So this approach appends a markdown by the end of the text to render the images, and a new CSS class on globals.css makes it a little nicer.

Before:

Screenshot 2024-11-04 at 18 33 53

After:

Screenshot 2024-11-04 at 18 32 50

If the image is tall:

Screenshot 2024-11-04 at 18 38 32

Multiple images:

Screenshot 2024-11-04 at 18 47 19
vercel[bot] commented 3 weeks ago

@thiagobarbosa is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.