Valtry commited on
Commit
8274867
·
verified ·
1 Parent(s): 71b83b8

Upload agent.py

Browse files
Files changed (1) hide show
  1. agent.py +21 -7
agent.py CHANGED
@@ -25,15 +25,18 @@ class AgentRouter:
25
  "stock",
26
  "price",
27
  "weather",
 
 
28
  ]
29
  datetime_keywords = [
30
  "time",
31
  "date",
32
- "day",
33
- "month",
34
- "year",
35
  "timezone",
36
  "clock",
 
 
 
 
37
  ]
38
  calc_keywords = [
39
  "calculate",
@@ -48,13 +51,24 @@ class AgentRouter:
48
  "minus",
49
  ]
50
 
51
- if any(k in lower for k in datetime_keywords):
52
- return "datetime"
 
 
 
 
 
 
 
53
 
54
- if any(k in lower for k in web_keywords):
 
55
  return "web"
56
 
57
- if any(k in lower for k in calc_keywords):
 
 
 
58
  return "calculator"
59
 
60
  # Fallback detection for math-like expressions.
 
25
  "stock",
26
  "price",
27
  "weather",
28
+ "headline",
29
+ "happening",
30
  ]
31
  datetime_keywords = [
32
  "time",
33
  "date",
 
 
 
34
  "timezone",
35
  "clock",
36
+ "what time",
37
+ "current time",
38
+ "today's date",
39
+ "todays date",
40
  ]
41
  calc_keywords = [
42
  "calculate",
 
51
  "minus",
52
  ]
53
 
54
+ tokens = set(re.findall(r"\b\w+\b", lower))
55
+
56
+ def has_phrase_or_token(keyword: str) -> bool:
57
+ if " " in keyword:
58
+ return keyword in lower
59
+ return keyword in tokens
60
+
61
+ has_web_intent = any(has_phrase_or_token(k) for k in web_keywords)
62
+ has_datetime_intent = any(has_phrase_or_token(k) for k in datetime_keywords)
63
 
64
+ # Give web queries priority when both are present (e.g., "latest AI news today").
65
+ if has_web_intent:
66
  return "web"
67
 
68
+ if has_datetime_intent:
69
+ return "datetime"
70
+
71
+ if any(has_phrase_or_token(k) for k in calc_keywords):
72
  return "calculator"
73
 
74
  # Fallback detection for math-like expressions.