Skip to content

feat(components): add extra_body support to OpenAI-compatible chat models#6250

Open
manaskumar3003 wants to merge 2 commits intoFlowiseAI:mainfrom
manaskumar3003:feature/openai-extra-body-support
Open

feat(components): add extra_body support to OpenAI-compatible chat models#6250
manaskumar3003 wants to merge 2 commits intoFlowiseAI:mainfrom
manaskumar3003:feature/openai-extra-body-support

Conversation

@manaskumar3003
Copy link
Copy Markdown

feat(components): add extra_body support to OpenAI-compatible chat model nodes

Adds an "Additional Body Params (JSON)" input to all OpenAI-compatible
chat model nodes. The JSON is merged into LangChain's modelKwargs, which
is spread into the final request body sent to the provider — matching
the semantics of the OpenAI SDK's extra_body parameter.

Enables use cases such as vLLM-served Qwen3 models where reasoning
behavior is controlled via non-standard fields, e.g.:

{ "chat_template_kwargs": { "enable_thinking": false } }
Affected nodes: ChatOpenAI, ChatOpenAICustom, ChatLocalAI,
AzureChatOpenAI, ChatOpenRouter, ChatCerebras, ChatCometAPI,
ChatNvdiaNIM, ChatSambanova, ChatLitellm, ChatFireworks.

The field is optional and additive , existing flows are unaffected.
Invalid JSON throws a clear error at node init.

…del nodes

Adds an "Additional Body Params (JSON)" input to all OpenAI-compatible
chat model nodes. The JSON is merged into LangChain's modelKwargs, which
is spread into the final request body sent to the provider — matching
the semantics of the OpenAI SDK's extra_body parameter.

Enables use cases such as vLLM-served Qwen3 models where reasoning
behavior is controlled via non-standard fields, e.g.:
  { "chat_template_kwargs": { "enable_thinking": false } }

Affected nodes: ChatOpenAI, ChatOpenAICustom, ChatLocalAI,
AzureChatOpenAI, ChatOpenRouter, ChatCerebras, ChatCometAPI,
ChatNvdiaNIM, ChatSambanova, ChatLitellm, ChatFireworks.

The field is optional and additive — existing flows are unaffected.
Invalid JSON throws a clear error at node init.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an "Additional Body Params" (extraBody) input field to various chat model components, allowing users to merge custom JSON fields into the API request body. This feature is implemented across multiple nodes including AzureChatOpenAI, ChatOpenAI, and several others. The feedback provided suggests a minor code simplification for merging these additional parameters into the model configuration, as spreading null or undefined values within an object literal is natively safe and does not require a null-coalescing fallback.

