Skip to content

Commit 7a33a4d

Browse files
authored
Merge branch 'main' into vectara-upload-files
2 parents 4925cf6 + 0c71e62 commit 7a33a4d

File tree

48 files changed

+820
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+820
-99
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { INodeParams, INodeCredential } from '../src/Interface'
2+
3+
class LangfuseApi implements INodeCredential {
4+
label: string
5+
name: string
6+
version: number
7+
description: string
8+
inputs: INodeParams[]
9+
10+
constructor() {
11+
this.label = 'Langfuse API'
12+
this.name = 'langfuseApi'
13+
this.version = 1.0
14+
this.description =
15+
'Refer to <a target="_blank" href="https://langfuse.com/docs/get-started/">official guide</a> on how to get API key on Langfuse'
16+
this.inputs = [
17+
{
18+
label: 'Secret Key',
19+
name: 'langFuseSecretKey',
20+
type: 'password',
21+
placeholder: 'sk-lf-abcdefg'
22+
},
23+
{
24+
label: 'Public Key',
25+
name: 'langFusePublicKey',
26+
type: 'string',
27+
placeholder: 'pk-lf-abcdefg'
28+
},
29+
{
30+
label: 'Endpoint',
31+
name: 'langFuseEndpoint',
32+
type: 'string',
33+
default: 'https://cloud.langfuse.com'
34+
}
35+
]
36+
}
37+
}
38+
39+
module.exports = { credClass: LangfuseApi }
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { INodeParams, INodeCredential } from '../src/Interface'
2+
3+
class LangsmithApi implements INodeCredential {
4+
label: string
5+
name: string
6+
version: number
7+
description: string
8+
inputs: INodeParams[]
9+
10+
constructor() {
11+
this.label = 'Langsmith API'
12+
this.name = 'langsmithApi'
13+
this.version = 1.0
14+
this.description =
15+
'Refer to <a target="_blank" href="https://docs.smith.langchain.com/">official guide</a> on how to get API key on Langsmith'
16+
this.inputs = [
17+
{
18+
label: 'API Key',
19+
name: 'langSmithApiKey',
20+
type: 'password',
21+
placeholder: '<LANGSMITH_API_KEY>'
22+
},
23+
{
24+
label: 'Endpoint',
25+
name: 'langSmithEndpoint',
26+
type: 'string',
27+
default: 'https://api.smith.langchain.com'
28+
}
29+
]
30+
}
31+
}
32+
33+
module.exports = { credClass: LangsmithApi }

packages/components/nodes/agents/AirtableAgent/AirtableAgent.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../
44
import { LoadPyodide, finalSystemPrompt, systemPrompt } from './core'
55
import { LLMChain } from 'langchain/chains'
66
import { BaseLanguageModel } from 'langchain/base_language'
7-
import { ConsoleCallbackHandler, CustomChainHandler } from '../../../src/handler'
7+
import { ConsoleCallbackHandler, CustomChainHandler, additionalCallbacks } from '../../../src/handler'
88
import axios from 'axios'
99

1010
class Airtable_Agents implements INode {
@@ -102,6 +102,7 @@ class Airtable_Agents implements INode {
102102

103103
const loggerHandler = new ConsoleCallbackHandler(options.logger)
104104
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
105+
const callbacks = await additionalCallbacks(nodeData, options)
105106

106107
const pyodide = await LoadPyodide()
107108

@@ -141,7 +142,7 @@ json.dumps(my_dict)`
141142
dict: dataframeColDict,
142143
question: input
143144
}
144-
const res = await chain.call(inputs, [loggerHandler])
145+
const res = await chain.call(inputs, [loggerHandler, ...callbacks])
145146
pythonCode = res?.text
146147
}
147148

@@ -169,10 +170,10 @@ json.dumps(my_dict)`
169170
}
170171

171172
if (options.socketIO && options.socketIOClientId) {
172-
const result = await chain.call(inputs, [loggerHandler, handler])
173+
const result = await chain.call(inputs, [loggerHandler, handler, ...callbacks])
173174
return result?.text
174175
} else {
175-
const result = await chain.call(inputs, [loggerHandler])
176+
const result = await chain.call(inputs, [loggerHandler, ...callbacks])
176177
return result?.text
177178
}
178179
}

