mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 11:22:15 +00:00
feat: Support thinking settings for Gemini models (#19591)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { SafetySetting } from '@google/generative-ai';
|
||||
import { ProjectsClient } from '@google-cloud/resource-manager';
|
||||
import { ChatVertexAI } from '@langchain/google-vertexai';
|
||||
import type { GoogleAISafetySetting } from '@langchain/google-common';
|
||||
import { ChatVertexAI, type ChatVertexAIInput } from '@langchain/google-vertexai';
|
||||
import { formatPrivateKey } from 'n8n-nodes-base/dist/utils/utilities';
|
||||
import {
|
||||
NodeConnectionTypes,
|
||||
@@ -11,12 +11,13 @@ import {
|
||||
type ILoadOptionsFunctions,
|
||||
type JsonObject,
|
||||
NodeOperationError,
|
||||
validateNodeParameters,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { getConnectionHintNoticeField } from '@utils/sharedFields';
|
||||
|
||||
import { makeErrorFromStatus } from './error-handling';
|
||||
import { additionalOptions } from '../gemini-common/additional-options';
|
||||
import { getAdditionalOptions } from '../gemini-common/additional-options';
|
||||
import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler';
|
||||
import { N8nLlmTracing } from '../N8nLlmTracing';
|
||||
|
||||
@@ -90,7 +91,7 @@ export class LmChatGoogleVertex implements INodeType {
|
||||
'The model which will generate the completion. <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models">Learn more</a>.',
|
||||
default: 'gemini-2.5-flash',
|
||||
},
|
||||
additionalOptions,
|
||||
getAdditionalOptions({ supportsThinkingBudget: true }),
|
||||
],
|
||||
};
|
||||
|
||||
@@ -143,21 +144,29 @@ export class LmChatGoogleVertex implements INodeType {
|
||||
temperature: 0.4,
|
||||
topK: 40,
|
||||
topP: 0.9,
|
||||
}) as {
|
||||
maxOutputTokens: number;
|
||||
temperature: number;
|
||||
topK: number;
|
||||
topP: number;
|
||||
};
|
||||
});
|
||||
|
||||
// Validate options parameter
|
||||
validateNodeParameters(
|
||||
options,
|
||||
{
|
||||
maxOutputTokens: { type: 'number', required: false },
|
||||
temperature: { type: 'number', required: false },
|
||||
topK: { type: 'number', required: false },
|
||||
topP: { type: 'number', required: false },
|
||||
thinkingBudget: { type: 'number', required: false },
|
||||
},
|
||||
this.getNode(),
|
||||
);
|
||||
|
||||
const safetySettings = this.getNodeParameter(
|
||||
'options.safetySettings.values',
|
||||
itemIndex,
|
||||
null,
|
||||
) as SafetySetting[];
|
||||
) as GoogleAISafetySetting[];
|
||||
|
||||
try {
|
||||
const model = new ChatVertexAI({
|
||||
const modelConfig: ChatVertexAIInput = {
|
||||
authOptions: {
|
||||
projectId,
|
||||
credentials: {
|
||||
@@ -186,7 +195,14 @@ export class LmChatGoogleVertex implements INodeType {
|
||||
|
||||
throw error;
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
// Add thinkingBudget if specified
|
||||
if (options.thinkingBudget !== undefined) {
|
||||
modelConfig.thinkingBudget = options.thinkingBudget;
|
||||
}
|
||||
|
||||
const model = new ChatVertexAI(modelConfig);
|
||||
|
||||
return {
|
||||
response: model,
|
||||
|
||||
Reference in New Issue
Block a user