Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -262,45 +262,48 @@ def custom_unmad_satirical_bot(message, history, top_k=3, lambda_param=0.6):
|
|
| 262 |
if cleaned_contexts:
|
| 263 |
top_contexts = "\n\n---\n\n".join(cleaned_contexts)
|
| 264 |
else:
|
| 265 |
-
top_contexts = "
|
| 266 |
|
| 267 |
# Add metadata about source diversity (optional)
|
| 268 |
source_info = []
|
| 269 |
for i, doc in enumerate(docs, 1):
|
| 270 |
-
source = doc['metadata'].get('source', '
|
| 271 |
-
page = doc['metadata'].get('page', '
|
| 272 |
# Clean source info too
|
| 273 |
if not re.search(r'[a-zA-Z]', str(source)): # Only if source doesn't contain English
|
| 274 |
source_info.append(f"[{i}] {source} - {page}")
|
| 275 |
|
| 276 |
-
source_context = "
|
| 277 |
else:
|
| 278 |
-
top_contexts = "
|
| 279 |
source_context = ""
|
| 280 |
|
| 281 |
# Prepare system prompt
|
| 282 |
system_prompt = """
|
| 283 |
-
|
| 284 |
-
|
| 285 |
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
|
|
|
|
|
|
|
|
|
| 295 |
"""
|
| 296 |
|
| 297 |
user_prompt = f"""
|
| 298 |
-
|
| 299 |
{top_contexts}
|
| 300 |
|
| 301 |
-
|
| 302 |
|
| 303 |
-
|
| 304 |
"""
|
| 305 |
|
| 306 |
# Generate response using OpenAI
|
|
|
|
| 262 |
if cleaned_contexts:
|
| 263 |
top_contexts = "\n\n---\n\n".join(cleaned_contexts)
|
| 264 |
else:
|
| 265 |
+
top_contexts = "No relevant information were found"
|
| 266 |
|
| 267 |
# Add metadata about source diversity (optional)
|
| 268 |
source_info = []
|
| 269 |
for i, doc in enumerate(docs, 1):
|
| 270 |
+
source = doc['metadata'].get('source', 'Unknown source')
|
| 271 |
+
page = doc['metadata'].get('page', 'Unnown page')
|
| 272 |
# Clean source info too
|
| 273 |
if not re.search(r'[a-zA-Z]', str(source)): # Only if source doesn't contain English
|
| 274 |
source_info.append(f"[{i}] {source} - {page}")
|
| 275 |
|
| 276 |
+
source_context = "Source: " + " | ".join(source_info[:3]) if source_info else ""
|
| 277 |
else:
|
| 278 |
+
top_contexts = "No relevant information were found"
|
| 279 |
source_context = ""
|
| 280 |
|
| 281 |
# Prepare system prompt
|
| 282 |
system_prompt = """
|
| 283 |
+
You are an old satirical writer from the magazine *Unmad*.
|
| 284 |
+
Your job is to listen to the user’s questions and respond with **satire, sarcasm, humor, teasing, and a bit of wisdom** — so that people laugh, think, and maybe learn something new.
|
| 285 |
|
| 286 |
+
You must **never** give a direct or plain answer — instead, respond playfully, with surprise, mockery, or witty jabs.
|
| 287 |
+
|
| 288 |
+
**You must strictly follow these rules — no exceptions:**
|
| 289 |
+
|
| 290 |
+
1. Do **not** use any emojis — not even one.
|
| 291 |
+
2. Do **not** use any English text — not even a single word.
|
| 292 |
+
3. Do **not** use English numbers or symbols (for example: PDF, URL, www, .com, scanned by, found in, etc.).
|
| 293 |
+
4. Do **not** mention any English text, scan watermarks, website names, or technical terms that appear in the context.
|
| 294 |
+
5. Use **only Bangla (Bengali)** in your responses.
|
| 295 |
+
6. If there’s no Bangla content in the context, respond using your own general knowledge.
|
| 296 |
+
7. Combine information from various sources to create a unified, coherent answer.
|
| 297 |
+
8. Do **not** provide any website or PDF references of any kind.
|
| 298 |
"""
|
| 299 |
|
| 300 |
user_prompt = f"""
|
| 301 |
+
Context (collected from various sources):
|
| 302 |
{top_contexts}
|
| 303 |
|
| 304 |
+
Question: {message}
|
| 305 |
|
| 306 |
+
Instruction: Using only the Bengali-language content from the context above, respond in the style of Unmad magazine. Do not use any English words, emojis, or scan watermarks. Write a fully Bengali response that is satirical and humorous in tone.
|
| 307 |
"""
|
| 308 |
|
| 309 |
# Generate response using OpenAI
|