Skip to content

Commit 8ebc4dc

Browse files
Feature/lang graph (#2319)
* add langgraph * datasource: initial commit * datasource: datasource details and chunks * datasource: Document Store Node * more changes * Document Store - Base functionality * Document Store Loader Component * Document Store Loader Component * before merging the modularity PR * after merging the modularity PR * preview mode * initial draft PR * fixes * minor updates and fixes * preview with loader and splitter * preview with credential * show stored chunks * preview update... * edit config * save, preview and other changes * save, preview and other changes * save, process and other changes * save, process and other changes * alpha1 - for internal testing * rerouting urls * bug fix on new leader create * pagination support for chunks * delete document store * Update pnpm-lock.yaml * doc store card view * Update store files to use updated storage functions, Document Store Table View and other changes * ui changes * add expanded chunk dialog, improve ui * change throw Error to InternalError * Bug Fixes and removal of subFolder, adding of view chunks for store * lint fixes * merge changes * DocumentStoreStatus component * ui changes for doc store * add remove metadata key field, add custom document loader * add chatflows used doc store chips * add types/interfaces to DocumentStore Services * document loader list dialog title bar color change * update interfaces * Whereused Chatflow Name and Added chunkNo to retain order of created chunks. * use typeorm order chunkNo, ui changes * update tabler icons react * cleanup agents * add pysandbox tool * add abort functionality, loading next agent * add empty view svg * update chatflow tool with chatId * rename to agentflows * update worker for prompt input values * update dashboard to agentflows, agentcanvas * fix marketplace use template * add agentflow templates * resolve merge conflict * update baseURL --------- Co-authored-by: vinodkiran <[email protected]> Co-authored-by: Vinod Paidimarry <[email protected]>
1 parent 95f1090 commit 8ebc4dc

File tree

92 files changed

+7215
-700
lines changed

Some content is hidden

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

92 files changed

+7215
-700
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { INodeParams, INodeCredential } from '../src/Interface'
2+
3+
class ChatflowApi implements INodeCredential {
4+
label: string
5+
name: string
6+
version: number
7+
inputs: INodeParams[]
8+
9+
constructor() {
10+
this.label = 'Chatflow API'
11+
this.name = 'chatflowApi'
12+
this.version = 1.0
13+
this.inputs = [
14+
{
15+
label: 'Chatflow Api Key',
16+
name: 'chatflowApiKey',
17+
type: 'password'
18+
}
19+
]
20+
}
21+
}
22+
23+
module.exports = { credClass: ChatflowApi }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* TODO: Implement codeInterpreter column to chat_message table
3+
import { INodeParams, INodeCredential } from '../src/Interface'
4+
5+
class E2BApi implements INodeCredential {
6+
label: string
7+
name: string
8+
version: number
9+
inputs: INodeParams[]
10+
11+
constructor() {
12+
this.label = 'E2B API'
13+
this.name = 'E2BApi'
14+
this.version = 1.0
15+
this.inputs = [
16+
{
17+
label: 'E2B Api Key',
18+
name: 'e2bApiKey',
19+
type: 'password'
20+
}
21+
]
22+
}
23+
}
24+
25+
module.exports = { credClass: E2BApi }
26+
*/

packages/components/nodes/agents/ToolAgent/ToolAgent.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ToolAgent_Agents implements INode {
5454
name: 'model',
5555
type: 'BaseChatModel',
5656
description:
57-
'Only compatible with models that are capable of function calling. ChatOpenAI, ChatMistral, ChatAnthropic, ChatVertexAI'
57+
'Only compatible with models that are capable of function calling: ChatOpenAI, ChatMistral, ChatAnthropic, ChatGoogleGenerativeAI, ChatVertexAI, GroqChat'
5858
},
5959
{
6060
label: 'System Message',

packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/FlowiseChatGoogleGenerativeAI.ts

+27-3
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ class LangchainChatGoogleGenerativeAI extends BaseChatModel implements GoogleGen
206206
options: this['ParsedCallOptions'],
207207
runManager?: CallbackManagerForLLMRun
208208
): Promise<ChatResult> {
209-
const prompt = convertBaseMessagesToContent(messages, this._isMultimodalModel)
209+
let prompt = convertBaseMessagesToContent(messages, this._isMultimodalModel)
210+
prompt = checkIfEmptyContentAndSameRole(prompt)
210211

211212
// Handle streaming
212213
if (this.streaming) {
@@ -235,7 +236,9 @@ class LangchainChatGoogleGenerativeAI extends BaseChatModel implements GoogleGen
235236
options: this['ParsedCallOptions'],
236237
runManager?: CallbackManagerForLLMRun
237238
): AsyncGenerator<ChatGenerationChunk> {
238-
const prompt = convertBaseMessagesToContent(messages, this._isMultimodalModel)
239+
let prompt = convertBaseMessagesToContent(messages, this._isMultimodalModel)
240+
prompt = checkIfEmptyContentAndSameRole(prompt)
241+
239242
//@ts-ignore
240243
if (options.tools !== undefined && options.tools.length > 0) {
241244
const result = await this._generateNonStreaming(prompt, options, runManager)
@@ -333,7 +336,9 @@ function convertAuthorToRole(author: string) {
333336
case 'tool':
334337
return 'function'
335338
default:
336-
throw new Error(`Unknown / unsupported author: ${author}`)
339+
// Instead of throwing, we return model
340+
// throw new Error(`Unknown / unsupported author: ${author}`)
341+
return 'model'
337342
}
338343
}
339344

@@ -396,6 +401,25 @@ function convertMessageContentToParts(content: MessageContent, isMultimodalModel
396401
})
397402
}
398403

404+
/*
405+
* This is a dedicated logic for Multi Agent Supervisor to handle the case where the content is empty, and the role is the same
406+
*/
407+
408+
function checkIfEmptyContentAndSameRole(contents: Content[]) {
409+
let prevRole = ''
410+
const removedContents: Content[] = []
411+
for (const content of contents) {
412+
const role = content.role
413+
if (content.parts.length && content.parts[0].text === '' && role === prevRole) {
414+
removedContents.push(content)
415+
}
416+
417+
prevRole = role
418+
}
419+
420+
return contents.filter((content) => !removedContents.includes(content))
421+
}
422+
399423
function convertBaseMessagesToContent(messages: BaseMessage[], isMultimodalModel: boolean) {
400424
return messages.reduce<{
401425
content: Content[]

packages/components/nodes/documentloaders/Csv/Csv.ts

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { omit } from 'lodash'
2-
import { ICommonObject, IDocument, INode, INodeData, INodeParams } from '../../../src/Interface'
2+
import { ICommonObject, IDocument, INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
33
import { TextSplitter } from 'langchain/text_splitter'
44
import { CSVLoader } from 'langchain/document_loaders/fs/csv'
5-
import { getFileFromStorage } from '../../../src'
5+
import { getFileFromStorage, handleEscapeCharacters } from '../../../src'
66

77
class Csv_DocumentLoaders implements INode {
88
label: string
@@ -14,11 +14,12 @@ class Csv_DocumentLoaders implements INode {
1414
category: string
1515
baseClasses: string[]
1616
inputs: INodeParams[]
17+
outputs: INodeOutputsValue[]
1718

1819
constructor() {
1920
this.label = 'Csv File'
2021
this.name = 'csvFile'
21-
this.version = 1.0
22+
this.version = 2.0
2223
this.type = 'Document'
2324
this.icon = 'csv.svg'
2425
this.category = 'Document Loaders'
@@ -65,13 +66,28 @@ class Csv_DocumentLoaders implements INode {
6566
additionalParams: true
6667
}
6768
]
69+
this.outputs = [
70+
{
71+
label: 'Document',
72+
name: 'document',
73+
description: 'Array of document objects containing metadata and pageContent',
74+
baseClasses: [...this.baseClasses, 'json']
75+
},
76+
{
77+
label: 'Text',
78+
name: 'text',
79+
description: 'Concatenated string from pageContent of documents',
80+
baseClasses: ['string', 'json']
81+
}
82+
]
6883
}
6984

7085
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
7186
const textSplitter = nodeData.inputs?.textSplitter as TextSplitter
7287
const csvFileBase64 = nodeData.inputs?.csvFile as string
7388
const columnName = nodeData.inputs?.columnName as string
7489
const metadata = nodeData.inputs?.metadata
90+
const output = nodeData.outputs?.output as string
7591
const _omitMetadataKeys = nodeData.inputs?.omitMetadataKeys as string
7692

7793
let omitMetadataKeys: string[] = []
@@ -156,7 +172,15 @@ class Csv_DocumentLoaders implements INode {
156172
}))
157173
}
158174

159-
return docs
175+
if (output === 'document') {
176+
return docs
177+
} else {
178+
let finaltext = ''
179+
for (const doc of docs) {
180+
finaltext += `${doc.pageContent}\n`
181+
}
182+
return handleEscapeCharacters(finaltext, false)
183+
}
160184
}
161185
}
162186

0 commit comments

Comments
 (0)