mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
add aiplugintools
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { initializeAgentExecutor, AgentExecutor } from 'langchain/agents'
|
||||
import { Tool } from 'langchain/tools'
|
||||
import { AIPluginTool } from 'langchain/tools'
|
||||
import { BaseChatModel } from 'langchain/chat_models/base'
|
||||
import { getBaseClasses } from '../../../src/utils'
|
||||
|
||||
@@ -39,9 +39,20 @@ class MRKLAgentChat_Agents implements INode {
|
||||
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
const model = nodeData.inputs?.model as BaseChatModel
|
||||
const tools = nodeData.inputs?.tools as Tool[]
|
||||
const tools = nodeData.inputs?.tools
|
||||
|
||||
const executor = await initializeAgentExecutor(tools, model, 'chat-zero-shot-react-description', true)
|
||||
const allowedTools = []
|
||||
for (let i = 0; i < tools.length; i += 1) {
|
||||
if (tools[i].pluginUrl) {
|
||||
const pluginURL: string = tools[i].pluginUrl
|
||||
const aiplugin = await AIPluginTool.fromPluginUrl(pluginURL)
|
||||
allowedTools.push(aiplugin)
|
||||
} else {
|
||||
allowedTools.push(tools[i])
|
||||
}
|
||||
}
|
||||
|
||||
const executor = await initializeAgentExecutor(allowedTools, model, 'chat-zero-shot-react-description', true)
|
||||
return executor
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { AIPluginTool } from 'langchain/tools'
|
||||
import { getBaseClasses } from '../../../src/utils'
|
||||
|
||||
class AIPlugin implements INode {
|
||||
label: string
|
||||
@@ -17,6 +19,7 @@ class AIPlugin implements INode {
|
||||
this.icon = 'aiplugin.svg'
|
||||
this.category = 'Tools'
|
||||
this.description = 'Execute actions using ChatGPT Plugin Url'
|
||||
this.baseClasses = [this.type, ...getBaseClasses(AIPluginTool)]
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Plugin Url',
|
||||
@@ -27,15 +30,13 @@ class AIPlugin implements INode {
|
||||
]
|
||||
}
|
||||
|
||||
async getBaseClasses(): Promise<string[]> {
|
||||
return ['Tool']
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
const { AIPluginTool } = await import('langchain/tools')
|
||||
const pluginUrl = nodeData.inputs?.pluginUrl as string
|
||||
|
||||
const aiplugin = await AIPluginTool.fromPluginUrl(pluginUrl)
|
||||
// Doesn't work currently
|
||||
// const aiplugin = await AIPluginTool.fromPluginUrl(pluginUrl)
|
||||
const aiplugin = {
|
||||
pluginUrl: pluginUrl
|
||||
}
|
||||
return aiplugin
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user