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

aistate messages dissapear? #1509

Open
wolfpixels opened this issue May 7, 2024 · 1 comment
Open

aistate messages dissapear? #1509

wolfpixels opened this issue May 7, 2024 · 1 comment
Assignees
Labels

Comments

@wolfpixels
Copy link

wolfpixels commented May 7, 2024

Description

So I'm having the same issue as this user: #1290

I'm using the vercel ai chat template and I've implemented a custom ai provider.
Like shaded-blue mentioned, messages dissapear from my aistate.

sync function submitUserMessage(content: string) {
  'use server'

  const aiState = getMutableAIState<typeof AI>()

  console.log('this is content', content)

  // Retrieve the current messages before the update
  const currentMessages = aiState.get().messages;

  // Log the number of messages currently stored
  console.log('Current number of messages before update:', currentMessages.length);

  // Log each message in the current state
  currentMessages.forEach((msg, index) => {
    console.log(`Message ${index + 1}:`, msg);
  });

When I have this in chat/lib/chat/actions.tsx - on each user message the current messages performs weird, showing different things like 0/1

Code example

sync function submitUserMessage(content: string) {
  'use server'

  const aiState = getMutableAIState<typeof AI>()

  console.log('this is content', content)

  // Retrieve the current messages before the update
  const currentMessages = aiState.get().messages;

  // Log the number of messages currently stored
  console.log('Current number of messages before update:', currentMessages.length);

  // Log each message in the current state
  currentMessages.forEach((msg, index) => {
    console.log(`Message ${index + 1}:`, msg);
  });

Additional context

No response

@jeremyphilemon
Copy link
Contributor

Hey @wolfpixels, sorry about this! I left a comment in this thread to investigate this behavior

@jeremyphilemon jeremyphilemon self-assigned this May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants