Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with rendering older tool result messages #556

Open
namishsaxena opened this issue Nov 18, 2024 · 1 comment
Open

Issue with rendering older tool result messages #556

namishsaxena opened this issue Nov 18, 2024 · 1 comment

Comments

@namishsaxena
Copy link

Screenshot 2024-11-18 at 14 38 09
As you can see after few messages older tool-result messages are not loading, on debugging I found the addToolMessageToChat isn't working properly as it kind of misses the tool-call messages or something. The issue could also be that in database the timestamp for message save is same and the ordering/ sorting doesn't work properly

@namishsaxena
Copy link
Author

on further investigation it is happening because the following code in /api/chat/route.ts. In here when new Date() is being assigned, it is causing all assistant/ tool messages getting the same time stamp.

` await saveMessages({
messages: responseMessagesWithoutIncompleteToolCalls.map(
(message) => {
const messageId = generateUUID();

            if (message.role === 'assistant') {
              streamingData.appendMessageAnnotation({
                messageIdFromServer: messageId,
              });
            }

            return {
              id: messageId,
              chatId: id,
              role: message.role,
              content: message.content,
              createdAt: new Date(),
            };
          },
        ),
      });
    } catch (error) {
      console.error('Failed to save chat');
    }
  }`

if anyone is encountering this, you can fix it like. You can extract index in the responseMessagesWithoutIncompleteToolCalls.map
const delay = index * 1000; createdAt: new Date(new Date().getTime() + delay),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant