Skip to content

Commit 86ab305

Browse files
committed
add openai function calling support
1 parent a9ec444 commit 86ab305

20 files changed

+529
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
2+
import { initializeAgentExecutorWithOptions, AgentExecutor } from 'langchain/agents'
3+
import { Tool } from 'langchain/tools'
4+
import { CustomChainHandler, getBaseClasses } from '../../../src/utils'
5+
import { BaseLanguageModel } from 'langchain/base_language'
6+
import { flatten } from 'lodash'
7+
8+
class OpenAIFunctionAgent_Agents implements INode {
9+
label: string
10+
name: string
11+
description: string
12+
type: string
13+
icon: string
14+
category: string
15+
baseClasses: string[]
16+
inputs: INodeParams[]
17+
18+
constructor() {
19+
this.label = 'OpenAI Function Agent'
20+
this.name = 'openAIFunctionAgent'
21+
this.type = 'AgentExecutor'
22+
this.category = 'Agents'
23+
this.icon = 'openai.png'
24+
this.description = `An agent that uses OpenAI's Function Calling functionality to pick the tool and args to call`
25+
this.baseClasses = [this.type, ...getBaseClasses(AgentExecutor)]
26+
this.inputs = [
27+
{
28+
label: 'Allowed Tools',
29+
name: 'tools',
30+
type: 'Tool',
31+
list: true
32+
},
33+
{
34+
label: 'OpenAI Chat Model',
35+
name: 'model',
36+
description:
37+
'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',
38+
type: 'BaseChatModel'
39+
}
40+
]
41+
}
42+
43+
async init(nodeData: INodeData): Promise<any> {
44+
const model = nodeData.inputs?.model as BaseLanguageModel
45+
let tools = nodeData.inputs?.tools as Tool[]
46+
tools = flatten(tools)
47+
48+
const executor = await initializeAgentExecutorWithOptions(tools, model, {
49+
agentType: 'openai-functions',
50+
verbose: process.env.DEBUG === 'true' ? true : false
51+
})
52+
return executor
53+
}
54+
55+
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
56+
const executor = nodeData.instance as AgentExecutor
57+
58+
if (options.socketIO && options.socketIOClientId) {
59+
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
60+
const result = await executor.run(input, [handler])
61+
return result
62+
} else {
63+
const result = await executor.run(input)
64+
return result
65+
}
66+
}
67+
}
68+
69+
module.exports = { nodeClass: OpenAIFunctionAgent_Agents }
Loading

packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts

+8
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,21 @@ class ChatOpenAI_ChatModels implements INode {
4343
label: 'gpt-4-32k-0314',
4444
name: 'gpt-4-32k-0314'
4545
},
46+
{
47+
label: 'gpt-4-0613',
48+
name: 'gpt-4-0613'
49+
},
4650
{
4751
label: 'gpt-3.5-turbo',
4852
name: 'gpt-3.5-turbo'
4953
},
5054
{
5155
label: 'gpt-3.5-turbo-0301',
5256
name: 'gpt-3.5-turbo-0301'
57+
},
58+
{
59+
label: 'gpt-3.5-turbo-0613',
60+
name: 'gpt-3.5-turbo-0613'
5361
}
5462
],
5563
default: 'gpt-3.5-turbo',

packages/components/nodes/tools/ZapierNLA/ZapierNLA.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ZapierNLAWrapper, ZapiterNLAWrapperParams } from 'langchain/tools'
1+
import { ZapierNLAWrapper, ZapierNLAWrapperParams } from 'langchain/tools'
22
import { INode, INodeData, INodeParams } from '../../../src/Interface'
33
import { ZapierToolKit } from 'langchain/agents'
44

