diff --git a/packages/components/credentials/GoogleSearchApi.credential.ts b/packages/components/credentials/GoogleSearchApi.credential.ts new file mode 100644 index 00000000..cb82b25a --- /dev/null +++ b/packages/components/credentials/GoogleSearchApi.credential.ts @@ -0,0 +1,31 @@ +import { INodeParams, INodeCredential } from '../src/Interface' + +class GoogleSearchApi implements INodeCredential { + label: string + name: string + version: number + description: string + inputs: INodeParams[] + + constructor() { + this.label = 'Google Custom Search API' + this.name = 'googleCustomSearchApi' + this.version = 1.0 + this.description = + 'Please refer to the Google Cloud Console for instructions on how to create an API key, and visit the Search Engine Creation page to learn how to generate your Search Engine ID.' + this.inputs = [ + { + label: 'Google Custom Search Api Key', + name: 'googleCustomSearchApiKey', + type: 'password' + }, + { + label: 'Programmable Search Engine ID', + name: 'googleCustomSearchApiId', + type: 'string' + } + ] + } +} + +module.exports = { credClass: GoogleSearchApi } diff --git a/packages/components/nodes/tools/GoogleSearchAPI/GoogleSearchAPI.ts b/packages/components/nodes/tools/GoogleSearchAPI/GoogleSearchAPI.ts new file mode 100644 index 00000000..29ebae8b --- /dev/null +++ b/packages/components/nodes/tools/GoogleSearchAPI/GoogleSearchAPI.ts @@ -0,0 +1,43 @@ +import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' +import { GoogleCustomSearch } from 'langchain/tools' + +class GoogleCustomSearchAPI_Tools implements INode { + label: string + name: string + version: number + description: string + type: string + icon: string + category: string + baseClasses: string[] + credential: INodeParams + inputs: INodeParams[] + + constructor() { + this.label = 'Google Custom Search' + this.name = 'googleCustomSearch' + this.version = 1.0 + this.type = 'GoogleCustomSearchAPI' + this.icon = 'google.png' + this.category = 'Tools' + this.description = 'Wrapper around Google Custom Search API - a real-time API to access Google search results' + this.inputs = [] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['googleCustomSearchApi'] + } + this.baseClasses = [this.type, ...getBaseClasses(GoogleCustomSearch)] + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const googleApiKey = getCredentialParam('googleCustomSearchApiKey', credentialData, nodeData) + const googleCseId = getCredentialParam('googleCustomSearchApiId', credentialData, nodeData) + return new GoogleCustomSearch({ apiKey: googleApiKey, googleCSEId: googleCseId }) + } +} + +module.exports = { nodeClass: GoogleCustomSearchAPI_Tools } diff --git a/packages/components/nodes/tools/GoogleSearchAPI/google.png b/packages/components/nodes/tools/GoogleSearchAPI/google.png new file mode 100644 index 00000000..c7cd4ca1 Binary files /dev/null and b/packages/components/nodes/tools/GoogleSearchAPI/google.png differ