File size: 2,198 Bytes
4114d85 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
import { INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses } from '../../../src/utils'
import { ChainTool } from 'langchain/tools'
import { BaseChain } from 'langchain/chains'
class ChainTool_Tools implements INode {
label: string
name: string
description: string
type: string
icon: string
category: string
baseClasses: string[]
inputs: INodeParams[]
constructor() {
this.label = 'Chain Tool'
this.name = 'chainTool'
this.type = 'ChainTool'
this.icon = 'chaintool.svg'
this.category = 'Tools'
this.description = 'Use a chain as allowed tool for agent'
this.baseClasses = [this.type, ...getBaseClasses(ChainTool)]
this.inputs = [
{
label: 'Chain Name',
name: 'name',
type: 'string',
placeholder: 'state-of-union-qa'
},
{
label: 'Chain Description',
name: 'description',
type: 'string',
rows: 3,
placeholder:
'State of the Union QA - useful for when you need to ask questions about the most recent state of the union address.'
},
{
label: 'Return Direct',
name: 'returnDirect',
type: 'boolean',
optional: true
},
{
label: 'Base Chain',
name: 'baseChain',
type: 'BaseChain'
}
]
}
async init(nodeData: INodeData): Promise<any> {
const name = nodeData.inputs?.name as string
const description = nodeData.inputs?.description as string
const baseChain = nodeData.inputs?.baseChain as BaseChain
const returnDirect = nodeData.inputs?.returnDirect as boolean
const obj = {
name,
description,
chain: baseChain
} as any
if (returnDirect) obj.returnDirect = returnDirect
const tool = new ChainTool(obj)
return tool
}
}
module.exports = { nodeClass: ChainTool_Tools }
|