Update src/api/agent.py
Browse files- src/api/agent.py +17 -0
src/api/agent.py
CHANGED
|
@@ -2539,7 +2539,24 @@ def _parse_refinement_action(question: str) -> Optional[str]:
|
|
| 2539 |
# Alternative search terms — NEW
|
| 2540 |
if ALT_TERMS_RE.search(q):
|
| 2541 |
return "alt_terms"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2542 |
if re.search(r"\b(summar(y|ize|ise)|overview|brief|what does the literature say|research snapshot)\b", q):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2543 |
return "summarize_topic"
|
| 2544 |
if re.search(r"\bpubmed\b", q):
|
| 2545 |
return "search_pubmed"
|
|
|
|
| 2539 |
# Alternative search terms — NEW
|
| 2540 |
if ALT_TERMS_RE.search(q):
|
| 2541 |
return "alt_terms"
|
| 2542 |
+
# summarize_topic: ONLY match short/topicless follow-ups like "summarize this",
|
| 2543 |
+
# "give me an overview", "what does the literature say" — NOT questions that
|
| 2544 |
+
# include an explicit new topic like "summarize quantum physics".
|
| 2545 |
+
# A question with 4+ non-stop content words almost certainly has its own topic
|
| 2546 |
+
# and should be handled as a fresh query, not a follow-up.
|
| 2547 |
if re.search(r"\b(summar(y|ize|ise)|overview|brief|what does the literature say|research snapshot)\b", q):
|
| 2548 |
+
_STOP = {
|
| 2549 |
+
'a','an','the','of','on','in','for','to','with','by','from','at','is','are',
|
| 2550 |
+
'was','were','be','been','have','has','had','do','does','did','will','would',
|
| 2551 |
+
'could','should','may','its','this','that','these','those','about','me','my',
|
| 2552 |
+
'give','show','tell','please','can','you','i','need','want','get','find',
|
| 2553 |
+
'research','summary','overview','summarize','summarise','brief','literature',
|
| 2554 |
+
}
|
| 2555 |
+
content_words = [t for t in re.findall(r'[a-z0-9]+', q)
|
| 2556 |
+
if t not in _STOP and (len(t) > 2 or t in {'ai','ml','nlp','cv','rl','dl','uae','ku','iot'})]
|
| 2557 |
+
# Any explicit topic word → treat as a fresh query, not a follow-up
|
| 2558 |
+
if content_words:
|
| 2559 |
+
return None
|
| 2560 |
return "summarize_topic"
|
| 2561 |
if re.search(r"\bpubmed\b", q):
|
| 2562 |
return "search_pubmed"
|