if (extraBody) {
try {
const parsedExtraBody = typeof extraBody === 'object' ? extraBody : JSON.parse(extraBody)
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the general rules, spreading null or undefined within an object literal is safe and does not require a ?? {} fallback. You can simplify this line.

Suggested change
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
obj.modelKwargs = { ...obj.modelKwargs, ...parsedExtraBody }
References
  1. Spreading null or undefined within an object literal is safe and does not require a ?? {} fallback, as it evaluates to an empty object.

if (extraBody) {
try {
const parsedExtraBody = typeof extraBody === 'object' ? extraBody : JSON.parse(extraBody)
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the general rules, spreading null or undefined within an object literal is safe and does not require a ?? {} fallback. You can simplify this line.

Suggested change
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
obj.modelKwargs = { ...obj.modelKwargs, ...parsedExtraBody }
References
  1. Spreading null or undefined within an object literal is safe and does not require a ?? {} fallback, as it evaluates to an empty object.

if (extraBody) {
try {
const parsedExtraBody = typeof extraBody === 'object' ? extraBody : JSON.parse(extraBody)
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the general rules, spreading null or undefined within an object literal is safe and does not require a ?? {} fallback. You can simplify this line.

Suggested change
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
obj.modelKwargs = { ...obj.modelKwargs, ...parsedExtraBody }
References
  1. Spreading null or undefined within an object literal is safe and does not require a ?? {} fallback, as it evaluates to an empty object.

if (extraBody) {
try {
const parsedExtraBody = typeof extraBody === 'object' ? extraBody : JSON.parse(extraBody)
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the general rules, spreading null or undefined within an object literal is safe and does not require a ?? {} fallback. You can simplify this line.

Suggested change
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
obj.modelKwargs = { ...obj.modelKwargs, ...parsedExtraBody }
References
  1. Spreading null or undefined within an object literal is safe and does not require a ?? {} fallback, as it evaluates to an empty object.

if (extraBody) {
try {
const parsedExtraBody = typeof extraBody === 'object' ? extraBody : JSON.parse(extraBody)
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the general rules, spreading null or undefined within an object literal is safe and does not require a ?? {} fallback. You can simplify this line.

Suggested change
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
obj.modelKwargs = { ...obj.modelKwargs, ...parsedExtraBody }
References
  1. Spreading null or undefined within an object literal is safe and does not require a ?? {} fallback, as it evaluates to an empty object.

if (extraBody) {
try {
const parsedExtraBody = typeof extraBody === 'object' ? extraBody : JSON.parse(extraBody)
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the general rules, spreading null or undefined within an object literal is safe and does not require a ?? {} fallback. You can simplify this line.

Suggested change
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
obj.modelKwargs = { ...obj.modelKwargs, ...parsedExtraBody }
References
  1. Spreading null or undefined within an object literal is safe and does not require a ?? {} fallback, as it evaluates to an empty object.

if (extraBody) {
try {
const parsedExtraBody = typeof extraBody === 'object' ? extraBody : JSON.parse(extraBody)
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the general rules, spreading null or undefined within an object literal is safe and does not require a ?? {} fallback. You can simplify this line.

Suggested change
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
obj.modelKwargs = { ...obj.modelKwargs, ...parsedExtraBody }
References
  1. Spreading null or undefined within an object literal is safe and does not require a ?? {} fallback, as it evaluates to an empty object.

if (extraBody) {
try {
const parsedExtraBody = typeof extraBody === 'object' ? extraBody : JSON.parse(extraBody)
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the general rules, spreading null or undefined within an object literal is safe and does not require a ?? {} fallback. You can simplify this line.

Suggested change
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
obj.modelKwargs = { ...obj.modelKwargs, ...parsedExtraBody }
References
  1. Spreading null or undefined within an object literal is safe and does not require a ?? {} fallback, as it evaluates to an empty object.

if (extraBody) {
try {
const parsedExtraBody = typeof extraBody === 'object' ? extraBody : JSON.parse(extraBody)
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the general rules, spreading null or undefined within an object literal is safe and does not require a ?? {} fallback. You can simplify this line.

Suggested change
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
obj.modelKwargs = { ...obj.modelKwargs, ...parsedExtraBody }
References
  1. Spreading null or undefined within an object literal is safe and does not require a ?? {} fallback, as it evaluates to an empty object.

if (extraBody) {
try {
const parsedExtraBody = typeof extraBody === 'object' ? extraBody : JSON.parse(extraBody)
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the general rules, spreading null or undefined within an object literal is safe and does not require a ?? {} fallback. You can simplify this line.

Suggested change
obj.modelKwargs = { ...(obj.modelKwargs ?? {}), ...parsedExtraBody }
obj.modelKwargs = { ...obj.modelKwargs, ...parsedExtraBody }
References
  1. Spreading null or undefined within an object literal is safe and does not require a ?? {} fallback, as it evaluates to an empty object.

…delKwargs

Spreading null/undefined inside an object literal is a no-op per spec, so
`{ ...(obj.modelKwargs ?? {}), ...parsedExtraBody }` simplifies to
`{ ...obj.modelKwargs, ...parsedExtraBody }`.

Addresses review feedback from gemini-code-assist.
@nehaaprasad
Copy link
Copy Markdown
Contributor

AI Code Trust — ship readiness

Score: 100 · Verdict: SAFE · Model: deterministic-v1

No blocking issues detected by automated checks.

Top issues:

  • maintainability (low) — Very long line reduces readability. packages/components/nodes/chatmodels/ChatLocalAI/ChatLocalAI.ts:99
  • maintainability (low) — Very long line reduces readability. packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts:217
  • maintainability (low) — Very long line reduces readability. packages/components/nodes/chatmodels/ChatOpenAICustom/ChatOpenAICustom.ts:125

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants