A modern, minimalist React.js chatbot application powered by OpenAI's GPT API. Built with TypeScript, Vite, and a beautiful glassmorphism design.
Software Engineer & Programming Teacher
I teach programming through engaging YouTube tutorials and content across multiple platforms. This project demonstrates modern React development with AI integration.
- 📽️ YouTube: @SergieCode - Programming tutorials and tech content
- 📸 Instagram: @sergiecode - Behind the scenes and quick tips
- 🧑🏼💻 LinkedIn: sergiecode - Professional updates and articles
- 😺 GitHub: sergiecode - Open source projects and code
- 👤 Facebook: sergiecodeok - Community and updates
- 🎞️ TikTok: @sergiecode - Quick coding tips and tricks
- 🕊️ Twitter: @sergiecode - Tech thoughts and updates
- 🧵 Threads: @sergiecode - Latest discussions
- 🎨 Modern UI - Clean glassmorphism design with smooth animations
- 🤖 AI-Powered - Integrated with OpenAI's GPT-3.5-turbo model
- 💬 Real-time Chat - Instant responses with typing indicators
- 📱 Responsive - Works perfectly on desktop and mobile devices
- 🔒 Secure - Environment variables for API key protection
- ⚡ Fast - Built with Vite for lightning-fast development
- 🎯 TypeScript - Full type safety and better development experience
- Node.js (v18 or higher)
- npm or yarn
- OpenAI API key
-
Clone the repository
git clone https://github.com/sergiecode/openai-api-chatbot-reactjs.git cd openai-api-chatbot-reactjs
-
Install dependencies
npm install
-
Set up environment variables
cp .env.template .env
Edit
.env
and add your OpenAI API key:VITE_OPENAI_API_KEY=your_openai_api_key_here
-
Start the development server
npm run dev
-
Open your browser Navigate to
http://localhost:5173
- Visit OpenAI Platform
- Sign in to your account (or create one)
- Navigate to "API Keys" section
- Click "Create new secret key"
- Copy the key and paste it in your
.env
file
src/
├── components/
│ ├── Chatbot.tsx # Main chatbot component
│ └── Chatbot.css # Chatbot styling
├── services/
│ └── openai.ts # OpenAI API integration
├── App.tsx # Main application component
├── App.css # Global styles
└── main.tsx # Application entry point
npm run dev
- Start development servernpm run build
- Build for productionnpm run preview
- Preview production buildnpm run lint
- Run ESLint
The app uses a modern glassmorphism design. You can customize colors and effects in:
src/App.css
- Global styles and layoutsrc/components/Chatbot.css
- Chatbot-specific styling
Modify AI behavior in src/services/openai.ts
:
- Change the model (e.g., gpt-4)
- Adjust max_tokens
- Modify temperature for creativity
⚠️ Client-side API calls: This demo makes API calls directly from the browser- 🏢 Production recommendation: Implement a backend server to secure your API key
- 🔐 Environment variables: Never commit
.env
files to version control - 📝 Rate limiting: Consider implementing rate limiting for production use
Contributions are welcome! Feel free to:
- Report bugs
- Suggest new features
- Submit pull requests
- Improve documentation
This project is open source and available under the MIT License.
This project is perfect for learning:
- React 19 with hooks
- TypeScript integration
- OpenAI API usage
- Modern CSS techniques
- Vite configuration
- Environment variable management
If you have questions or need help:
- 💬 Comment on my YouTube videos
- 📧 Reach out on LinkedIn
- 🐦 Tweet me on Twitter
⭐ If you found this project helpful, please give it a star on GitHub!
Made with ❤️ by Sergie Code