fix: resolved merge conflict

This commit is contained in:
atilgner
2023-06-14 10:25:17 -07:00
25 changed files with 568 additions and 20 deletions
@@ -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 }
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

@@ -49,9 +49,12 @@ class MultiPromptChain_Chains implements INode {
promptTemplates.push(prompt.systemMessage)
}
const chain = MultiPromptChain.fromPrompts(model, promptNames, promptDescriptions, promptTemplates, undefined, {
verbose: process.env.DEBUG === 'true' ? true : false
} as any)
const chain = MultiPromptChain.fromLLMAndPrompts(model, {
promptNames,
promptDescriptions,
promptTemplates,
llmChainOpts: { verbose: process.env.DEBUG === 'true' ? true : false }
})
return chain
}
@@ -61,7 +64,7 @@ class MultiPromptChain_Chains implements INode {
const obj = { input }
if (options.socketIO && options.socketIOClientId) {
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId, 2)
const res = await chain.call(obj, [handler])
return res?.text
} else {
@@ -32,6 +32,12 @@ class MultiRetrievalQAChain_Chains implements INode {
name: 'vectorStoreRetriever',
type: 'VectorStoreRetriever',
list: true
},
{
label: 'Return Source Documents',
name: 'returnSourceDocuments',
type: 'boolean',
optional: true
}
]
}
@@ -39,6 +45,8 @@ class MultiRetrievalQAChain_Chains implements INode {
async init(nodeData: INodeData): Promise<any> {
const model = nodeData.inputs?.model as BaseLanguageModel
const vectorStoreRetriever = nodeData.inputs?.vectorStoreRetriever as VectorStoreRetriever[]
const returnSourceDocuments = nodeData.inputs?.returnSourceDocuments as boolean
const retrieverNames = []
const retrieverDescriptions = []
const retrievers = []
@@ -49,23 +57,29 @@ class MultiRetrievalQAChain_Chains implements INode {
retrievers.push(vs.vectorStore.asRetriever((vs.vectorStore as any).k ?? 4))
}
const chain = MultiRetrievalQAChain.fromRetrievers(model, retrieverNames, retrieverDescriptions, retrievers, undefined, {
verbose: process.env.DEBUG === 'true' ? true : false
} as any)
const chain = MultiRetrievalQAChain.fromLLMAndRetrievers(model, {
retrieverNames,
retrieverDescriptions,
retrievers,
retrievalQAChainOpts: { verbose: process.env.DEBUG === 'true' ? true : false, returnSourceDocuments }
})
return chain
}
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string | ICommonObject> {
const chain = nodeData.instance as MultiRetrievalQAChain
const returnSourceDocuments = nodeData.inputs?.returnSourceDocuments as boolean
const obj = { input }
if (options.socketIO && options.socketIOClientId) {
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId, 2, returnSourceDocuments)
const res = await chain.call(obj, [handler])
if (res.text && res.sourceDocuments) return res
return res?.text
} else {
const res = await chain.call(obj)
if (res.text && res.sourceDocuments) return res
return res?.text
}
}
@@ -43,6 +43,10 @@ class ChatOpenAI_ChatModels implements INode {
label: 'gpt-4-32k-0314',
name: 'gpt-4-32k-0314'
},
{
label: 'gpt-4-0613',
name: 'gpt-4-0613'
},
{
label: 'gpt-3.5-turbo',
name: 'gpt-3.5-turbo'
@@ -50,6 +54,10 @@ class ChatOpenAI_ChatModels implements INode {
{
label: 'gpt-3.5-turbo-0301',
name: 'gpt-3.5-turbo-0301'
},
{
label: 'gpt-3.5-turbo-0613',
name: 'gpt-3.5-turbo-0613'
}
],
default: 'gpt-3.5-turbo',
@@ -1,4 +1,4 @@
import { ZapierNLAWrapper, ZapiterNLAWrapperParams } from 'langchain/tools'
import { ZapierNLAWrapper, ZapierNLAWrapperParams } from 'langchain/tools'
import { INode, INodeData, INodeParams } from '../../../src/Interface'
import { ZapierToolKit } from 'langchain/agents'
@@ -32,7 +32,7 @@ class ZapierNLA_Tools implements INode {
async init(nodeData: INodeData): Promise<any> {
const apiKey = nodeData.inputs?.apiKey as string
const obj: Partial<ZapiterNLAWrapperParams> = {
const obj: Partial<ZapierNLAWrapperParams> = {
apiKey
}
const zapier = new ZapierNLAWrapper(obj)
+2 -3
View File
@@ -1,6 +1,6 @@
{
"name": "flowise-components",
"version": "1.2.12",
"version": "1.2.13",
"description": "Flowiseai Components",
"main": "dist/src/index",
"types": "dist/src/index.d.ts",
@@ -32,8 +32,7 @@
"faiss-node": "^0.2.1",
"form-data": "^4.0.0",
"graphql": "^16.6.0",
"html-to-text": "^9.0.5",
"langchain": "^0.0.91",
"langchain": "^0.0.94",
"linkifyjs": "^4.1.1",
"mammoth": "^1.5.1",
"moment": "^2.29.3",