Spaces:
Sleeping
Sleeping
| # π€ 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! π** | |