A simple chatbot built with Next.js, TypeScript, and Tailwind CSS that integrates with OpenAI's GPT-3.5 API.
- Modern chat interface with message bubbles
- Real-time messaging with typing indicators
- Responsive design with Tailwind CSS
- TypeScript for type safety
- Next.js API routes for secure API calls
- Environment variable configuration
-
Install dependencies:
npm install
-
Set up environment variables:
- Copy
env.exampleto.env.local - Add your OpenAI API key:
OPENAI_API_KEY=your_openai_api_key_here
- Copy
-
Run the development server:
npm run dev
-
Open your browser: Navigate to http://localhost:3000
src/
├── app/
│ ├── api/chat/
│ │ └── route.ts # API endpoint for OpenAI integration
│ ├── globals.css # Global styles with Tailwind
│ ├── layout.tsx # Root layout
│ └── page.tsx # Main page component
├── components/
│ ├── Chatbot.tsx # Main chatbot component
│ ├── ChatInput.tsx # Message input component
│ └── MessageBubble.tsx # Individual message component
└── types/
└── chat.ts # TypeScript type definitions
- Next.js 14 - React framework with App Router
- TypeScript - Type safety and better developer experience
- Tailwind CSS - Utility-first CSS framework
- OpenAI API - GPT-3.5 integration for AI responses
- Visit OpenAI Platform
- Sign up or log in to your account
- Navigate to API Keys section
- Create a new API key
- Copy the key and add it to your
.env.localfile
- Modify the system prompt in
src/app/api/chat/route.ts - Adjust styling in the component files
- Change the GPT model or parameters in the API route
- Add more features like conversation history, user authentication, etc.
This project can be deployed to platforms like Vercel, Netlify, or any other hosting service that supports Next.js applications. Make sure to set your environment variables in your deployment platform.