Searxng Tool implementation (#2599)

* Searxng Tool implementation, first commit with most functionality

* Fixed complains of pnpm lint

* Picky linter
This commit is contained in:
Torsten Raudssus 2024-06-11 17:29:07 +02:00 committed by GitHub
parent f1e78d870e
commit 66e1296a06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" id="svg8" version="1.1" viewBox="0 0 92 92" height="92mm" width="92mm">
<defs id="defs2"/>
<metadata id="metadata5">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<g transform="translate(-40.921303,-17.416526)" id="layer1">
<circle r="0" style="fill:none;stroke:#000000;stroke-width:12;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" cy="92" cx="75" id="path3713"/>
<circle r="30" cy="53.902557" cx="75.921303" id="path834" style="fill:none;fill-opacity:1;stroke:#3050ff;stroke-width:10;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"/>
<path d="m 67.514849,37.91524 a 18,18 0 0 1 21.051475,3.312407 18,18 0 0 1 3.137312,21.078282" id="path852" style="fill:none;fill-opacity:1;stroke:#3050ff;stroke-width:5;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"/>
<rect transform="rotate(-46.234709)" ry="1.8669105e-13" y="122.08995" x="3.7063529" height="39.963303" width="18.846331" id="rect912" style="opacity:1;fill:#3050ff;fill-opacity:1;stroke:none;stroke-width:8;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -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 <a target="_blank" href="https://docs.searxng.org/user/configured_engines.html#configured-engines">Configured Engines</a>)',
optional: true,
additionalParams: true,
type: 'string'
},
{
label: 'Engines',
name: 'engines',
description:
'Comma separated list, specifies the active search engines. (see <a target="_blank" href="https://docs.searxng.org/user/configured_engines.html#configured-engines">Configured Engines</a>)',
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<any> {
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 }