harismlnaslm commited on
Commit
2754850
Β·
1 Parent(s): 6fc73ab

Add AI configuration guide and test script for real AI integration

Browse files
Files changed (3) hide show
  1. AI_CONFIGURATION.md +141 -0
  2. test_api_simple.py +90 -0
  3. test_chat_ai.py +54 -0
AI_CONFIGURATION.md ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # πŸ€– AI Configuration Guide
2
+
3
+ ## πŸ”§ **Fixed Issues:**
4
+
5
+ ### βœ… **Real AI Integration (No More Mock Responses)**
6
+
7
+ The chat API now uses **real AI** instead of template responses:
8
+
9
+ 1. **Trained Model Priority**: Uses your trained model if available
10
+ 2. **HuggingFace API Fallback**: Uses HuggingFace Inference API
11
+ 3. **Smart Mock Fallback**: Only uses mock responses as last resort
12
+
13
+ ### βœ… **AI Response Flow:**
14
+
15
+ ```
16
+ User Question β†’ Trained Model β†’ HuggingFace API β†’ Smart Mock
17
+ ```
18
+
19
+ ## πŸš€ **How It Works:**
20
+
21
+ ### **1. Trained Model (Best)**
22
+ - If `./models/textilindo-trained` exists
23
+ - Uses your custom-trained model
24
+ - Provides most accurate responses
25
+
26
+ ### **2. HuggingFace API (Good)**
27
+ - Requires `HUGGINGFACE_API_KEY` environment variable
28
+ - Uses powerful pre-trained models
29
+ - Good for general questions
30
+
31
+ ### **3. Smart Mock (Fallback)**
32
+ - Only when AI models fail
33
+ - Improved keyword matching
34
+ - Better response relevance
35
+
36
+ ## πŸ”‘ **Setup HuggingFace API Key:**
37
+
38
+ ### **Option 1: Environment Variable**
39
+ ```bash
40
+ export HUGGINGFACE_API_KEY=your_api_key_here
41
+ ```
42
+
43
+ ### **Option 2: HuggingFace Space Settings**
44
+ 1. Go to your space settings
45
+ 2. Add environment variable: `HUGGINGFACE_API_KEY`
46
+ 3. Set value to your HuggingFace API key
47
+
48
+ ### **Get API Key:**
49
+ 1. Visit: https://huggingface.co/settings/tokens
50
+ 2. Create new token with "Read" permissions
51
+ 3. Copy the token
52
+
53
+ ## πŸ§ͺ **Test AI Integration:**
54
+
55
+ ### **Test Questions:**
56
+ ```bash
57
+ # Test 1: Operating hours
58
+ curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/chat" \
59
+ -H "Content-Type: application/json" \
60
+ -d '{"message": "Jam berapa Textilindo buka?"}'
61
+
62
+ # Test 2: Location
63
+ curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/chat" \
64
+ -H "Content-Type: application/json" \
65
+ -d '{"message": "dimana lokasi textilindo?"}'
66
+
67
+ # Test 3: Shipping
68
+ curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/chat" \
69
+ -H "Content-Type: application/json" \
70
+ -d '{"message": "apa ada gratis ongkir?"}'
71
+ ```
72
+
73
+ ## πŸ“Š **Expected Results:**
74
+
75
+ ### **Before (Mock Responses):**
76
+ ```json
77
+ {
78
+ "message": "Jam berapa Textilindo buka?",
79
+ "response": "Textilindo berkantor pusat di Jl. Raya Prancis...",
80
+ "status": "success"
81
+ }
82
+ ```
83
+
84
+ ### **After (Real AI):**
85
+ ```json
86
+ {
87
+ "message": "Jam berapa Textilindo buka?",
88
+ "response": "Jam operasional Senin-Jumat 08:00-17:00, Sabtu 08:00-12:00.",
89
+ "status": "success"
90
+ }
91
+ ```
92
+
93
+ ## 🎯 **Training Your Model:**
94
+
95
+ ### **1. Start Training:**
96
+ ```bash
97
+ curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/api/train/start" \
98
+ -H "Content-Type: application/json" \
99
+ -d '{
100
+ "model_name": "distilgpt2",
101
+ "dataset_path": "data/lora_dataset_20250910_145055.jsonl",
102
+ "max_samples": 20,
103
+ "epochs": 1
104
+ }'
105
+ ```
106
+
107
+ ### **2. Monitor Progress:**
108
+ ```bash
109
+ curl "https://harismlnaslm-Textilindo-AI.hf.space/api/train/status"
110
+ ```
111
+
112
+ ### **3. Test Trained Model:**
113
+ ```bash
114
+ curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/api/train/test"
115
+ ```
116
+
117
+ ## βœ… **Verification:**
118
+
119
+ ### **Check AI Status:**
120
+ ```bash
121
+ curl "https://harismlnaslm-Textilindo-AI.hf.space/health"
122
+ ```
123
+
124
+ ### **Test Chat:**
125
+ ```bash
126
+ curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/chat" \
127
+ -H "Content-Type: application/json" \
128
+ -d '{"message": "Jam berapa Textilindo buka?"}'
129
+ ```
130
+
131
+ ## πŸŽ‰ **Success Indicators:**
132
+
133
+ - βœ… **Relevant Responses**: AI answers match the questions
134
+ - βœ… **No More Mock Fallbacks**: Real AI responses
135
+ - βœ… **Trained Model Priority**: Uses your custom model
136
+ - βœ… **HuggingFace API**: Works with API key
137
+ - βœ… **Smart Fallbacks**: Better error handling
138
+
139
+ ---
140
+
141
+ **Your AI is now using real intelligence instead of templates! πŸš€**
test_api_simple.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Simple test for the pure API
4
+ """
5
+
6
+ import requests
7
+ import json
8
+
9
+ def test_api():
10
+ base_url = "https://harismlnaslm-Textilindo-AI.hf.space"
11
+
12
+ print("πŸ§ͺ Testing Textilindo AI Pure API")
13
+ print("=" * 50)
14
+
15
+ # Test 1: API Info
16
+ print("1️⃣ Testing API Info...")
17
+ try:
18
+ response = requests.get(f"{base_url}/")
19
+ print(f"Status: {response.status_code}")
20
+ if response.status_code == 200:
21
+ try:
22
+ data = response.json()
23
+ print(f"βœ… API Info: {data.get('name', 'Unknown')}")
24
+ print(f" Hardware: {data.get('hardware', 'Unknown')}")
25
+ print(f" Status: {data.get('status', 'Unknown')}")
26
+ except:
27
+ print("❌ Response is not JSON (still serving HTML)")
28
+ else:
29
+ print(f"❌ Error: {response.status_code}")
30
+ except Exception as e:
31
+ print(f"❌ Error: {e}")
32
+
33
+ # Test 2: Health Check
34
+ print("\n2️⃣ Testing Health Check...")
35
+ try:
36
+ response = requests.get(f"{base_url}/health")
37
+ print(f"Status: {response.status_code}")
38
+ if response.status_code == 200:
39
+ data = response.json()
40
+ print(f"βœ… Health: {data.get('status', 'Unknown')}")
41
+ else:
42
+ print(f"❌ Error: {response.status_code}")
43
+ except Exception as e:
44
+ print(f"❌ Error: {e}")
45
+
46
+ # Test 3: GPU Info
47
+ print("\n3️⃣ Testing GPU Info...")
48
+ try:
49
+ response = requests.get(f"{base_url}/api/train/gpu")
50
+ print(f"Status: {response.status_code}")
51
+ if response.status_code == 200:
52
+ data = response.json()
53
+ print(f"βœ… GPU: {data}")
54
+ else:
55
+ print(f"❌ Error: {response.status_code}")
56
+ except Exception as e:
57
+ print(f"❌ Error: {e}")
58
+
59
+ # Test 4: Training Data
60
+ print("\n4️⃣ Testing Training Data...")
61
+ try:
62
+ response = requests.get(f"{base_url}/api/train/data")
63
+ print(f"Status: {response.status_code}")
64
+ if response.status_code == 200:
65
+ data = response.json()
66
+ print(f"βœ… Data Files: {data.get('count', 0)}")
67
+ for file in data.get('files', []):
68
+ print(f" πŸ“ {file.get('name', 'Unknown')}: {file.get('lines', 0)} lines")
69
+ else:
70
+ print(f"❌ Error: {response.status_code}")
71
+ except Exception as e:
72
+ print(f"❌ Error: {e}")
73
+
74
+ # Test 5: Chat API
75
+ print("\n5️⃣ Testing Chat API...")
76
+ try:
77
+ response = requests.post(f"{base_url}/chat", json={"message": "dimana lokasi textilindo?"})
78
+ print(f"Status: {response.status_code}")
79
+ if response.status_code == 200:
80
+ data = response.json()
81
+ print(f"βœ… Chat Response: {data.get('response', 'No response')}")
82
+ else:
83
+ print(f"❌ Error: {response.status_code}")
84
+ except Exception as e:
85
+ print(f"❌ Error: {e}")
86
+
87
+ print("\nπŸŽ‰ API Test Complete!")
88
+
89
+ if __name__ == "__main__":
90
+ test_api()
test_chat_ai.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Test script to verify AI chat integration is working
4
+ """
5
+
6
+ import requests
7
+ import json
8
+
9
+ def test_chat_ai():
10
+ base_url = "https://harismlnaslm-Textilindo-AI.hf.space"
11
+
12
+ print("πŸ€– Testing AI Chat Integration")
13
+ print("=" * 50)
14
+
15
+ # Test questions
16
+ test_questions = [
17
+ "Jam berapa Textilindo buka?",
18
+ "dimana lokasi textilindo?",
19
+ "apa ada gratis ongkir?",
20
+ "berapa ketentuan pembelian?",
21
+ "apa bisa dikirimkan sample?"
22
+ ]
23
+
24
+ for i, question in enumerate(test_questions, 1):
25
+ print(f"\n{i}️⃣ Testing: '{question}'")
26
+
27
+ try:
28
+ response = requests.post(
29
+ f"{base_url}/chat",
30
+ json={"message": question},
31
+ headers={"Content-Type": "application/json"}
32
+ )
33
+
34
+ if response.status_code == 200:
35
+ data = response.json()
36
+ ai_response = data.get('response', 'No response')
37
+ print(f"βœ… AI Response: {ai_response}")
38
+
39
+ # Check if response is relevant
40
+ if question.lower() in ai_response.lower() or any(word in ai_response.lower() for word in question.lower().split()):
41
+ print("βœ… Response appears relevant")
42
+ else:
43
+ print("⚠️ Response might not be relevant")
44
+
45
+ else:
46
+ print(f"❌ Error: {response.status_code} - {response.text}")
47
+
48
+ except Exception as e:
49
+ print(f"❌ Error: {e}")
50
+
51
+ print("\nπŸŽ‰ Chat AI Test Complete!")
52
+
53
+ if __name__ == "__main__":
54
+ test_chat_ai()