From 66e1296a06f5061b23908a1164e1d07fffe1f794 Mon Sep 17 00:00:00 2001 From: Torsten Raudssus Date: Tue, 11 Jun 2024 17:29:07 +0200 Subject: [PATCH] Searxng Tool implementation (#2599) * Searxng Tool implementation, first commit with most functionality * Fixed complains of pnpm lint * Picky linter --- .../nodes/tools/Searxng/SearXNG.svg | 19 +++ .../components/nodes/tools/Searxng/Searxng.ts | 119 ++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 packages/components/nodes/tools/Searxng/SearXNG.svg create mode 100644 packages/components/nodes/tools/Searxng/Searxng.ts diff --git a/packages/components/nodes/tools/Searxng/SearXNG.svg b/packages/components/nodes/tools/Searxng/SearXNG.svg new file mode 100644 index 000000000..915d2783b --- /dev/null +++ b/packages/components/nodes/tools/Searxng/SearXNG.svg @@ -0,0 +1,19 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/components/nodes/tools/Searxng/Searxng.ts b/packages/components/nodes/tools/Searxng/Searxng.ts new file mode 100644 index 000000000..b3f647371 --- /dev/null +++ b/packages/components/nodes/tools/Searxng/Searxng.ts @@ -0,0 +1,119 @@ +import { SearxngSearch } from '@langchain/community/tools/searxng_search' +import { INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses } from '../../../src/utils' + +class Searxng_Tools implements INode { + label: string + name: string + version: number + description: string + type: string + icon: string + category: string + baseClasses: string[] + inputs: INodeParams[] + + constructor() { + this.label = 'SearXNG' + this.name = 'searXNG' + this.version = 1.0 + this.type = 'SearXNG' + this.icon = 'SearXNG.svg' + this.category = 'Tools' + this.description = 'Wrapper around SearXNG - a free internet metasearch engine' + this.inputs = [ + { + label: 'Base URL', + name: 'apiBase', + type: 'string', + default: 'http://searxng:8080' + }, + { + label: 'Categories', + name: 'categories', + description: + 'Comma separated list, specifies the active search categories. (see Configured Engines)', + optional: true, + additionalParams: true, + type: 'string' + }, + { + label: 'Engines', + name: 'engines', + description: + 'Comma separated list, specifies the active search engines. (see Configured Engines)', + optional: true, + additionalParams: true, + type: 'string' + }, + { + label: 'Language', + name: 'language', + description: 'Code of the language.', + optional: true, + additionalParams: true, + type: 'string' + }, + { + label: 'Page No.', + name: 'pageno', + description: 'Search page number.', + optional: true, + additionalParams: true, + type: 'number' + }, + { + label: 'Time Range', + name: 'time_range', + description: + 'Time range of search for engines which support it. See if an engine supports time range search in the preferences page of an instance.', + optional: true, + additionalParams: true, + type: 'string' + }, + { + label: 'Safe Search', + name: 'safesearch', + description: + 'Filter search results of engines which support safe search. See if an engine supports safe search in the preferences page of an instance.', + optional: true, + additionalParams: true, + type: 'number' + } + ] + this.baseClasses = [this.type, ...getBaseClasses(SearxngSearch)] + } + + async init(nodeData: INodeData, _: string): Promise { + const apiBase = nodeData.inputs?.apiBase as string + const categories = nodeData.inputs?.categories as string + const engines = nodeData.inputs?.engines as string + const language = nodeData.inputs?.language as string + const pageno = nodeData.inputs?.pageno as number + const time_range = nodeData.inputs?.time_range as string + const safesearch = nodeData.inputs?.safesearch as 0 | 1 | 2 | undefined + const format = 'json' as 'json' + + const params = { + format, + categories, + engines, + language, + pageno, + time_range, + safesearch + } + + const headers = {} + + const tool = new SearxngSearch({ + apiBase, + params, + headers + }) + + return tool + } +} + +module.exports = { nodeClass: Searxng_Tools }