Spaces:
Running
Running
Commit ·
a7887b4
1
Parent(s): 2b0613b
fix(chat): detect casual conversation to prevent unwanted web search on chit-chat
Browse files- app/routers/chat.py +23 -4
- app/services/llm_service.py +7 -4
app/routers/chat.py
CHANGED
|
@@ -270,12 +270,31 @@ async def ask_question(
|
|
| 270 |
# Mode D: Pure conversational AI assistant with FastMCP Web Search, arXiv academic research, & workspace collective knowledge
|
| 271 |
web_results = None
|
| 272 |
arxiv_results = None
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
]
|
| 277 |
q_strip = request.query.strip().lower()
|
| 278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
|
| 280 |
if not is_simple_greeting:
|
| 281 |
import json
|
|
|
|
| 270 |
# Mode D: Pure conversational AI assistant with FastMCP Web Search, arXiv academic research, & workspace collective knowledge
|
| 271 |
web_results = None
|
| 272 |
arxiv_results = None
|
| 273 |
+
|
| 274 |
+
# Conversational chit-chat, greetings, check-ins, and reactions
|
| 275 |
+
conversational_patterns = [
|
| 276 |
+
"بقولك", "بقول لك", "معاك", "يا باشا", "يا صاحبي", "يا زميلي", "يا برو", "سامعني",
|
| 277 |
+
"انت هنا", "انت معايا", "ممكن سؤال", "عايز اسالك", "عايز اسألك", "اسمعني", "الو",
|
| 278 |
+
"هلا", "مرحبا", "مرحب", "سلام", "سلام عليكم", "السلام عليكم", "صباح الخير", "مساء الخير",
|
| 279 |
+
"ازيك", "عامل ايه", "اخبارك", "مين انت", "من انت", "عرفني بنفسك", "انت مين",
|
| 280 |
+
"ما اسمك", "اسمك ايه", "بتعمل ايه", "تقدر تعمل ايه", "اي دا", "ايه ده", "اي دا يعم",
|
| 281 |
+
"يا عم", "يا راجل", "طب بقولك", "طب اسمع", "شكرا", "شكراً", "تسلم", "الله يخليك",
|
| 282 |
+
"عفوا", "تمام", "ماشي", "اوك", "اوكي", "حلو", "جميل", "رائع", "حصل خير", "فهمت",
|
| 283 |
+
"واضح", "خلاص", "تمام كدا", "hello", "hi", "hey", "who are you", "what is your name",
|
| 284 |
+
"what can you do", "thanks", "thank you", "ok", "okay", "listen", "can you hear me",
|
| 285 |
+
"are you there", "good morning", "good evening", "how are you", "what's up", "sup",
|
| 286 |
+
"yo", "cool", "got it", "understood", "alright", "tell me"
|
| 287 |
]
|
| 288 |
q_strip = request.query.strip().lower()
|
| 289 |
+
cleaned_q = re.sub(r'[\?!.,;:\-_—~#@$%^&*()،؟]', '', q_strip).strip()
|
| 290 |
+
|
| 291 |
+
is_simple_greeting = (
|
| 292 |
+
cleaned_q in conversational_patterns
|
| 293 |
+
or (len(cleaned_q) <= 35 and any(cleaned_q.startswith(p) for p in [
|
| 294 |
+
"بقولك", "بقول لك", "ازيك", "عامل ايه", "سلام", "مرحبا", "الو", "هلا", "يا باشا",
|
| 295 |
+
"يا صاحبي", "مين انت", "من انت", "صباح الخير", "مساء الخير", "شكرا", "تمام", "اي دا", "ايه ده"
|
| 296 |
+
]))
|
| 297 |
+
)
|
| 298 |
|
| 299 |
if not is_simple_greeting:
|
| 300 |
import json
|
app/services/llm_service.py
CHANGED
|
@@ -1360,11 +1360,14 @@ Return only the final user-facing answer."""
|
|
| 1360 |
is_arabic_query = any("\u0600" <= c <= "\u06ff" for c in query)
|
| 1361 |
lang_rule = "Respond in Arabic (فصحى طبيعية ومفيدة)." if is_arabic_query else "Respond in English."
|
| 1362 |
|
| 1363 |
-
system_prompt = f"""You are Atlas, a
|
| 1364 |
-
Your name is Atlas (أطلس). When asked about your identity or name (e.g., "من أنت؟" or "ما اسمك؟" or "who are you?"), introduce yourself clearly as Atlas
|
| 1365 |
{lang_rule}
|
| 1366 |
-
Always match the user's language.
|
| 1367 |
-
|
|
|
|
|
|
|
|
|
|
| 1368 |
"""
|
| 1369 |
if web_results:
|
| 1370 |
try:
|
|
|
|
| 1360 |
is_arabic_query = any("\u0600" <= c <= "\u06ff" for c in query)
|
| 1361 |
lang_rule = "Respond in Arabic (فصحى طبيعية ومفيدة)." if is_arabic_query else "Respond in English."
|
| 1362 |
|
| 1363 |
+
system_prompt = f"""You are Atlas, a smart, friendly, and helpful AI research and workspace assistant.
|
| 1364 |
+
Your name is Atlas (أطلس). When asked about your identity or name (e.g., "من أنت؟" or "ما اسمك؟" or "who are you?"), introduce yourself clearly as Atlas.
|
| 1365 |
{lang_rule}
|
| 1366 |
+
Always match the user's language, dialect, and tone naturally.
|
| 1367 |
+
If the user greets you, opens a conversation, or speaks casually (such as "بقولك", "بقولك ايه", "معاك", "ازيك", "اي دا يعم", "ممكن سؤال", "سامعني"):
|
| 1368 |
+
- Respond warmly, conversationally, and concisely like a real intelligent partner (e.g., "معاك يا فندم، اتفضل قولّي! محتاج مساعدة في إيه؟").
|
| 1369 |
+
- Do NOT output academic dictionaries, formal definition tables, or research papers about slang words unless explicitly asked to define a linguistic term.
|
| 1370 |
+
Be direct, helpful, and natural. Never invent facts.
|
| 1371 |
"""
|
| 1372 |
if web_results:
|
| 1373 |
try:
|