vercel / ai-chatbot

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

Fix duplicate dividers caused by tool call messages in getUIStateFrom… #371

Open laurencebedford opened 1 week ago

laurencebedford commented 1 week ago

…AIState function

Here is an image of the bug - double divider on tool call image

When loading message history, the current implementation of getUIStateFromAIState in ./lib/chat/actions.tsx results in duplicate dividers being rendered whenever a tool call message is present. This issue occurs due to how tool call messages are handled in the mapping logic without filtering out their assistant response counterparts.

This pull request addresses the issue by refining the mapping logic within getUIStateFromAIState. It introduces a filter to exclude assistant messages that are tool call responses, ensuring that only relevant messages are displayed without duplication.

Changes Made:

Added a filter condition to exclude assistant messages that are responses to tool calls. Updated the mapping logic to handle message display appropriately based on role and content type. This fix ensures a cleaner and more accurate rendering of message history, particularly when tool calls are involved, preventing unnecessary duplication of dividers.

vercel[bot] commented 1 week ago

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

A member of the Team first needs to authorize it.

laurencebedford commented 1 week ago

to fix #370

leerob commented 3 days ago

CleanShot 2024-07-01 at 19 04 42@2x I cannot reproduce this issue.