mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat: Add AI tool building capabilities (#7336)
Github issue / Community forum post (link here to close automatically): https://community.n8n.io/t/langchain-memory-chat/23733 --------- Signed-off-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: Val <68596159+valya@users.noreply.github.com> Co-authored-by: Alex Grozav <alex@grozav.com> Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in> Co-authored-by: Deborah <deborah@starfallprojects.co.uk> Co-authored-by: Jesper Bylund <mail@jesperbylund.com> Co-authored-by: Jon <jonathan.bennetts@gmail.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: Giulio Andreini <andreini@netseven.it> Co-authored-by: Mason Geloso <Mason.geloso@gmail.com> Co-authored-by: Mason Geloso <hone@Masons-Mac-mini.local> Co-authored-by: Mutasem Aldmour <mutasem@n8n.io>
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
/* eslint-disable n8n-nodes-base/node-dirname-against-convention */
|
||||
import {
|
||||
NodeConnectionType,
|
||||
type IExecuteFunctions,
|
||||
type INodeType,
|
||||
type INodeTypeDescription,
|
||||
type SupplyData,
|
||||
} from 'n8n-workflow';
|
||||
import { SerpAPI } from 'langchain/tools';
|
||||
import { logWrapper } from '../../../utils/logWrapper';
|
||||
import { getConnectionHintNoticeField } from '../../../utils/sharedFields';
|
||||
|
||||
export class ToolSerpApi implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'SerpApi (Google Search)',
|
||||
name: 'toolSerpApi',
|
||||
icon: 'file:serpApi.svg',
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
description: 'Search in Google using SerpAPI',
|
||||
defaults: {
|
||||
name: 'SerpAPI',
|
||||
},
|
||||
codex: {
|
||||
categories: ['AI'],
|
||||
subcategories: {
|
||||
AI: ['Tools'],
|
||||
},
|
||||
resources: {
|
||||
primaryDocumentation: [
|
||||
{
|
||||
url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolserpapi/',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
|
||||
inputs: [],
|
||||
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
|
||||
outputs: [NodeConnectionType.AiTool],
|
||||
outputNames: ['Tool'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'serpApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
getConnectionHintNoticeField([NodeConnectionType.AiAgent]),
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Country',
|
||||
name: 'gl',
|
||||
type: 'string',
|
||||
default: 'us',
|
||||
description:
|
||||
'Defines the country to use for search. Head to <a href="https://serpapi.com/google-countries">Google countries page</a> for a full list of supported countries.',
|
||||
},
|
||||
{
|
||||
displayName: 'Device',
|
||||
name: 'device',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Desktop',
|
||||
value: 'desktop',
|
||||
},
|
||||
{
|
||||
name: 'Mobile',
|
||||
value: 'mobile',
|
||||
},
|
||||
{
|
||||
name: 'Tablet',
|
||||
value: 'tablet',
|
||||
},
|
||||
],
|
||||
default: 'desktop',
|
||||
description: 'Device to use to get the results',
|
||||
},
|
||||
{
|
||||
displayName: 'Explicit Array',
|
||||
name: 'no_cache',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
'Whether to force SerpApi to fetch the Google results even if a cached version is already present. Cache expires after 1h. Cached searches are free, and are not counted towards your searches per month.',
|
||||
},
|
||||
{
|
||||
displayName: 'Google Domain',
|
||||
name: 'google_domain',
|
||||
type: 'string',
|
||||
default: 'google.com',
|
||||
description:
|
||||
'Defines the country to use for search. Head to <a href="https://serpapi.com/google-countries">Google countries page</a> for a full list of supported countries.',
|
||||
},
|
||||
{
|
||||
displayName: 'Language',
|
||||
name: 'hl',
|
||||
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 <a href="https://serpapi.com/google-languages">Google languages page</a> for a full list of supported languages.',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> {
|
||||
const credentials = await this.getCredentials('serpApi');
|
||||
|
||||
const options = this.getNodeParameter('options', itemIndex) as object;
|
||||
|
||||
return {
|
||||
response: logWrapper(new SerpAPI(credentials.apiKey as string, options), this),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user