packages/components/nodes/agents/CSVAgent/CSVAgent.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getBaseClasses } from '../../../src/utils'
44
import { LoadPyodide, finalSystemPrompt, systemPrompt } from './core'
55
import { LLMChain } from 'langchain/chains'
66
import { BaseLanguageModel } from 'langchain/base_language'
7-
import { ConsoleCallbackHandler, CustomChainHandler } from '../../../src/handler'
7+
import { ConsoleCallbackHandler, CustomChainHandler, additionalCallbacks } from '../../../src/handler'
88

99
class CSV_Agents implements INode {
1010
label: string
@@ -63,6 +63,7 @@ class CSV_Agents implements INode {
6363

6464
const loggerHandler = new ConsoleCallbackHandler(options.logger)
6565
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
66+
const callbacks = await additionalCallbacks(nodeData, options)
6667

6768
let files: string[] = []
6869

@@ -119,7 +120,7 @@ json.dumps(my_dict)`
119120
dict: dataframeColDict,
120121
question: input
121122
}
122-
const res = await chain.call(inputs, [loggerHandler])
123+
const res = await chain.call(inputs, [loggerHandler, ...callbacks])
123124
pythonCode = res?.text
124125
}
125126

@@ -149,10 +150,10 @@ json.dumps(my_dict)`
149150
}
150151

151152
if (options.socketIO && options.socketIOClientId) {
152-
const result = await chain.call(inputs, [loggerHandler, handler])
153+
const result = await chain.call(inputs, [loggerHandler, handler, ...callbacks])
153154
return result?.text
154155
} else {
155-
const result = await chain.call(inputs, [loggerHandler])
156+
const result = await chain.call(inputs, [loggerHandler, ...callbacks])
156157
return result?.text
157158
}
158159
}

packages/components/nodes/agents/ConversationalAgent/ConversationalAgent.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BaseChatMemory } from 'langchain/memory'
55
import { getBaseClasses, mapChatHistory } from '../../../src/utils'
66
import { BaseLanguageModel } from 'langchain/base_language'
77
import { flatten } from 'lodash'
8+
import { additionalCallbacks } from '../../../src/handler'
89

