Uamir commited on
Commit
bba9d1a
·
verified ·
1 Parent(s): 316e205

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +13 -20
main.py CHANGED
@@ -58,39 +58,32 @@ def ask_bot(query: str):
58
  docs = retriever.get_relevant_documents(query)
59
  context = "\n".join([d.page_content for d in docs])
60
 
 
 
 
 
 
61
  # --- Add previous conversation history to context ---
62
  history_text = ""
63
  for turn in conversation_history[-6:]: # last 3 user-bot pairs
64
  history_text += f"User: {turn['user']}\nBot: {turn['bot']}\n"
65
 
66
- full_prompt = f"""You are ShopMart's e-commerce assistant. Follow these instructions STRICTLY:
67
-
68
- 🚫 NEVER respond with:
69
- - "Amazing offers available now!"
70
- - "Weekly Deals" or promotional templates
71
- - Generic discount information
72
- - "Check our deals page" responses
73
- - Any pre-written marketing content
74
-
75
- ✅ ALWAYS respond with:
76
- - Direct answer to the specific question asked
77
- - Actual product information from the context data
78
- - Real prices and availability status
79
- - If product not found, say "I don't have information about that product"
80
 
81
- EXAMPLE - If asked about MacBook Air M2 price:
82
- "The MacBook Air M2 is priced at [ACTUAL PRICE] PKR and [STOCK STATUS]. [Add specs if available]"
83
 
84
- NOT: "Amazing offers available now! Weekly deals..."
85
 
 
86
  {history_text}
87
 
88
- Available Product Data:
89
  {context}
90
 
91
- Customer Question: {query}
92
 
93
- Direct Answer (no promotional templates):"""
94
 
95
  response = llm.invoke(full_prompt)
96
 
 
58
  docs = retriever.get_relevant_documents(query)
59
  context = "\n".join([d.page_content for d in docs])
60
 
61
+ # --- Check if context is empty ---
62
+ print("Context retrieved:", context) # Debug line
63
+ if not context.strip():
64
+ return "I don't have specific information about that product in our database. Please contact support for current pricing and availability."
65
+
66
  # --- Add previous conversation history to context ---
67
  history_text = ""
68
  for turn in conversation_history[-6:]: # last 3 user-bot pairs
69
  history_text += f"User: {turn['user']}\nBot: {turn['bot']}\n"
70
 
71
+ full_prompt = f"""CRITICAL: You must ONLY use the data provided below. DO NOT use any pre-trained promotional responses.
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
+ If the context data below contains the requested product information, provide it directly.
74
+ If the context data does not contain the information, say "I don't have that information available."
75
 
76
+ DO NOT EVER SAY: "Amazing offers", "Weekly deals", "Check our deals page", or any promotional content.
77
 
78
+ Previous conversation:
79
  {history_text}
80
 
81
+ Data from our store:
82
  {context}
83
 
84
+ Customer question: {query}
85
 
86
+ Answer using ONLY the above store data:"""
87
 
88
  response = llm.invoke(full_prompt)
89