DuckDuckGo web search agent skill support ()

* duckduckgo web search agent skill support

* move ddg to first option in dropdown menu

* lint

* add duckduckgo option stating no config required
This commit is contained in:
Sean Hatfield 2024-11-04 17:01:11 -08:00 committed by GitHub
parent 04e29203a5
commit a2eced0b43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 84 additions and 0 deletions
frontend/src/pages/Admin/Agents/WebSearchSelection
SearchProviderOptions
icons
index.jsx
server
models
utils/agents/aibitat/plugins

View file

@ -316,3 +316,13 @@ export function TavilySearchOptions({ settings }) {
</>
);
}
export function DuckDuckGoOptions() {
return (
<>
<p className="text-sm text-white/60 my-2">
DuckDuckGo is ready to use without any additional configuration.
</p>
</>
);
}

Binary file not shown.

After

(image error) Size: 218 KiB

View file

@ -8,6 +8,7 @@ import BingSearchIcon from "./icons/bing.png";
import SerplySearchIcon from "./icons/serply.png";
import SearXNGSearchIcon from "./icons/searxng.png";
import TavilySearchIcon from "./icons/tavily.svg";
import DuckDuckGoIcon from "./icons/duckduckgo.png";
import {
CaretUpDown,
MagnifyingGlass,
@ -24,6 +25,7 @@ import {
SerplySearchOptions,
SearXNGOptions,
TavilySearchOptions,
DuckDuckGoOptions,
} from "./SearchProviderOptions";
const SEARCH_PROVIDERS = [
@ -35,6 +37,14 @@ const SEARCH_PROVIDERS = [
description:
"Web search will be disabled until a provider and keys are provided.",
},
{
name: "DuckDuckGo",
value: "duckduckgo-engine",
logo: DuckDuckGoIcon,
options: () => <DuckDuckGoOptions />,
description:
"Free and privacy-focused web search using DuckDuckGo's HTML interface.",
},
{
name: "Google Search Engine",
value: "google-search-engine",

View file

@ -100,6 +100,7 @@ const SystemSettings = {
"serply-engine",
"searxng-engine",
"tavily-search",
"duckduckgo-engine",
].includes(update)
)
throw new Error("Invalid SERP provider.");

View file

@ -80,6 +80,9 @@ const webBrowsing = {
case "tavily-search":
engine = "_tavilySearch";
break;
case "duckduckgo-engine":
engine = "_duckDuckGoEngine";
break;
default:
engine = "_googleSearchEngine";
}
@ -499,6 +502,66 @@ const webBrowsing = {
);
return JSON.stringify(data);
},
_duckDuckGoEngine: async function (query) {
this.super.introspect(
`${this.caller}: Using DuckDuckGo to search for "${
query.length > 100 ? `${query.slice(0, 100)}...` : query
}"`
);
const searchURL = new URL("https://html.duckduckgo.com/html");
searchURL.searchParams.append("q", query);
const response = await fetch(searchURL.toString());
if (!response.ok) {
return `There was an error searching DuckDuckGo. Status: ${response.status}`;
}
const html = await response.text();
const data = [];
const results = html.split('<div class="result results_links');
// Skip first element since it's before the first result
for (let i = 1; i < results.length; i++) {
const result = results[i];
// Extract title
const titleMatch = result.match(
/<a[^>]*class="result__a"[^>]*>(.*?)<\/a>/
);
const title = titleMatch ? titleMatch[1].trim() : "";
// Extract URL
const urlMatch = result.match(
/<a[^>]*class="result__a"[^>]*href="([^"]*)">/
);
const link = urlMatch ? urlMatch[1] : "";
// Extract snippet
const snippetMatch = result.match(
/<a[^>]*class="result__snippet"[^>]*>(.*?)<\/a>/
);
const snippet = snippetMatch
? snippetMatch[1].replace(/<\/?b>/g, "").trim()
: "";
if (title && link && snippet) {
data.push({ title, link, snippet });
}
}
if (data.length === 0) {
return `No information was found online for the search query.`;
}
this.super.introspect(
`${this.caller}: I found ${data.length} results - looking over them now.`
);
return JSON.stringify(data);
},
});
},
};