910
const DEFAULT_PREFIX = `Assistant is a large language model trained by OpenAI.
1011
@@ -91,13 +92,14 @@ class ConversationalAgent_Agents implements INode {
9192
const executor = nodeData.instance as AgentExecutor
9293
const memory = nodeData.inputs?.memory as BaseChatMemory
9394

95+
const callbacks = await additionalCallbacks(nodeData, options)
96+
9497
if (options && options.chatHistory) {
9598
memory.chatHistory = mapChatHistory(options)
9699
executor.memory = memory
97100
}
98101

99-
const result = await executor.call({ input })
100-
102+
const result = await executor.call({ input }, [...callbacks])
101103
return result?.output
102104
}
103105
}

packages/components/nodes/agents/ConversationalRetrievalAgent/ConversationalRetrievalAgent.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { initializeAgentExecutorWithOptions, AgentExecutor } from 'langchain/age
33
import { getBaseClasses, mapChatHistory } from '../../../src/utils'
44
import { flatten } from 'lodash'
55
import { BaseChatMemory } from 'langchain/memory'
6-
import { ConsoleCallbackHandler, CustomChainHandler } from '../../../src/handler'
6+
import { ConsoleCallbackHandler, CustomChainHandler, additionalCallbacks } from '../../../src/handler'
77

88
const defaultMessage = `Do your best to answer the questions. Feel free to use any tools available to look up relevant information, only if necessary.`
99

@@ -86,13 +86,14 @@ class ConversationalRetrievalAgent_Agents implements INode {
8686
}
8787

8888
const loggerHandler = new ConsoleCallbackHandler(options.logger)
89+
const callbacks = await additionalCallbacks(nodeData, options)
8990

9091
if (options.socketIO && options.socketIOClientId) {
9192
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
92-
const result = await executor.call({ input }, [loggerHandler, handler])
93+
const result = await executor.call({ input }, [loggerHandler, handler, ...callbacks])
9394
return result?.output
9495
} else {
95-
const result = await executor.call({ input }, [loggerHandler])
96+
const result = await executor.call({ input }, [loggerHandler, ...callbacks])
9697
return result?.output
9798
}
9899
}

packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { INode, INodeData, INodeParams } from '../../../src/Interface'
1+
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
22
import { initializeAgentExecutorWithOptions, AgentExecutor } from 'langchain/agents'
33
import { getBaseClasses } from '../../../src/utils'
44
import { Tool } from 'langchain/tools'
55
import { BaseLanguageModel } from 'langchain/base_language'
66
import { flatten } from 'lodash'
7+
import { additionalCallbacks } from '../../../src/handler'
78

89
class MRKLAgentChat_Agents implements INode {
910
label: string
@@ -51,9 +52,12 @@ class MRKLAgentChat_Agents implements INode {
5152
return executor
5253
}
5354

54-
async run(nodeData: INodeData, input: string): Promise<string> {
55+
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
5556
const executor = nodeData.instance as AgentExecutor
56-
const result = await executor.call({ input })
57+
58+
const callbacks = await additionalCallbacks(nodeData, options)
59+
60+
const result = await executor.call({ input }, [...callbacks])
5761

5862
return result?.output
5963
}

packages/components/nodes/agents/MRKLAgentLLM/MRKLAgentLLM.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { INode, INodeData, INodeParams } from '../../../src/Interface'
1+
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
22
import { initializeAgentExecutorWithOptions, AgentExecutor } from 'langchain/agents'
33
import { Tool } from 'langchain/tools'
44
import { getBaseClasses } from '../../../src/utils'
55
import { BaseLanguageModel } from 'langchain/base_language'
66
import { flatten } from 'lodash'
7+
import { additionalCallbacks } from '../../../src/handler'
78

89
class MRKLAgentLLM_Agents implements INode {
910
label: string
@@ -52,9 +53,12 @@ class MRKLAgentLLM_Agents implements INode {
5253
return executor
5354
}
5455

55-
async run(nodeData: INodeData, input: string): Promise<string> {
56+
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
5657
const executor = nodeData.instance as AgentExecutor
57-
const result = await executor.call({ input })
58+
59+
const callbacks = await additionalCallbacks(nodeData, options)
60+
61+
const result = await executor.call({ input }, [...callbacks])
5862

5963
return result?.output
6064
}

packages/components/nodes/agents/OpenAIFunctionAgent/OpenAIFunctionAgent.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getBaseClasses, mapChatHistory } from '../../../src/utils'
44
import { BaseLanguageModel } from 'langchain/base_language'
55
import { flatten } from 'lodash'
66
import { BaseChatMemory } from 'langchain/memory'
7-
import { ConsoleCallbackHandler, CustomChainHandler } from '../../../src/handler'
7+
import { ConsoleCallbackHandler, CustomChainHandler, additionalCallbacks } from '../../../src/handler'
88

99
class OpenAIFunctionAgent_Agents implements INode {
1010
label: string
@@ -86,13 +86,14 @@ class OpenAIFunctionAgent_Agents implements INode {
8686
}
8787

8888
const loggerHandler = new ConsoleCallbackHandler(options.logger)
89+
const callbacks = await additionalCallbacks(nodeData, options)
8990

9091
if (options.socketIO && options.socketIOClientId) {
9192
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
92-
const result = await executor.run(input, [loggerHandler, handler])
93+
const result = await executor.run(input, [loggerHandler, handler, ...callbacks])
9394
return result
9495
} else {
95-
const result = await executor.run(input, [loggerHandler])
96+
const result = await executor.run(input, [loggerHandler, ...callbacks])
9697
return result
9798
}
9899
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { INode, INodeParams } from '../../../src/Interface'
2+
3+
class LangFuse_Analytic implements INode {
4+
label: string
5+
name: string
6+
version: number
7+
description: string
8+
type: string
9+
icon: string
10+
category: string
11+
baseClasses: string[]
12+
inputs?: INodeParams[]
13+
credential: INodeParams
14+
15+
constructor() {
16+
this.label = 'LangFuse'
17+
this.name = 'langFuse'
18+
this.version = 1.0
19+
this.type = 'LangFuse'
20+
this.icon = 'langfuse.png'
21+
this.category = 'Analytic'
22+
this.baseClasses = [this.type]
23+
this.inputs = []
24+
this.credential = {
25+
label: 'Connect Credential',
26+
name: 'credential',
27+
type: 'credential',
28+
credentialNames: ['langfuseApi']
29+
}
30+
}
31+
}
32+
33+
module.exports = { nodeClass: LangFuse_Analytic }

0 commit comments

Comments
 (0)