harismlnaslm commited on
Commit
5b0123f
·
1 Parent(s): 592f8de

Add company overview synthesis when query mentions 'textilindo' without 95% match

Browse files
Files changed (2) hide show
  1. __pycache__/app.cpython-312.pyc +0 -0
  2. app.py +55 -0
__pycache__/app.cpython-312.pyc CHANGED
Binary files a/__pycache__/app.cpython-312.pyc and b/__pycache__/app.cpython-312.pyc differ
 
app.py CHANGED
@@ -493,6 +493,13 @@ Minimum purchase is 1 roll (67-70 yards)."""
493
  logger.info(f"Using high-quality training data match (similarity: {similarity_score:.2f})")
494
  return training_match.get('output', '')
495
 
 
 
 
 
 
 
 
496
  # If no high similarity match, use AI model
497
  logger.info(f"No high similarity match, using AI model for: {user_message[:50]}...")
498
 
@@ -592,6 +599,54 @@ Minimum purchase is 1 roll (67-70 yards)."""
592
  return training_match.get('output', '')
593
  return self.get_fallback_response(user_message)
594
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
595
  def get_fallback_response(self, user_message: str) -> str:
596
  """Fallback response when no training data match and no API available"""
597
  # Try to give a more contextual response based on the question
 
493
  logger.info(f"Using high-quality training data match (similarity: {similarity_score:.2f})")
494
  return training_match.get('output', '')
495
 
496
+ # If user asks generally about Textilindo, synthesize an overview from training data
497
+ if "textilindo" in user_message.lower():
498
+ overview = self.get_company_overview()
499
+ if overview:
500
+ logger.info("Returning company overview synthesized from training data")
501
+ return overview
502
+
503
  # If no high similarity match, use AI model
504
  logger.info(f"No high similarity match, using AI model for: {user_message[:50]}...")
505
 
 
599
  return training_match.get('output', '')
600
  return self.get_fallback_response(user_message)
601
 
602
+ def get_company_overview(self) -> str:
603
+ """Build a short Textilindo overview from available training data."""
604
+ try:
605
+ location = None
606
+ hours = None
607
+ shipping = None
608
+ catalog = None
609
+ min_order = None
610
+ products = None
611
+
612
+ for item in self.data_loader.training_data:
613
+ instr = (item.get('instruction') or '').lower()
614
+ out = (item.get('output') or '').strip()
615
+ if not out:
616
+ continue
617
+ if location is None and any(k in instr for k in ["lokasi", "alamat", "dimana textilindo", "lokasi mana"]):
618
+ location = out
619
+ if hours is None and any(k in instr for k in ["jam", "operasional", "buka"]):
620
+ hours = out
621
+ if shipping is None and any(k in instr for k in ["ongkir", "pengiriman", "kirim"]):
622
+ shipping = out
623
+ if catalog is None and any(k in instr for k in ["katalog", "pdf", "buku"]):
624
+ catalog = out
625
+ if min_order is None and any(k in instr for k in ["minimal order", "ketentuan pembelian", "per roll", "ecer"]):
626
+ min_order = out
627
+ if products is None and any(k in instr for k in ["produk", "kain", "bahan"]):
628
+ products = out
629
+
630
+ parts = []
631
+ if location:
632
+ parts.append(f"Alamat: {location}")
633
+ if hours:
634
+ parts.append(f"Jam operasional: {hours}")
635
+ if shipping:
636
+ parts.append(f"Pengiriman: {shipping}")
637
+ if min_order:
638
+ parts.append(f"Pembelian: {min_order}")
639
+ if catalog:
640
+ parts.append(f"Katalog: {catalog}")
641
+ if products:
642
+ parts.append(f"Produk: {products}")
643
+
644
+ if parts:
645
+ return "Tentang Textilindo — " + " | ".join(parts)
646
+ return "Textilindo adalah perusahaan tekstil. Tanyakan lokasi, jam operasional, katalog, produk, atau pengiriman untuk info detail."
647
+ except Exception as e:
648
+ logger.error(f"Error building company overview: {e}")
649
+ return "Textilindo adalah perusahaan tekstil. Tanyakan detail spesifik yang Anda butuhkan."
650
  def get_fallback_response(self, user_message: str) -> str:
651
  """Fallback response when no training data match and no API available"""
652
  # Try to give a more contextual response based on the question