Merge pull request #503 from FlowiseAI/bugfix/ChainToolWithLLMChain

Bugfix/ChainTool with LLMChain
This commit is contained in:
Henry Heng
2023-07-07 20:25:59 +01:00
committed by GitHub
2 changed files with 26 additions and 1 deletions
@@ -1,7 +1,7 @@
import { INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses } from '../../../src/utils'
import { ChainTool } from 'langchain/tools'
import { BaseChain } from 'langchain/chains'
import { ChainTool } from './core'
class ChainTool_Tools implements INode {
label: string
@@ -0,0 +1,25 @@
import { DynamicTool, DynamicToolInput } from 'langchain/tools'
import { BaseChain } from 'langchain/chains'
export interface ChainToolInput extends Omit<DynamicToolInput, 'func'> {
chain: BaseChain
}
export class ChainTool extends DynamicTool {
chain: BaseChain
constructor({ chain, ...rest }: ChainToolInput) {
super({
...rest,
func: async (input, runManager) => {
// To enable LLM Chain which has promptValues
if ((chain as any).prompt && (chain as any).prompt.promptValues) {
const values = await chain.call((chain as any).prompt.promptValues, runManager?.getChild())
return values?.text
}
return chain.run(input, runManager?.getChild())
}
})
this.chain = chain
}
}