Skip to content

Commit 58ae2e4

Browse files
feat(js): thinking mode options for Gemini models (#2851)
1 parent f2f7fe2 commit 58ae2e4

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

js/plugins/googleai/src/gemini.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import {
1818
EnhancedGenerateContentResponse,
1919
FileDataPart,
20-
FunctionCallingMode,
2120
FunctionCallPart,
21+
FunctionCallingMode,
2222
FunctionDeclaration,
2323
FunctionResponsePart,
2424
GenerateContentCandidate as GeminiCandidate,
@@ -37,27 +37,27 @@ import {
3737
ToolConfig,
3838
} from '@google/generative-ai';
3939
import {
40-
Genkit,
4140
GENKIT_CLIENT_HEADER,
41+
Genkit,
4242
GenkitError,
4343
JSONSchema,
4444
z,
4545
} from 'genkit';
4646
import {
4747
CandidateData,
4848
GenerationCommonConfigSchema,
49-
getBasicUsageStats,
5049
MediaPart,
5150
MessageData,
5251
ModelAction,
5352
ModelInfo,
5453
ModelMiddleware,
55-
modelRef,
5654
ModelReference,
5755
Part,
5856
ToolDefinitionSchema,
5957
ToolRequestPart,
6058
ToolResponsePart,
59+
getBasicUsageStats,
60+
modelRef,
6161
} from 'genkit/model';
6262
import {
6363
downloadRequestMedia,
@@ -132,6 +132,29 @@ export const GeminiConfigSchema = GenerationCommonConfigSchema.extend({
132132
"'gemini-2.0-flash-exp' model at present."
133133
)
134134
.optional(),
135+
thinkingConfig: z
136+
.object({
137+
includeThoughts: z
138+
.boolean()
139+
.describe(
140+
'Indicates whether to include thoughts in the response.' +
141+
'If true, thoughts are returned only when available.'
142+
)
143+
.optional(),
144+
thinkingBudget: z
145+
.number()
146+
.min(0)
147+
.max(24576)
148+
.describe(
149+
'The thinking budget parameter gives the model guidance on the ' +
150+
'number of thinking tokens it can use when generating a response. ' +
151+
'A greater number of tokens is typically associated with more detailed ' +
152+
'thinking, which is needed for solving more complex tasks. ' +
153+
'Setting the thinking budget to 0 disables thinking.'
154+
)
155+
.optional(),
156+
})
157+
.optional(),
135158
}).passthrough();
136159
export type GeminiConfig = z.infer<typeof GeminiConfigSchema>;
137160

js/plugins/vertexai/src/gemini.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,29 @@ export const GeminiConfigSchema = GenerationCommonConfigSchema.extend({
267267
'With NONE, the model is prohibited from making function calls.'
268268
)
269269
.optional(),
270+
thinkingConfig: z
271+
.object({
272+
includeThoughts: z
273+
.boolean()
274+
.describe(
275+
'Indicates whether to include thoughts in the response.' +
276+
'If true, thoughts are returned only when available.'
277+
)
278+
.optional(),
279+
thinkingBudget: z
280+
.number()
281+
.min(0)
282+
.max(24576)
283+
.describe(
284+
'The thinking budget parameter gives the model guidance on the ' +
285+
'number of thinking tokens it can use when generating a response. ' +
286+
'A greater number of tokens is typically associated with more detailed ' +
287+
'thinking, which is needed for solving more complex tasks. ' +
288+
'Setting the thinking budget to 0 disables thinking.'
289+
)
290+
.optional(),
291+
})
292+
.optional(),
270293
}).passthrough();
271294

272295
/**

0 commit comments

Comments
 (0)