Spaces:
Sleeping
Sleeping
Update main.py
Browse files
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
|
| 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 |
-
|
| 82 |
-
|
| 83 |
|
| 84 |
-
NOT: "Amazing offers
|
| 85 |
|
|
|
|
| 86 |
{history_text}
|
| 87 |
|
| 88 |
-
|
| 89 |
{context}
|
| 90 |
|
| 91 |
-
Customer
|
| 92 |
|
| 93 |
-
|
| 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 |
|