Textilindo-AI / AI_CONFIGURATION.md
harismlnaslm's picture
Add AI configuration guide and test script for real AI integration
2754850
# πŸ€– AI Configuration Guide
## πŸ”§ **Fixed Issues:**
### βœ… **Real AI Integration (No More Mock Responses)**
The chat API now uses **real AI** instead of template responses:
1. **Trained Model Priority**: Uses your trained model if available
2. **HuggingFace API Fallback**: Uses HuggingFace Inference API
3. **Smart Mock Fallback**: Only uses mock responses as last resort
### βœ… **AI Response Flow:**
```
User Question β†’ Trained Model β†’ HuggingFace API β†’ Smart Mock
```
## πŸš€ **How It Works:**
### **1. Trained Model (Best)**
- If `./models/textilindo-trained` exists
- Uses your custom-trained model
- Provides most accurate responses
### **2. HuggingFace API (Good)**
- Requires `HUGGINGFACE_API_KEY` environment variable
- Uses powerful pre-trained models
- Good for general questions
### **3. Smart Mock (Fallback)**
- Only when AI models fail
- Improved keyword matching
- Better response relevance
## πŸ”‘ **Setup HuggingFace API Key:**
### **Option 1: Environment Variable**
```bash
export HUGGINGFACE_API_KEY=your_api_key_here
```
### **Option 2: HuggingFace Space Settings**
1. Go to your space settings
2. Add environment variable: `HUGGINGFACE_API_KEY`
3. Set value to your HuggingFace API key
### **Get API Key:**
1. Visit: https://huggingface.co/settings/tokens
2. Create new token with "Read" permissions
3. Copy the token
## πŸ§ͺ **Test AI Integration:**
### **Test Questions:**
```bash
# Test 1: Operating hours
curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/chat" \
-H "Content-Type: application/json" \
-d '{"message": "Jam berapa Textilindo buka?"}'
# Test 2: Location
curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/chat" \
-H "Content-Type: application/json" \
-d '{"message": "dimana lokasi textilindo?"}'
# Test 3: Shipping
curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/chat" \
-H "Content-Type: application/json" \
-d '{"message": "apa ada gratis ongkir?"}'
```
## πŸ“Š **Expected Results:**
### **Before (Mock Responses):**
```json
{
"message": "Jam berapa Textilindo buka?",
"response": "Textilindo berkantor pusat di Jl. Raya Prancis...",
"status": "success"
}
```
### **After (Real AI):**
```json
{
"message": "Jam berapa Textilindo buka?",
"response": "Jam operasional Senin-Jumat 08:00-17:00, Sabtu 08:00-12:00.",
"status": "success"
}
```
## 🎯 **Training Your Model:**
### **1. Start Training:**
```bash
curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/api/train/start" \
-H "Content-Type: application/json" \
-d '{
"model_name": "distilgpt2",
"dataset_path": "data/lora_dataset_20250910_145055.jsonl",
"max_samples": 20,
"epochs": 1
}'
```
### **2. Monitor Progress:**
```bash
curl "https://harismlnaslm-Textilindo-AI.hf.space/api/train/status"
```
### **3. Test Trained Model:**
```bash
curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/api/train/test"
```
## βœ… **Verification:**
### **Check AI Status:**
```bash
curl "https://harismlnaslm-Textilindo-AI.hf.space/health"
```
### **Test Chat:**
```bash
curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/chat" \
-H "Content-Type: application/json" \
-d '{"message": "Jam berapa Textilindo buka?"}'
```
## πŸŽ‰ **Success Indicators:**
- βœ… **Relevant Responses**: AI answers match the questions
- βœ… **No More Mock Fallbacks**: Real AI responses
- βœ… **Trained Model Priority**: Uses your custom model
- βœ… **HuggingFace API**: Works with API key
- βœ… **Smart Fallbacks**: Better error handling
---
**Your AI is now using real intelligence instead of templates! πŸš€**