@@ -32,7 +32,7 @@ class ZapierNLA_Tools implements INode {
3232
async init(nodeData: INodeData): Promise<any> {
3333
const apiKey = nodeData.inputs?.apiKey as string
3434

35-
const obj: Partial<ZapiterNLAWrapperParams> = {
35+
const obj: Partial<ZapierNLAWrapperParams> = {
3636
apiKey
3737
}
3838
const zapier = new ZapierNLAWrapper(obj)

packages/components/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"faiss-node": "^0.2.1",
3333
"form-data": "^4.0.0",
3434
"graphql": "^16.6.0",
35-
"langchain": "^0.0.91",
35+
"langchain": "^0.0.94",
3636
"linkifyjs": "^4.1.1",
3737
"mammoth": "^1.5.1",
3838
"moment": "^2.29.3",

packages/server/marketplaces/API Agent.json

+24
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,21 @@
286286
"label": "gpt-4-32k-0314",
287287
"name": "gpt-4-32k-0314"
288288
},
289+
{
290+
"label": "gpt-4-0613",
291+
"name": "gpt-4-0613"
292+
},
289293
{
290294
"label": "gpt-3.5-turbo",
291295
"name": "gpt-3.5-turbo"
292296
},
293297
{
294298
"label": "gpt-3.5-turbo-0301",
295299
"name": "gpt-3.5-turbo-0301"
300+
},
301+
{
302+
"label": "gpt-3.5-turbo-0613",
303+
"name": "gpt-3.5-turbo-0613"
296304
}
297305
],
298306
"default": "gpt-3.5-turbo",
@@ -481,13 +489,21 @@
481489
"label": "gpt-4-32k-0314",
482490
"name": "gpt-4-32k-0314"
483491
},
492+
{
493+
"label": "gpt-4-0613",
494+
"name": "gpt-4-0613"
495+
},
484496
{
485497
"label": "gpt-3.5-turbo",
486498
"name": "gpt-3.5-turbo"
487499
},
488500
{
489501
"label": "gpt-3.5-turbo-0301",
490502
"name": "gpt-3.5-turbo-0301"
503+
},
504+
{
505+
"label": "gpt-3.5-turbo-0613",
506+
"name": "gpt-3.5-turbo-0613"
491507
}
492508
],
493509
"default": "gpt-3.5-turbo",
@@ -620,13 +636,21 @@
620636
"label": "gpt-4-32k-0314",
621637
"name": "gpt-4-32k-0314"
622638
},
639+
{
640+
"label": "gpt-4-0613",
641+
"name": "gpt-4-0613"
642+
},
623643
{
624644
"label": "gpt-3.5-turbo",
625645
"name": "gpt-3.5-turbo"
626646
},
627647
{
628648
"label": "gpt-3.5-turbo-0301",
629649
"name": "gpt-3.5-turbo-0301"
650+
},
651+
{
652+
"label": "gpt-3.5-turbo-0613",
653+
"name": "gpt-3.5-turbo-0613"
630654
}
631655
],
632656
"default": "gpt-3.5-turbo",

packages/server/marketplaces/AutoGPT.json

+8
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,21 @@
132132
"label": "gpt-4-32k-0314",
133133
"name": "gpt-4-32k-0314"
134134
},
135+
{
136+
"label": "gpt-4-0613",
137+
"name": "gpt-4-0613"
138+
},
135139
{
136140
"label": "gpt-3.5-turbo",
137141
"name": "gpt-3.5-turbo"
138142
},
139143
{
140144
"label": "gpt-3.5-turbo-0301",
141145
"name": "gpt-3.5-turbo-0301"
146+
},
147+
{
148+
"label": "gpt-3.5-turbo-0613",
149+
"name": "gpt-3.5-turbo-0613"
142150
}
143151
],
144152
"default": "gpt-3.5-turbo",

packages/server/marketplaces/BabyAGI.json

+8
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,21 @@
235235
"label": "gpt-4-32k-0314",
236236
"name": "gpt-4-32k-0314"
237237
},
238+
{
239+
"label": "gpt-4-0613",
240+
"name": "gpt-4-0613"
241+
},
238242
{
239243
"label": "gpt-3.5-turbo",
240244
"name": "gpt-3.5-turbo"
241245
},
242246
{
243247
"label": "gpt-3.5-turbo-0301",
244248
"name": "gpt-3.5-turbo-0301"
249+
},
250+
{
251+
"label": "gpt-3.5-turbo-0613",
252+
"name": "gpt-3.5-turbo-0613"
245253
}
246254
],
247255
"default": "gpt-3.5-turbo",

packages/server/marketplaces/ChatGPTPlugin.json

