generateText Persistant #9866
Replies: 2 comments
-
|
Hey! 👋 You actually don't need to convert to UIMessage for database storage. Since generateText is part of the AI SDK Core (server-side), the recommended pattern is to store messages in the CoreMessage format (essentially { role: 'user' | 'assistant', content: ... }). UIMessage is generally reserved for the client-side state (like in the useChat hook). When using generateText, you can pull the raw text or the full response messages directly for your DB. Here is the standard flow: const { text, response } = await generateText({ // Save to DB as a standard CoreMessage So the short answer: Store as CoreMessage, not UIMessage. When you fetch them later to display on the frontend, the SDK can handle the hydration seamlessly. Hope this helps! Let me know if this clarifies things. |
Beta Was this translation helpful? Give feedback.
-
|
This discussion was automatically locked because it has not been updated in over 30 days. If you still have questions about this topic, please ask us at community.vercel.com/ai-sdk |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
After spending countless hours researching, I'm still not sure the recommended way to store messages from generateText() into my database.
Has anyone got any recommendations? AI SDK V5
We only seem to have access to
ResponseMessage, from what I can see, it's recommended to storeUIMessage, however there is no conversion helper function?Beta Was this translation helpful? Give feedback.
All reactions