bep40 commited on
Commit
fc7c618
·
verified ·
1 Parent(s): 5018b26

Improve: smart local fallback for chatbot when no API token

Browse files
Files changed (1) hide show
  1. index.html +9 -3
index.html CHANGED
@@ -1314,9 +1314,15 @@ try{
1314
  let token=window.huggingface?.variables?.HF_TOKEN;
1315
  if(!token){
1316
  hideTyping();
1317
- appendMsg('bot',formatBotResponse('⚠️ Chưa cấu hình API key. Tuy nhiên, tôi vẫn có thể giúp bạn tìm sản phẩm!\\n\\n'+
1318
- (matchedProducts.length?'Dựa trên câu hỏi của bạn, đây là các sản phẩm phù hợp:':'Hãy thử tìm kiếm cụ thể hơn, ví dụ: "bếp từ", "máy hút mùi", "lò nướng"...'),matchedProducts));
1319
- chatHistory.push({role:'assistant',content:'[Tìm thấy '+matchedProducts.length+' sản phẩm phù hợp]'});
 
 
 
 
 
 
1320
  chatBusy=false;document.getElementById('chatSend').disabled=false;
1321
  return;
1322
  }
 
1314
  let token=window.huggingface?.variables?.HF_TOKEN;
1315
  if(!token){
1316
  hideTyping();
1317
+ // Smart local response without AI
1318
+ let reply='';
1319
+ if(matchedProducts.length>0){
1320
+ reply='Tôi tìm thấy <strong>'+matchedProducts.length+' sản phẩm</strong> phù hợp với yêu cầu của bạn:';
1321
+ }else{
1322
+ reply='Tôi chưa tìm thấy sản phẩm cụ thể. Bạn có thể thử:<br>• Gõ tên sản phẩm (ví dụ: "bếp từ", "máy hút mùi")<br>• Gõ danh mục (ví dụ: "lò nướng", "chậu rửa")<br>• Gõ mã sản phẩm hoặc thương hiệu<br><br>📞 Hoặc gọi hotline <strong>1800 1212</strong> (miễn phí) để được tư vấn trực tiếp!';
1323
+ }
1324
+ appendMsg('bot',formatBotResponse(reply,matchedProducts));
1325
+ chatHistory.push({role:'assistant',content:reply});
1326
  chatBusy=false;document.getElementById('chatSend').disabled=false;
1327
  return;
1328
  }