-
-
Notifications
You must be signed in to change notification settings - Fork 17.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9ec444
commit 86ab305
Showing
20 changed files
with
529 additions
and
4 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
packages/components/nodes/agents/OpenAIFunctionAgent/OpenAIFunctionAgent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' | ||
import { initializeAgentExecutorWithOptions, AgentExecutor } from 'langchain/agents' | ||
import { Tool } from 'langchain/tools' | ||
import { CustomChainHandler, getBaseClasses } from '../../../src/utils' | ||
import { BaseLanguageModel } from 'langchain/base_language' | ||
import { flatten } from 'lodash' | ||
|
||
class OpenAIFunctionAgent_Agents implements INode { | ||
label: string | ||
name: string | ||
description: string | ||
type: string | ||
icon: string | ||
category: string | ||
baseClasses: string[] | ||
inputs: INodeParams[] | ||
|
||
constructor() { | ||
this.label = 'OpenAI Function Agent' | ||
this.name = 'openAIFunctionAgent' | ||
this.type = 'AgentExecutor' | ||
this.category = 'Agents' | ||
this.icon = 'openai.png' | ||
this.description = `An agent that uses OpenAI's Function Calling functionality to pick the tool and args to call` | ||
this.baseClasses = [this.type, ...getBaseClasses(AgentExecutor)] | ||
this.inputs = [ | ||
{ | ||
label: 'Allowed Tools', | ||
name: 'tools', | ||
type: 'Tool', | ||
list: true | ||
}, | ||
{ | ||
label: 'OpenAI Chat Model', | ||
name: 'model', | ||
description: | ||
'Only works with gpt-3.5-turbo-0613 and gpt-4-0613. Refer <a target="_blank" href="https://platform.openai.com/docs/guides/gpt/function-calling">docs</a> for more info', | ||
type: 'BaseChatModel' | ||
} | ||
] | ||
} | ||
|
||
async init(nodeData: INodeData): Promise<any> { | ||
const model = nodeData.inputs?.model as BaseLanguageModel | ||
let tools = nodeData.inputs?.tools as Tool[] | ||
tools = flatten(tools) | ||
|
||
const executor = await initializeAgentExecutorWithOptions(tools, model, { | ||
agentType: 'openai-functions', | ||
verbose: process.env.DEBUG === 'true' ? true : false | ||
}) | ||
return executor | ||
} | ||
|
||
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> { | ||
const executor = nodeData.instance as AgentExecutor | ||
|
||
if (options.socketIO && options.socketIOClientId) { | ||
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId) | ||
const result = await executor.run(input, [handler]) | ||
return result | ||
} else { | ||
const result = await executor.run(input) | ||
return result | ||
} | ||
} | ||
} | ||
|
||
module.exports = { nodeClass: OpenAIFunctionAgent_Agents } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.