From 7486f947d161e0bc9c9c84cf18463703a98900db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Wed, 8 Jan 2025 12:57:06 +0100 Subject: [PATCH] searxng tool --- .../credentials/SearXngApi.credentials.ts | 19 +++ .../tools/ToolSearXng/ToolSearXng.node.ts | 125 ++++++++++++++++++ .../nodes/tools/ToolSearXng/searXng.svg | 1 + packages/@n8n/nodes-langchain/package.json | 2 + 4 files changed, 147 insertions(+) create mode 100644 packages/@n8n/nodes-langchain/credentials/SearXngApi.credentials.ts create mode 100644 packages/@n8n/nodes-langchain/nodes/tools/ToolSearXng/ToolSearXng.node.ts create mode 100644 packages/@n8n/nodes-langchain/nodes/tools/ToolSearXng/searXng.svg diff --git a/packages/@n8n/nodes-langchain/credentials/SearXngApi.credentials.ts b/packages/@n8n/nodes-langchain/credentials/SearXngApi.credentials.ts new file mode 100644 index 0000000000..3248afa4de --- /dev/null +++ b/packages/@n8n/nodes-langchain/credentials/SearXngApi.credentials.ts @@ -0,0 +1,19 @@ +import type { ICredentialType, INodeProperties } from 'n8n-workflow'; + +export class SearXngApi implements ICredentialType { + name = 'searXngApi'; + + displayName = 'SearXNG'; + + documentationUrl = 'searxng'; + + properties: INodeProperties[] = [ + { + displayName: 'API URL', + name: 'apiUrl', + type: 'string', + default: '', + required: true, + }, + ]; +} diff --git a/packages/@n8n/nodes-langchain/nodes/tools/ToolSearXng/ToolSearXng.node.ts b/packages/@n8n/nodes-langchain/nodes/tools/ToolSearXng/ToolSearXng.node.ts new file mode 100644 index 0000000000..95898850bc --- /dev/null +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolSearXng/ToolSearXng.node.ts @@ -0,0 +1,125 @@ +import { SearxngSearch } from '@langchain/community/tools/searxng_search'; +import { NodeConnectionType } from 'n8n-workflow'; +import type { + INodeType, + INodeTypeDescription, + ISupplyDataFunctions, + SupplyData, +} from 'n8n-workflow'; + +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + +type Options = { + numResults: number; + pageNumber: number; + language: string; + safesearch: 0 | 1 | 2; +}; + +export class ToolSearXng implements INodeType { + description: INodeTypeDescription = { + displayName: 'SearXNG', + name: 'toolSearXng', + icon: 'file:searXng.svg', + group: ['transform'], + version: 1, + description: 'Search in SearXNG', + defaults: { + name: 'SearXNG', + }, + codex: { + categories: ['AI'], + subcategories: { + AI: ['Tools'], + Tools: ['Other Tools'], + }, + resources: { + primaryDocumentation: [ + { + url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolsearxng/', + }, + ], + }, + }, + inputs: [], + outputs: [NodeConnectionType.AiTool], + outputNames: ['Tool'], + credentials: [ + { + name: 'searXngApi', + required: true, + }, + ], + properties: [ + getConnectionHintNoticeField([NodeConnectionType.AiAgent]), + { + displayName: 'Options', + name: 'options', + type: 'collection', + placeholder: 'Add Option', + default: {}, + options: [ + { + displayName: 'Number of Results', + name: 'numResults', + type: 'number', + default: 10, + }, + { + displayName: 'Search Page Number', + name: 'pageNumber', + type: 'number', + default: 1, + }, + { + displayName: 'Language', + name: 'language', + type: 'string', + default: 'en', + description: + 'Defines the language to use. It\'s a two-letter language code. (e.g., `en` for English, `es` for Spanish, or `fr` for French). Head to SearXNG search syntax page for more info.', + }, + { + displayName: 'Safe Search', + name: 'safesearch', + type: 'options', + options: [ + { + name: 'None', + value: 0, + }, + { + name: 'Moderate', + value: 1, + }, + { + name: 'Strict', + value: 2, + }, + ], + default: 0, + description: 'Filter search results of engines which support safe search', + }, + ], + }, + ], + }; + + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { + const credentials = await this.getCredentials<{ apiUrl: string }>('searXngApi'); + const options = this.getNodeParameter('options', itemIndex) as Options; + + const tool = new SearxngSearch({ + apiBase: credentials.apiUrl, + headers: { + Accept: 'application/json', + }, + params: options, + }); + + return { + response: logWrapper(tool, this), + }; + } +} diff --git a/packages/@n8n/nodes-langchain/nodes/tools/ToolSearXng/searXng.svg b/packages/@n8n/nodes-langchain/nodes/tools/ToolSearXng/searXng.svg new file mode 100644 index 0000000000..832aeda7a3 --- /dev/null +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolSearXng/searXng.svg @@ -0,0 +1 @@ + diff --git a/packages/@n8n/nodes-langchain/package.json b/packages/@n8n/nodes-langchain/package.json index 519b9f6ad4..2c72defd25 100644 --- a/packages/@n8n/nodes-langchain/package.json +++ b/packages/@n8n/nodes-langchain/package.json @@ -35,6 +35,7 @@ "dist/credentials/OpenRouterApi.credentials.js", "dist/credentials/PineconeApi.credentials.js", "dist/credentials/QdrantApi.credentials.js", + "dist/credentials/SearXngApi.credentials.js", "dist/credentials/SerpApi.credentials.js", "dist/credentials/WolframAlphaApi.credentials.js", "dist/credentials/XataApi.credentials.js", @@ -99,6 +100,7 @@ "dist/nodes/tools/ToolCalculator/ToolCalculator.node.js", "dist/nodes/tools/ToolCode/ToolCode.node.js", "dist/nodes/tools/ToolHttpRequest/ToolHttpRequest.node.js", + "dist/nodes/tools/ToolSearXng/ToolSearXng.node.js", "dist/nodes/tools/ToolSerpApi/ToolSerpApi.node.js", "dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js", "dist/nodes/tools/ToolWikipedia/ToolWikipedia.node.js",