A beautiful, modern chatbot application built with React, TypeScript, and the OpenAI API.
- Clean and intuitive chat interface
- Real-time messaging with OpenAI's GPT models
- Markdown support for rich text formatting
- Responsive design that works on all devices
- Secure API key handling (stored locally)
- Dark/Light mode support (system preference)
- Node.js (version 16 or higher)
- npm or yarn
- An OpenAI API key (Get one here)
- Clone the repository:
git clone <repository-url>
cd react-tsx- Install dependencies:
npm install- Start the development server:
npm run dev-
Open your browser and navigate to
http://localhost:3000 -
Enter your OpenAI API key when prompted
-
Start chatting with the AI!
To create a production build:
npm run buildThe built files will be in the dist directory.
To preview the production build:
npm run previewreact-tsx/
├── src/
│ ├── components/
│ │ ├── ChatMessage.tsx # Individual message component
│ │ ├── ChatMessage.css
│ │ ├── ChatInput.tsx # Input field component
│ │ └── ChatInput.css
│ ├── services/
│ │ └── openai.ts # OpenAI API integration
│ ├── App.tsx # Main app component
│ ├── App.css
│ ├── main.tsx # Application entry point
│ └── index.css
├── index.html
├── package.json
├── tsconfig.json
└── vite.config.ts
- React 18 - UI framework
- TypeScript - Type-safe JavaScript
- Vite - Fast build tool and dev server
- OpenAI API - AI chat capabilities
- React Markdown - Markdown rendering
This application uses dangerouslyAllowBrowser: true for the OpenAI client, which is suitable for development and personal use. For production applications, you should:
- Create a backend server to handle OpenAI API calls
- Store the API key securely on the server
- Never expose your API key in client-side code
Edit src/services/openai.ts and modify the model parameter:
model: 'gpt-4', // or 'gpt-3.5-turbo', 'gpt-4-turbo', etc.Modify the temperature and max_tokens parameters in src/services/openai.ts:
temperature: 0.7, // Lower = more focused, Higher = more creative
max_tokens: 1000, // Maximum response lengthMIT
Contributions are welcome! Please feel free to submit a Pull Request.