A powerful React-based AI Chatbot that supports multiple AI models (Together AI, Fireworks AI, and Hugging Face). This chatbot features real-time streaming, a typing indicator, and a simple UI built with Bootstrap.
β Multi-Model Support: Choose between Together AI, Fireworks AI, and Hugging Face
β Real-Time Streaming: AI responses appear word-by-word for a realistic chat experience
β Typing Indicator: Shows "Bot is typing..." while waiting for a response
β Bootstrap UI: Simple and responsive design
β API Key Management: Uses environment variables for security
Try it live here: Live Demo
git clone https://github.com/amankkamboj/ai-chatbot.git
cd ai-chatbot
**2οΈβ£ Install Dependencies**
```sh
npm install
**3οΈβ£ Set Up Environment Variables**
Create a `.env` file in the project root and add your API keys:
REACT_APP_TOGETHER_AI_KEY=your_together_ai_api_key
REACT_APP_FIREWORKS_API_KEY=your_fireworks_api_key
REACT_APP_HUGGINGFACE_API_KEY=your_huggingface_api_key
**Get API Keys from:**
- πΉ [Together AI](https://together.ai/)
- πΉ [Fireworks AI](https://fireworks.ai/)
- πΉ [Hugging Face](https://huggingface.co/)
---
**π Run the Chatbot**
npm start
The chatbot will be available at:
π `http://localhost:3000`
---
**π οΈ How It Works**
**1οΈβ£ Select AI Model**
Choose from:
- πΉ **Together AI (DeepSeek-R1)**
- πΉ **Fireworks AI (LLaMA 2-13B)**
- πΉ **Hugging Face (Flan-T5 Large)**
**2οΈβ£ Type a Message**
- The bot will show **"Typing..."** while generating a response.
- If **Together AI is selected**, the response is **streamed word-by-word**.
- The final AI-generated response is displayed.
---
**π Code Explanation**
**πΉ `Chatbot.js` (Main Component)**
- **Handles user input** and **sends API requests**.
- **Displays responses** from the selected AI model.
- **Manages typing indicator and streaming responses**.
javascript
const [messages, setMessages] = useState([]);
const [input, setInput] = useState("");
const [selectedAI, setSelectedAI] = useState("together");
const [isTyping, setIsTyping] = useState(false);
**πΉ AI API Calls**
Each AI model has **different response formats**, so we handle them correctly.
**Together AI (DeepSeek-R1)**
- Uses **real-time streaming** for better UX.
- API: `https://api.together.xyz/v1/chat/completions`
{
model: "deepseek-ai/DeepSeek-R1",
messages: [{ role: "user", content: input }],
stream: true
}
**Fireworks AI (LLaMA 2-13B)**
- API: `https://api.fireworks.ai/inference/v1/completions`
```javascript
{
model: "accounts/fireworks/models/llama-v2-13b-chat",
prompt: input,
max_tokens: 100
}
```
**Hugging Face (Flan-T5 Large)**
- API: `https://api-inference.huggingface.co/models/google/flan-t5-large`
{
inputs: input;
}
```
---
**π¨ UI Design**
- Built with **React Bootstrap** for a clean and responsive UI.
- **Typing Indicator** shows an animated **spinner** while waiting for AI response.
{
isTyping && (
<div className="text-start text-muted">
<Spinner animation="grow" size="sm" /> Bot is typing...
</div>
);
}
**π Future Enhancements**
πΉ **Support more AI models** (e.g., OpenAI GPT, Cohere)
πΉ **Add voice input & text-to-speech**
πΉ **Dark mode support**
πΉ **Host on Vercel or Netlify**
---
**π Contributing**
1. **Fork the repo**
2. **Create a feature branch** (`git checkout -b feature-name`)
3. **Commit your changes** (`git commit -m "Added new feature"`)
4. **Push to GitHub** (`git push origin feature-name`)
5. **Open a Pull Request**
---
**π License**
This project is **open-source** under the **MIT License**.
---
**π Contact**
π‘ Created by [**Aman Kamboj**]
π§ Email: **amankamboj2387@gmail.com**
π GitHub: [**https://github.com/amankkamboj/**]
π LinkedIn: [**https://www.linkedin.com/in/freelancer-aman-webdeveloper/**]