3 Introduction to Vercel AI SDK
This chapter covers
- Overview of the Vercel AI SDK for React/Next.js
- Incorporating streaming AI responses in React apps
- Separating AI and UI state in React/Next.js
- Enhancing conversational UIs with multimedia content
When building our minimal generative AI application, we encountered several challenges:
- Vendor Lock-in: While it's easy to create a wrapper on top of an existing API provider (e.g., OpenAI), there's a risk of vendor lock-in. If the provider becomes unreliable or changes their service, we would need to re-architect our entire application to switch providers.
- Streaming Responses: Some providers support streaming responses, but adopting this feature often requires significant architectural changes to the application.
- State Management: Our initial solution did not maintain any memory or state, but to introduce a conversation history between the user and the assistant, we need to manage separate states for the UI client and the AI assistant. Ideally, we need an abstraction to handle both UI and AI states seamlessly.
To address these three considerations, we can either create certain abstractions from scratch that deal with a specific problem, or as a better solution, seek specialized tools and frameworks that contain this functionality in a wholistic way.