+8
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,21 @@
295295
"label": "gpt-4-32k-0314",
296296
"name": "gpt-4-32k-0314"
297297
},
298+
{
299+
"label": "gpt-4-0613",
300+
"name": "gpt-4-0613"
301+
},
298302
{
299303
"label": "gpt-3.5-turbo",
300304
"name": "gpt-3.5-turbo"
301305
},
302306
{
303307
"label": "gpt-3.5-turbo-0301",
304308
"name": "gpt-3.5-turbo-0301"
309+
},
310+
{
311+
"label": "gpt-3.5-turbo-0613",
312+
"name": "gpt-3.5-turbo-0613"
305313
}
306314
],
307315
"default": "gpt-3.5-turbo",

packages/server/marketplaces/Conversational Agent.json

+8
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,21 @@
4242
"label": "gpt-4-32k-0314",
4343
"name": "gpt-4-32k-0314"
4444
},
45+
{
46+
"label": "gpt-4-0613",
47+
"name": "gpt-4-0613"
48+
},
4549
{
4650
"label": "gpt-3.5-turbo",
4751
"name": "gpt-3.5-turbo"
4852
},
4953
{
5054
"label": "gpt-3.5-turbo-0301",
5155
"name": "gpt-3.5-turbo-0301"
56+
},
57+
{
58+
"label": "gpt-3.5-turbo-0613",
59+
"name": "gpt-3.5-turbo-0613"
5260
}
5361
],
5462
"default": "gpt-3.5-turbo",

packages/server/marketplaces/Conversational Retrieval QA Chain.json

+8
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,21 @@
356356
"label": "gpt-4-32k-0314",
357357
"name": "gpt-4-32k-0314"
358358
},
359+
{
360+
"label": "gpt-4-0613",
361+
"name": "gpt-4-0613"
362+
},
359363
{
360364
"label": "gpt-3.5-turbo",
361365
"name": "gpt-3.5-turbo"
362366
},
363367
{
364368
"label": "gpt-3.5-turbo-0301",
365369
"name": "gpt-3.5-turbo-0301"
370+
},
371+
{
372+
"label": "gpt-3.5-turbo-0613",
373+
"name": "gpt-3.5-turbo-0613"
366374
}
367375
],
368376
"default": "gpt-3.5-turbo",

packages/server/marketplaces/Github Repo QnA.json

+8
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,21 @@
373373
"label": "gpt-4-32k-0314",
374374
"name": "gpt-4-32k-0314"
375375
},
376+
{
377+
"label": "gpt-4-0613",
378+
"name": "gpt-4-0613"
379+
},
376380
{
377381
"label": "gpt-3.5-turbo",
378382
"name": "gpt-3.5-turbo"
379383
},
380384
{
381385
"label": "gpt-3.5-turbo-0301",
382386
"name": "gpt-3.5-turbo-0301"
387+
},
388+
{
389+
"label": "gpt-3.5-turbo-0613",
390+
"name": "gpt-3.5-turbo-0613"
383391
}
384392
],
385393
"default": "gpt-3.5-turbo",

packages/server/marketplaces/Multi Prompt Chain.json

+8
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,21 @@
302302
"label": "gpt-4-32k-0314",
303303
"name": "gpt-4-32k-0314"
304304
},
305+
{
306+
"label": "gpt-4-0613",
307+
"name": "gpt-4-0613"
308+
},
305309
{
306310
"label": "gpt-3.5-turbo",
307311
"name": "gpt-3.5-turbo"
308312
},
309313
{
310314
"label": "gpt-3.5-turbo-0301",
311315
"name": "gpt-3.5-turbo-0301"
316+
},
317+
{
318+
"label": "gpt-3.5-turbo-0613",
319+
"name": "gpt-3.5-turbo-0613"
312320
}
313321
],
314322
"default": "gpt-3.5-turbo",

packages/server/marketplaces/Multi Retrieval QA Chain.json

+8
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,21 @@
299299
"label": "gpt-4-32k-0314",
300300
"name": "gpt-4-32k-0314"
301301
},
302+
{
303+
"label": "gpt-4-0613",
304+
"name": "gpt-4-0613"
305+
},
302306
{
303307
"label": "gpt-3.5-turbo",
304308
"name": "gpt-3.5-turbo"
305309
},
306310
{
307311
"label": "gpt-3.5-turbo-0301",
308312
"name": "gpt-3.5-turbo-0301"
313+
},
314+
{
315+
"label": "gpt-3.5-turbo-0613",
316+
"name": "gpt-3.5-turbo-0613"
309317
}
310318
],
311319
"default": "gpt-3.5-turbo",

0 commit comments

Comments
 (0)