Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
83 lines
2.1 KiB
TypeScript
83 lines
2.1 KiB
TypeScript
import { WikipediaQueryRun } from '@langchain/community/tools/wikipedia_query_run';
|
|
import {
|
|
type IExecuteFunctions,
|
|
NodeConnectionTypes,
|
|
type INodeType,
|
|
type INodeTypeDescription,
|
|
type ISupplyDataFunctions,
|
|
type SupplyData,
|
|
type INodeExecutionData,
|
|
nodeNameToToolName,
|
|
} from 'n8n-workflow';
|
|
|
|
import { logWrapper, getConnectionHintNoticeField } from '@n8n/ai-utilities';
|
|
|
|
function getTool(ctx: ISupplyDataFunctions | IExecuteFunctions): WikipediaQueryRun {
|
|
const WikiTool = new WikipediaQueryRun();
|
|
WikiTool.name = nodeNameToToolName(ctx.getNode());
|
|
WikiTool.description =
|
|
'A tool for interacting with and fetching data from the Wikipedia API. The input should always be a string query.';
|
|
return WikiTool;
|
|
}
|
|
|
|
export class ToolWikipedia implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'Wikipedia',
|
|
name: 'toolWikipedia',
|
|
icon: 'file:wikipedia.svg',
|
|
group: ['transform'],
|
|
version: 1,
|
|
description: 'Search in Wikipedia',
|
|
defaults: {
|
|
name: 'Wikipedia',
|
|
},
|
|
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.toolwikipedia/',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
|
|
inputs: [],
|
|
|
|
outputs: [NodeConnectionTypes.AiTool],
|
|
outputNames: ['Tool'],
|
|
properties: [getConnectionHintNoticeField([NodeConnectionTypes.AiAgent])],
|
|
};
|
|
|
|
async supplyData(this: ISupplyDataFunctions): Promise<SupplyData> {
|
|
return {
|
|
response: logWrapper(getTool(this), this),
|
|
};
|
|
}
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
const WikiTool = getTool(this);
|
|
|
|
const items = this.getInputData();
|
|
|
|
const response: INodeExecutionData[] = [];
|
|
for (let itemIndex = 0; itemIndex < this.getInputData().length; itemIndex++) {
|
|
const item = items[itemIndex];
|
|
if (item === undefined) {
|
|
continue;
|
|
}
|
|
const result = await WikiTool.invoke(item.json);
|
|
response.push({
|
|
json: { response: result },
|
|
pairedItem: { item: itemIndex },
|
|
});
|
|
}
|
|
|
|
return [response];
|
|
}
|
|
}
|