mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-06 15:02:20 +02:00
Separate current reference lookups from publication date restrictions
This commit is contained in:
@@ -231,18 +231,8 @@ class WebSearchTool:
|
||||
if not query:
|
||||
query = raw.split("\n")[0].strip()
|
||||
if time_filter is None:
|
||||
q_lc = query.lower()
|
||||
if any(kw in q_lc for kw in (
|
||||
"today", "latest", "breaking", "this morning", "right now",
|
||||
"currently", "current events", "what's happening", "what is happening",
|
||||
)):
|
||||
time_filter = "day"
|
||||
elif any(kw in q_lc for kw in ("this week", "past week", "recent news", "last few days")):
|
||||
time_filter = "week"
|
||||
elif any(kw in q_lc for kw in ("this month", "past month")):
|
||||
time_filter = "month"
|
||||
elif " news" in q_lc or q_lc.startswith("news ") or q_lc.endswith(" news"):
|
||||
time_filter = "week"
|
||||
from src.search_intent import inferred_search_publication_window
|
||||
time_filter = inferred_search_publication_window(query)
|
||||
loop = asyncio.get_running_loop()
|
||||
if progress_cb:
|
||||
await progress_cb({
|
||||
@@ -254,7 +244,7 @@ class WebSearchTool:
|
||||
results = await asyncio.wait_for(
|
||||
loop.run_in_executor(
|
||||
None,
|
||||
lambda: searxng_search_results(query, max_pages),
|
||||
lambda: searxng_search_results(query, max_pages, **({'time_filter': time_filter} if time_filter else {})),
|
||||
),
|
||||
timeout=30,
|
||||
)
|
||||
@@ -283,7 +273,7 @@ class WebSearchTool:
|
||||
results = await asyncio.wait_for(
|
||||
loop.run_in_executor(
|
||||
None,
|
||||
lambda: searxng_search_results(query, max_pages),
|
||||
lambda: searxng_search_results(query, max_pages, **({'time_filter': time_filter} if time_filter else {})),
|
||||
),
|
||||
timeout=12,
|
||||
)
|
||||
|
||||
@@ -3490,15 +3490,19 @@ def preserve_requested_web_recency(name, args, *, user_text='', prior_search_int
|
||||
if (current_intent
|
||||
and not re.search(r'\b(?:latest|recent|current|today|news|updates?|20\d{2})\b', query, re.I)):
|
||||
query = f'{query} latest {current_year}'
|
||||
if current_intent and not normalized.get('time_filter'):
|
||||
if re.search(r'\b(?:version|release|driver)\b', user, re.I):
|
||||
normalized['time_filter'] = 'year'
|
||||
elif re.search(r"\btoday(?:'s)?\b", user, re.I):
|
||||
normalized['time_filter'] = 'day'
|
||||
elif re.search(r'\brecent\b', user, re.I):
|
||||
normalized['time_filter'] = 'month'
|
||||
else:
|
||||
normalized['time_filter'] = 'week'
|
||||
from src.search_intent import inferred_search_publication_window, reference_lookup_without_date_window, requested_search_publication_window
|
||||
requested_window = requested_search_publication_window(user)
|
||||
if requested_window:
|
||||
normalized['time_filter'] = requested_window
|
||||
elif reference_lookup_without_date_window(user):
|
||||
# A model-generated publication cutoff must not hide still-current
|
||||
# reference pages when the user did not ask for recent publications.
|
||||
normalized.pop('time_filter', None)
|
||||
normalized.pop('freshness', None)
|
||||
elif not normalized.get('time_filter'):
|
||||
window = inferred_search_publication_window(user)
|
||||
if window:
|
||||
normalized['time_filter'] = window
|
||||
normalized['query'] = query
|
||||
return normalized
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
"""Shared publication-recency semantics for query repair and search execution."""
|
||||
import re
|
||||
|
||||
|
||||
def reference_lookup_without_date_window(text: str) -> bool:
|
||||
"""Current reference information need not have been published recently."""
|
||||
reference = re.search(
|
||||
r'\b(?:documentation|docs|manuals?|guides?|reference|installation|configuration)\b'
|
||||
r'|\bprivacy\s+(?:features|settings|protections)\b', text, re.I,
|
||||
)
|
||||
publication = re.search(
|
||||
r'\b(?:published|publication|announced|released|news|headlines|recent|today|yesterday)\b'
|
||||
r'|\b(?:this|last|past)\s+(?:\d+\s+)?(?:days?|weeks?|months?|years?)\b'
|
||||
r'|\b(?:since|after|before|between|during)\b|\b20\d{2}\b', text, re.I,
|
||||
)
|
||||
return bool(reference and not publication)
|
||||
|
||||
|
||||
def requested_search_publication_window(text: str) -> str | None:
|
||||
"""Recognize explicit named publication windows."""
|
||||
if re.search(r'\b(?:today|yesterday|this morning|right now)\b', text, re.I):
|
||||
return 'day'
|
||||
for unit, value in [('week', 'week'), ('month', 'month'), ('year', 'year')]:
|
||||
if re.search(rf'\b(?:this|past|last)\s+{unit}\b', text, re.I):
|
||||
return value
|
||||
return None
|
||||
|
||||
|
||||
def inferred_search_publication_window(text: str) -> str | None:
|
||||
"""Infer publication recency, not freshness of every requested fact."""
|
||||
requested = requested_search_publication_window(text)
|
||||
if requested:
|
||||
return requested
|
||||
if reference_lookup_without_date_window(text):
|
||||
return None
|
||||
if re.search(r"\b(?:current events|what(?:'s| is) happening)\b", text, re.I):
|
||||
return 'day'
|
||||
if re.search(r'\b(?:news|neews|headlines|breaking|latest developments)\b', text, re.I):
|
||||
return 'week'
|
||||
if re.search(r'\brecent\b', text, re.I):
|
||||
return 'month'
|
||||
return None
|
||||
+1
-1
@@ -337,7 +337,7 @@ FUNCTION_TOOL_SCHEMAS = [
|
||||
"properties": {
|
||||
"query": {"type": "string", "description": "Search query"},
|
||||
"command": {"type": "string", "description": "Search query in text command form"},
|
||||
"time_filter": {"type": "string", "enum": ["day", "week", "month", "year"], "description": "Optional freshness filter for news/latest/today queries"}
|
||||
"time_filter": {"type": "string", "enum": ["day", "week", "month", "year"], "description": "Optional publication-date window for recent articles/news. Omit for current documentation, manuals, or features unless the user specifies a publication window."}
|
||||
},
|
||||
"required": []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user