AI SDK Chatbot Starter
Next.js chatbot using Vercel AI SDK for fast, scalable, and context-aware conversations.
VERCEL AI SDK Chatbot Template - EdgeOne Pages
A modern AI chatbot template built with Next.js 14, Vercel AI SDK, and Tailwind CSS, specifically designed for deployment on EdgeOne Pages. This template provides a complete AI chat interface with support for multiple AI providers and models.
What is this template?
This template is a production-ready AI chatbot application that you can deploy directly to EdgeOne Pages with one click. It features:
- Multi-Provider Support: Works with DeepSeek, OpenAI, Anthropic, Google, and xAI models
- Modern UI: Dark theme design with smooth animations and responsive layout
- Real-time Streaming: Live AI responses with typing effects
- Error Handling: Comprehensive error handling and retry mechanisms
- EdgeOne Optimized: Specifically configured for EdgeOne Pages deployment
โจ Features
- ๐ค Multi-AI Support: DeepSeek, OpenAI GPT, Anthropic Claude, Google Gemini, xAI Grok
- ๐จ Modern UI: Dark theme with SVG background and smooth animations
- โก Real-time Streaming: Live AI responses with typewriter effects
- ๐ฑ Responsive Design: Works perfectly on desktop, tablet, and mobile
- ๐ญ Smooth Animations: Page transitions, loading states, and interactive effects
- ๐ง Configurable: Easy model switching and parameter adjustment
- ๐ก๏ธ Robust Error Handling: Comprehensive error messages and retry functionality
- ๐ EdgeOne Optimized: Built specifically for EdgeOne Pages deployment
๐ Quick Start
1. Clone the Project
git clone https://github.com/tomcomtang/vercel-ai-sdk-chatbot.git
cd vercel-ai-sdk-chatbot
2. Install Dependencies
npm install
# or
yarn install
# or
pnpm install
3. Configure Environment Variables
Copy the environment variables example file:
cp env.example .env.local
Edit the .env.local
file and add your API keys:
# DeepSeek API Key (Required for default model)
DEEPSEEK_API_KEY=your_deepseek_api_key_here
# Optional: Other AI Provider Keys
OPENAI_API_KEY=your_openai_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here
GOOGLE_GENERATIVE_AI_API_KEY=your_google_api_key_here
XAI_API_KEY=your_xai_api_key_here
4. Start Development Server
npm run dev
# or
yarn dev
# or
pnpm dev
Open http://localhost:3000 to view the application.
๐ ๏ธ Tech Stack
- Framework: Next.js 14 (App Router)
- AI SDK: Vercel AI SDK v5
- AI Models: DeepSeek, OpenAI GPT, Anthropic Claude, Google Gemini, xAI Grok
- Styling: Tailwind CSS
- Icons: Lucide React
- Language: TypeScript
- Deployment: EdgeOne Pages
๐ Project Structure
vercel-ai-sdk-chatbot/
โโโ app/
โ โโโ api/chat/route.ts # AI chat API route
โ โโโ globals.css # Global styles
โ โโโ layout.tsx # Root layout
โ โโโ page.tsx # Main page
โโโ components/
โ โโโ ChatInput.tsx # Chat input component
โ โโโ HomeScreen.tsx # Home screen component
โ โโโ MessageList.tsx # Message list component
โ โโโ ModelSelector.tsx # Model selection component
โ โโโ ErrorMessage.tsx # Error message component
โโโ hooks/
โ โโโ useChatLogic.ts # Chat logic hook
โ โโโ useScrollLogic.ts # Scroll logic hook
โโโ functions/
โ โโโ api/chat/index.js # EdgeOne Pages Action
โโโ env.example # Environment variables example
โโโ EDGEONE_SETUP.md # EdgeOne deployment guide
โโโ package.json # Project configuration
โโโ README.md # Project documentation
โ๏ธ Configuration Options
Environment Variables
Variable Name | Required | Default Value | Description |
---|---|---|---|
DEEPSEEK_API_KEY | โ | - | DeepSeek API key |
OPENAI_API_KEY | โ | - | OpenAI API key |
ANTHROPIC_API_KEY | โ | - | Anthropic API key |
GOOGLE_GENERATIVE_AI_API_KEY | โ | - | Google AI API key |
XAI_API_KEY | โ | - | xAI API key |
Supported Models
- DeepSeek:
deepseek-chat
,deepseek-reasoner
- OpenAI:
gpt-4o-mini
- Anthropic:
claude-3-5-sonnet-latest
- Google:
gemini-2.0-flash
- xAI:
grok-3
๐จ Customization
Modify AI Behavior
Edit the system
prompt in app/api/chat/route.ts
:
system: `You are an intelligent AI assistant dedicated to helping users. Please follow these principles:
1. Provide accurate, useful, and concise answers
2. Maintain a friendly and professional tone
3. Be honest when uncertain about answers
4. Support both Chinese and English communication
5. Provide practical advice and solutions`;
Adjust AI Parameters
const result = await streamText({
model: providerConfig.provider(selectedModel),
messages: convertToModelMessages(uiMessages),
maxOutputTokens: 1000, // Maximum output tokens
temperature: 0.7, // Creativity (0-1)
// ... other parameters
});
Custom Styling
The project uses Tailwind CSS, you can:
- Modify global styles in
app/globals.css
- Update component styles in individual component files
- Customize the color scheme and animations
๐ Deployment
EdgeOne Pages Deployment (Recommended)
- Click the "Deploy to EdgeOne" button above
- Configure environment variables in EdgeOne console
- Deploy automatically
Manual Deployment
- Push code to GitHub
- Connect your GitHub repository to EdgeOne Pages
- Configure environment variables in EdgeOne dashboard
- Deploy automatically
Other Deployment Options
- Vercel: Supports Next.js with API routes
- Netlify: Supports Next.js static export
- Railway: Full-stack deployment
๐ License
This project is licensed under the MIT License.
๐ค Contributing
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
๐ Support
If you encounter any issues or have questions, please:
- Check the Issues page
- Create a new issue with detailed description
- Contact the maintainer
๐ Acknowledgments
- Vercel AI SDK for providing excellent AI integration tools
- Next.js for the powerful React framework
- Tailwind CSS for the utility-first CSS framework
- EdgeOne Pages for cloud-edge integrated deployment platform
Made with โค๏ธ by tomcomtang