From 8c2cdffab8a77e3c22d78d770db6d612136d7a30 Mon Sep 17 00:00:00 2001 From: Narendranath Gogineni Date: Wed, 23 Apr 2025 19:52:25 +0530 Subject: [PATCH 1/3] add support for gemini thinking input params --- src/providers/google-vertex-ai/chatComplete.ts | 6 ++++++ .../google-vertex-ai/transformGenerationConfig.ts | 7 +++++++ src/types/requestBody.ts | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/src/providers/google-vertex-ai/chatComplete.ts b/src/providers/google-vertex-ai/chatComplete.ts index c7ed0fefd..5503e39f3 100644 --- a/src/providers/google-vertex-ai/chatComplete.ts +++ b/src/providers/google-vertex-ai/chatComplete.ts @@ -337,6 +337,10 @@ export const VertexGoogleChatCompleteConfig: ProviderConfig = { labels: { param: 'labels', }, + thinking: { + param: 'generationConfig', + transform: (params: Params) => transformGenerationConfig(params), + }, }; interface AnthorpicTextContentItem { @@ -425,6 +429,8 @@ export const GoogleChatCompleteResponseTransform: ( ); } + console.log(JSON.stringify(response, null, 2)); + if ('candidates' in response) { const { promptTokenCount = 0, diff --git a/src/providers/google-vertex-ai/transformGenerationConfig.ts b/src/providers/google-vertex-ai/transformGenerationConfig.ts index cd1aa231c..7d15142a1 100644 --- a/src/providers/google-vertex-ai/transformGenerationConfig.ts +++ b/src/providers/google-vertex-ai/transformGenerationConfig.ts @@ -50,5 +50,12 @@ export function transformGenerationConfig(params: Params) { generationConfig['responseSchema'] = schema; } + if (params?.thinking) { + const thinkingConfig: Record = {}; + thinkingConfig['include_thoughts'] = true; + thinkingConfig['thinking_budget'] = params.thinking.budget_tokens; + generationConfig['thinking_config'] = thinkingConfig; + } + return generationConfig; } diff --git a/src/types/requestBody.ts b/src/types/requestBody.ts index 0e1f45467..5616bc48f 100644 --- a/src/types/requestBody.ts +++ b/src/types/requestBody.ts @@ -404,6 +404,10 @@ export interface Params { // Anthropic specific anthropic_beta?: string; anthropic_version?: string; + thinking?: { + type?: string; + budget_tokens: number; + }; } interface Examples { From c8840ca111864093b70bb1a5c817441554b80c69 Mon Sep 17 00:00:00 2001 From: Narendranath Gogineni Date: Wed, 23 Apr 2025 20:15:38 +0530 Subject: [PATCH 2/3] remove debug log --- src/providers/google-vertex-ai/chatComplete.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/providers/google-vertex-ai/chatComplete.ts b/src/providers/google-vertex-ai/chatComplete.ts index 5503e39f3..2b412a497 100644 --- a/src/providers/google-vertex-ai/chatComplete.ts +++ b/src/providers/google-vertex-ai/chatComplete.ts @@ -429,8 +429,6 @@ export const GoogleChatCompleteResponseTransform: ( ); } - console.log(JSON.stringify(response, null, 2)); - if ('candidates' in response) { const { promptTokenCount = 0, From 668fd620b869fbfbb48afe8b640f25f0c42f4637 Mon Sep 17 00:00:00 2001 From: Narendranath Gogineni Date: Thu, 24 Apr 2025 14:54:25 +0530 Subject: [PATCH 3/3] add gemini thinking support google provider as well --- src/providers/google/chatComplete.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/providers/google/chatComplete.ts b/src/providers/google/chatComplete.ts index 608305e86..1e2b67f8b 100644 --- a/src/providers/google/chatComplete.ts +++ b/src/providers/google/chatComplete.ts @@ -71,6 +71,12 @@ const transformGenerationConfig = (params: Params) => { } generationConfig['responseSchema'] = schema; } + if (params?.thinking) { + const thinkingConfig: Record = {}; + thinkingConfig['include_thoughts'] = true; + thinkingConfig['thinking_budget'] = params.thinking.budget_tokens; + generationConfig['thinking_config'] = thinkingConfig; + } return generationConfig; }; @@ -405,6 +411,10 @@ export const GoogleChatCompleteConfig: ProviderConfig = { } }, }, + thinking: { + param: 'generationConfig', + transform: (params: Params) => transformGenerationConfig(params), + }, }; export interface GoogleErrorResponse {