Spaces:
Build error
Build error
File size: 803 Bytes
f0499d2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import { SafeSearchType, search } from "duck-duck-scrape";
import { convert as htmlToText } from "html-to-text";
import { Tool } from "langchain/tools";
export class DuckDuckGo extends Tool {
name = "duckduckgo_search";
maxResults = 4;
/** @ignore */
async _call(input: string) {
const searchResults = await search(input, {
safeSearch: SafeSearchType.OFF,
});
if (searchResults.noResults) {
return "No good search result found";
}
const results = searchResults.results
.slice(0, this.maxResults)
.map(({ title, description, url }) => htmlToText(description))
.join("\n\n");
return results;
}
description =
"a search engine. useful for when you need to answer questions about current events. input should be a search query.";
}
|