A modern AI chatbot application built with Next.js, AI SDK v5, and Tailwind CSS. Features a clean chat interface with support for multiple AI models (OpenAI and Google Gemini) and tool calling capabilities.
- 🤖 Multi-Model Support: Switch between OpenAI GPT-4o and Google Gemini models
- 🛠️ Tool Calling: Built-in tools for weather, time, calculations, and information search
- 💬 Real-time Streaming: Stream responses from AI models in real-time
- 🎨 Modern UI: Clean, responsive chat interface with tool call visualization
- 📝 Message History: Messages are stored in the frontend for conversation continuity
- 🔧 Modular Components: Well-organized component structure for easy maintenance
- Framework: Next.js 15.5
- Runtime: Bun
- AI SDK: ai-sdk v5 with @ai-sdk/react, @ai-sdk/openai, @ai-sdk/google
- Styling: Tailwind CSS with Shadcn/ui components
- Language: TypeScript
- Validation: Zod
- Icons: Lucide React
├── app/
│ ├── api/
│ │ └── chat/
│ │ └── route.ts # Chat API endpoint with tool definitions
│ ├── layout.tsx # Root layout with Toaster
│ └── page.tsx # Main page with chat UI
├── components/
│ ├── chat/
│ │ ├── chat-container.tsx # Main chat container with controls
│ │ ├── chat-input.tsx # Message input component
│ │ ├── chat-messages.tsx # Messages list with auto-scroll
│ │ ├── message-item.tsx # Individual message wrapper
│ │ ├── message-content.tsx # Message content renderer (text + tools)
│ │ └── index.ts # Export barrel
│ ├── ui/ # Shadcn/ui components
│ └── app-sidebar.tsx # Application sidebar
└── lib/
└── utils.ts # Utility functions (cn, etc.)
- Bun installed on your system
- OpenAI API key (for GPT-4o model)
- Google AI API key (for Gemini model)
- Clone the repository:
git clone <your-repo-url>
cd nextjs-ai-agent- Install dependencies:
bun install- Set up environment variables:
Copy the .env.local file and add your API keys:
# OpenAI API Key
OPENAI_API_KEY=your-openai-api-key-here
# Google Gemini API Key
GOOGLE_GENERATIVE_AI_API_KEY=your-google-api-key-here
# Default model provider (openai or google)
DEFAULT_MODEL_PROVIDER=openai- Run the development server:
bun dev- Open http://localhost:3000 in your browser.
The AI agent has access to the following tools:
- getWeather: Get current weather information for a city
- getCurrentTime: Get current date and time for a specific timezone
- calculate: Perform basic mathematical calculations
- searchInfo: Search for information on various topics
- Select your preferred AI model (OpenAI or Google Gemini) from the dropdown
- Type your message in the input field
- Press Enter or click the send button
- Watch as the AI responds and uses tools when appropriate
- Tool calls and results are displayed with visual indicators
bun run buildbun run lintbun start- AI SDK v5: Uses the latest AI SDK for streaming and tool calling
- Route Handler: API route at
/api/chathandles all chat interactions - Tool System: Tools are defined with Zod schemas for type-safe validation
- Multi-Model: Supports switching between OpenAI and Google models dynamically
- React Hooks: Uses
useChathook from @ai-sdk/react for state management - Component Splitting: Chat UI is split into small, focused components
- Real-time Updates: Messages stream in real-time with proper rendering
- Tool Visualization: Tool calls and results are clearly displayed
- Auto-scroll: Messages automatically scroll to bottom on new content
Feel free to open issues or submit pull requests for improvements.
MIT
