Skip to content

Commit 68fef87

Browse files
fix(core): propagate BeforeModel hook model override end-to-end (#24784)
Signed-off-by: krishdef7 <gargkrish06@gmail.com> Co-authored-by: Sandy Tao <sandytao520@icloud.com>
1 parent e432f7c commit 68fef87

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/core/src/core/geminiChat.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,21 @@ export class GeminiChat {
597597
);
598598
}
599599

600+
if (beforeModelResult.modifiedModel) {
601+
modelToUse = resolveModel(
602+
beforeModelResult.modifiedModel,
603+
useGemini3_1,
604+
useGemini3_1FlashLite,
605+
false,
606+
hasAccessToPreview,
607+
this.context.config,
608+
);
609+
lastModelToUse = modelToUse;
610+
// Re-evaluate contentsToUse based on the new model's feature support
611+
contentsToUse = supportsModernFeatures(modelToUse)
612+
? [...contentsForPreviewModel]
613+
: [...requestContents];
614+
}
600615
if (beforeModelResult.modifiedConfig) {
601616
Object.assign(config, beforeModelResult.modifiedConfig);
602617
}

packages/core/src/hooks/hookSystem.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export interface BeforeModelHookResult {
4848
reason?: string;
4949
/** Synthetic response to return instead of calling the model (if blocked) */
5050
syntheticResponse?: GenerateContentResponse;
51+
/** Modified model override (if not blocked) */
52+
modifiedModel?: string;
5153
/** Modified config (if not blocked) */
5254
modifiedConfig?: GenerateContentConfig;
5355
/** Modified contents (if not blocked) */
@@ -292,6 +294,7 @@ export class HookSystem {
292294
beforeModelOutput.applyLLMRequestModifications(llmRequest);
293295
return {
294296
blocked: false,
297+
modifiedModel: modifiedRequest?.model,
295298
modifiedConfig: modifiedRequest?.config,
296299
modifiedContents: modifiedRequest?.contents,
297300
};

0 commit comments

Comments
 (0)