mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
add fix to allow chaintool with llmchain
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user