Skip to content

Commit d71369c

Browse files
toi500HenryHengZJ
andauthored
Fix(FlowiseChatGoogleGenerativeAI): Prevent "parts must not be empty" API error in Seq Agents (#4292)
* Fix(FlowiseChatGoogleGenerativeAI): Prevent "parts must not be empty" API error in Seq Agents * Fix: Update pnpm-lock.yaml to resolve CI issues * convert role function and tool to function * remove comment --------- Co-authored-by: Henry <[email protected]>
1 parent d3510d1 commit d71369c

File tree

6 files changed

+84
-69
lines changed

6 files changed

+84
-69
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Flowise has 3 different modules in a single mono repository.
121121
Flowise support different environment variables to configure your instance. You can specify the following variables in the `.env` file inside `packages/server` folder. Read [more](https://docs.flowiseai.com/environment-variables)
122122

123123
| Variable | Description | Type | Default |
124-
|------------------------------------|----------------------------------------------------------------------------------|--------------------------------------------------|-------------------------------------|
124+
| ---------------------------------- | -------------------------------------------------------------------------------- | ------------------------------------------------ | ----------------------------------- |
125125
| PORT | The HTTP port Flowise runs on | Number | 3000 |
126126
| CORS_ORIGINS | The allowed origins for all cross-origin HTTP calls | String | |
127127
| IFRAME_ORIGINS | The allowed origins for iframe src embedding | String | |

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"pnpm": ">=9"
8484
},
8585
"resolutions": {
86-
"@google/generative-ai": "^0.22.0",
86+
"@google/generative-ai": "^0.24.0",
8787
"@grpc/grpc-js": "^1.10.10",
8888
"@langchain/core": "0.3.37",
8989
"@qdrant/openapi-typescript-fetch": "1.2.6",

packages/components/models.json

+12-4
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,16 @@
420420
"name": "chatGoogleGenerativeAI",
421421
"models": [
422422
{
423-
"label": "gemini-2.0-flash-001",
424-
"name": "gemini-2.0-flash-001"
423+
"label": "gemini-2.5-pro-preview-03-25",
424+
"name": "gemini-2.5-pro-preview-03-25"
425425
},
426426
{
427-
"label": "gemini-2.0-flash-lite-001",
428-
"name": "gemini-2.0-flash-lite-001"
427+
"label": "gemini-2.0-flash",
428+
"name": "gemini-2.0-flash"
429+
},
430+
{
431+
"label": "gemini-2.0-flash-lite",
432+
"name": "gemini-2.0-flash-lite"
429433
},
430434
{
431435
"label": "gemini-1.5-flash",
@@ -1336,6 +1340,10 @@
13361340
{
13371341
"label": "text-embedding-004",
13381342
"name": "text-embedding-004"
1343+
},
1344+
{
1345+
"label": "gemini-embedding-exp-03-07",
1346+
"name": "gemini-embedding-exp-03-07"
13391347
}
13401348
]
13411349
},

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

+25-19
Original file line numberDiff line numberDiff line change
@@ -415,24 +415,18 @@ function getMessageAuthor(message: BaseMessage) {
415415
}
416416

417417
function convertAuthorToRole(author: string) {
418-
switch (author) {
419-
/**
420-
* Note: Gemini currently is not supporting system messages
421-
* we will convert them to human messages and merge with following
422-
* */
418+
switch (author.toLowerCase()) {
423419
case 'ai':
424-
case 'model': // getMessageAuthor returns message.name. code ex.: return message.name ?? type;
420+
case 'assistant':
421+
case 'model':
425422
return 'model'
426-
case 'system':
427-
case 'human':
428-
return 'user'
429423
case 'function':
430424
case 'tool':
431425
return 'function'
426+
case 'system':
427+
case 'human':
432428
default:
433-
// Instead of throwing, we return model (Needed for Multi Agent)
434-
// throw new Error(`Unknown / unsupported author: ${author}`)
435-
return 'model'
429+
return 'user'
436430
}
437431
}
438432

@@ -520,17 +514,29 @@ function convertMessageContentToParts(message: BaseMessage, isMultimodalModel: b
520514

521515
function checkIfEmptyContentAndSameRole(contents: Content[]) {
522516
let prevRole = ''
523-
const removedContents: Content[] = []
517+
const validContents: Content[] = []
518+
524519
for (const content of contents) {
525-
const role = content.role
526-
if (content.parts.length && content.parts[0].text === '' && role === prevRole) {
527-
removedContents.push(content)
520+
// Skip only if completely empty
521+
if (!content.parts || !content.parts.length) {
522+
continue
523+
}
524+
525+
// Ensure role is always either 'user' or 'model'
526+
content.role = content.role === 'model' ? 'model' : 'user'
527+
528+
// Handle consecutive messages
529+
if (content.role === prevRole && validContents.length > 0) {
530+
// Merge with previous content if same role
531+
validContents[validContents.length - 1].parts.push(...content.parts)
532+
continue
528533
}
529534

530-
prevRole = role
535+
validContents.push(content)
536+
prevRole = content.role
531537
}
532538

533-
return contents.filter((content) => !removedContents.includes(content))
539+
return validContents
534540
}
535541

536542
function convertBaseMessagesToContent(messages: BaseMessage[], isMultimodalModel: boolean) {
@@ -568,7 +574,7 @@ function convertBaseMessagesToContent(messages: BaseMessage[], isMultimodalModel
568574
}
569575
}
570576
let actualRole = role
571-
if (actualRole === 'function') {
577+
if (actualRole === 'function' || actualRole === 'tool') {
572578
// GenerativeAI API will throw an error if the role is not "user" or "model."
573579
actualRole = 'user'
574580
}

packages/components/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@gomomento/sdk-core": "^1.51.1",
3737
"@google-ai/generativelanguage": "^2.5.0",
3838
"@google-cloud/storage": "^7.15.2",
39-
"@google/generative-ai": "^0.15.0",
39+
"@google/generative-ai": "^0.24.0",
4040
"@huggingface/inference": "^2.6.1",
4141
"@langchain/anthropic": "0.3.14",
4242
"@langchain/aws": "0.1.4",
@@ -45,7 +45,7 @@
4545
"@langchain/community": "^0.3.24",
4646
"@langchain/core": "0.3.37",
4747
"@langchain/exa": "^0.0.5",
48-
"@langchain/google-genai": "0.1.9",
48+
"@langchain/google-genai": "0.2.3",
4949
"@langchain/google-vertexai": "^0.2.0",
5050
"@langchain/groq": "0.1.2",
5151
"@langchain/langgraph": "^0.0.22",

0 commit comments

Comments
 (0)