Skip to content

Vertex thinking changes to disable thinking mode for 2.5 models #1090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/providers/google-vertex-ai/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ export const GoogleChatCompleteResponseTransform: (
promptTokenCount = 0,
candidatesTokenCount = 0,
totalTokenCount = 0,
thoughtsTokenCount = 0,
} = response.usageMetadata;

return {
Expand Down Expand Up @@ -499,6 +500,9 @@ export const GoogleChatCompleteResponseTransform: (
prompt_tokens: promptTokenCount,
completion_tokens: candidatesTokenCount,
total_tokens: totalTokenCount,
completion_tokens_details: {
reasoning_tokens: thoughtsTokenCount,
},
},
};
}
Expand Down Expand Up @@ -589,6 +593,9 @@ export const GoogleChatCompleteStreamChunkTransform: (
prompt_tokens: parsedChunk.usageMetadata.promptTokenCount,
completion_tokens: parsedChunk.usageMetadata.candidatesTokenCount,
total_tokens: parsedChunk.usageMetadata.totalTokenCount,
completion_tokens_details: {
reasoning_tokens: parsedChunk.usageMetadata.thoughtsTokenCount ?? 0,
},
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/providers/google-vertex-ai/transformGenerationConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export function transformGenerationConfig(params: Params) {

if (params?.thinking) {
const thinkingConfig: Record<string, any> = {};
thinkingConfig['include_thoughts'] = true;
thinkingConfig['include_thoughts'] =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Based on this vertex doc: https://cloud.google.com/vertex-ai/generative-ai/docs/thinking#budget

In order to disable thinking, you need to set thinking budget tokens to 0. I do not see any parameter named include_thoughts available.

Copy link
Collaborator Author

@narengogi narengogi May 14, 2025

Choose a reason for hiding this comment

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

I found this parameter looking inside the sdk, I'll find it and link it here

params.thinking.type && params.thinking.type === 'enabled' ? true : false;
thinkingConfig['thinking_budget'] = params.thinking.budget_tokens;
generationConfig['thinking_config'] = thinkingConfig;
}
Expand Down
1 change: 1 addition & 0 deletions src/providers/google-vertex-ai/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface GoogleGenerateContentResponse {
promptTokenCount: number;
candidatesTokenCount: number;
totalTokenCount: number;
thoughtsTokenCount?: number;
};
}

Expand Down
10 changes: 9 additions & 1 deletion src/providers/google/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ const transformGenerationConfig = (params: Params) => {
}
if (params?.thinking) {
const thinkingConfig: Record<string, any> = {};
thinkingConfig['include_thoughts'] = true;
thinkingConfig['include_thoughts'] =
params.thinking.type && params.thinking.type === 'enabled' ? true : false;
thinkingConfig['thinking_budget'] = params.thinking.budget_tokens;
generationConfig['thinking_config'] = thinkingConfig;
}
Expand Down Expand Up @@ -479,6 +480,7 @@ interface GoogleGenerateContentResponse {
promptTokenCount: number;
candidatesTokenCount: number;
totalTokenCount: number;
thoughtsTokenCount: number;
};
}

Expand Down Expand Up @@ -579,6 +581,9 @@ export const GoogleChatCompleteResponseTransform: (
prompt_tokens: response.usageMetadata.promptTokenCount,
completion_tokens: response.usageMetadata.candidatesTokenCount,
total_tokens: response.usageMetadata.totalTokenCount,
completion_tokens_details: {
reasoning_tokens: response.usageMetadata.thoughtsTokenCount ?? 0,
},
},
};
}
Expand Down Expand Up @@ -624,6 +629,9 @@ export const GoogleChatCompleteStreamChunkTransform: (
prompt_tokens: parsedChunk.usageMetadata.promptTokenCount,
completion_tokens: parsedChunk.usageMetadata.candidatesTokenCount,
total_tokens: parsedChunk.usageMetadata.totalTokenCount,
completion_tokens_details: {
reasoning_tokens: parsedChunk.usageMetadata.thoughtsTokenCount ?? 0,
},
};
}

Expand Down