# ๐Ÿค– 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! ๐Ÿš€**