Any tips on AIState? Seem to be doing a lot of fighting trying to get it to show what I'm expecting. #1290
Replies: 4 comments 1 reply
-
+1 having this exact problem |
Beta Was this translation helpful? Give feedback.
-
I've mentioned it here: #1509 - this is the 2nd weird error I've encountered with their ai chat template. You are not going crazy, my guess is they are moving fast, perhaps too fast, to try and be the dominate ai sdk platform and stuff is breaking |
Beta Was this translation helpful? Give feedback.
-
Hey @shaded-blue, sorry about this! I tried reproducing this to investigate what might be causing this, but I couldn't get the same results as you. Here's the action that mutates the AI state in the way you described above. Can you pull the code and help me try and reproduce your behavior so I can try and figure out what might be the cause? |
Beta Was this translation helpful? Give feedback.
-
@wolfpixels Glad to know I'm not alone haha. I did eventually get around it, but by massively simplifying the approach I'd been using when doing all of this state client-side (before my move to this SDK). If you're still having the issue I can try to lay out a few more details when I get some time! @jeremyphilemon I have run back into this issue now that I've updated to the tool-call / tool-results structure etc. Specifically, the issue only seems to occur with tool-call/tool-result two part messages, not simple user/assistant messages for example. It manifests as some messages missing from the AIState during the tool call, and although the correct messages are being returned to the client, it seems to be sending the wrong data to my server actions for persistence.. I believe the issue is stemming from a lack of understanding on my end, of how exactly I should be interacting with the AIState. For clarification, looking at the example repo here, should we not be doing a .update() => .done() for the call and result in the generator function, but just a single .done()? Could this create problems for example? I'll try to put together a basic project with a single tool to reproduce and share that with you should I do so. If I don't run into the issue there, well, I guess it's somewhere in my codebase after all. Lol. |
Beta Was this translation helpful? Give feedback.
-
To be clear, I'm not exactly new to this, but I feel like I have completely lost it since trying to integrate this AI SDK into my codebase / project, and part of my brain is just no longer functioning.
I seem to have absolutely no understanding of how this AIState is being updated.
For example, in my sendMessage server action, I am setting the initial message with update:
And I am using the same render function they are for the response, which uses done to add the response:
I log aiState.get() through the mutation steps and see exactly what I expect, which is the new message after the update, and both at the done.
Similarly, if I log getAIState() in messageSave, which gets run after from the unstable_onSetAIState, I can see both messages.
When I send a follow-up message, the very first message I sent is gone from AIState, seemingly in between the last step of unstable_onSetAIState, and the absolute very start of the sendMessage action.
All follow up messages are successfully stored in the AIState.
Another oddity, is that when logged from the client, useAIState's state seems to look completely different from that on the server.
I've read through the rather terse docs many times, but again, I feel I've just found myself in some kind of rut here and my brain absolutely cannot seem to reconcile whatever is missing in my understanding, but I must be missing something, because for a tool that claims to streamline interaction with LLM's, I must say I've found this significantly more difficult to understand and implement than rolling an entire solution myself, even before getting to the UI part, which is the entire reason I started this attempt at a migration.
All advice is greatly appreciated, and thank you for your time. Sorry for the bit of a rant, this has really gotten to me. Lol.
Beta Was this translation helpful? Give feedback.
All reactions