θΏ™ζ˜―indexlocζδΎ›ηš„ζœεŠ‘οΌŒδΈθ¦θΎ“ε…₯任何密码
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions server/utils/agents/aibitat/plugins/web-browsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const webBrowsing = {
* https://programmablesearchengine.google.com/controlpanel/create
*/
search: async function (query) {
query = this.enhanceQueryForRecency(query);

const provider =
(await SystemSettings.get({ label: "agent_search_provider" }))
?.value ?? "unknown";
Expand Down Expand Up @@ -111,6 +113,57 @@ const webBrowsing = {
return `${str.slice(0, length)}...${str.slice(-length)}`;
},

/**
* Enhances search queries asking for recent information by adding current date context
* @param {string} query - Original search query
* @returns {string} Enhanced query with current date, or original query if no enhancement needed
*/
enhanceQueryForRecency(query) {
const recentKeywords = [
"today",
"latest",
"recent",
"current",
"this week",
"this month",
"breaking",
"new",
"updated",
"updates",
];

const lowerQuery = query.toLowerCase();
const needsRecency = recentKeywords.some((keyword) =>
lowerQuery.includes(keyword)
);

if (!needsRecency) return query;

// Strip LLM added date references (ex: "January 2025", "2024", "December 2024", etc)
const cleanQuery = query
.replace(
/\b(January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{4}\b/gi,
""
)
.replace(/\b\d{4}\b/g, "")
.replace(/\s{2,}/g, " ")
.trim();

// Get date in month year format
const now = new Date();
const monthYear = now.toLocaleDateString("en-US", {
month: "long",
year: "numeric",
});

const enhancedQuery = `${cleanQuery} as of ${monthYear}`;
this.super.introspect(
`${this.caller}: Enhanced query for recency: "${query}" β†’ "${enhancedQuery}"`
);

return enhancedQuery;
},

/**
* Use Google Custom Search Engines
* Free to set up, easy to use, 100 calls/day
Expand Down