Skip to content

Comments

fix(ai): Add a warning when setting top-level params in hybrid mode#9577

Open
hsubox76 wants to merge 4 commits intomainfrom
ch-hybrid-config
Open

fix(ai): Add a warning when setting top-level params in hybrid mode#9577
hsubox76 wants to merge 4 commits intomainfrom
ch-hybrid-config

Conversation

@hsubox76
Copy link
Contributor

When using hybrid mode, top level params will be ignored (see comments in code)

const model = getGenerativeModel(ai, {
  mode: InferenceMode.PREFER_ON_DEVICE,
  // this will be ignored
  generationConfig: {},
  // this will be used (when doing device inference)
  onDeviceParams: {
    createOptions: {
      expectedInputs: [{ type: "image" }],
    },
  },
  // this will be used (when doing cloud inference)
  inCloudParams: {
    model: "gemini-2.5-flash-lite",
    generationConfig: {
      maxOutputTokens: 3,
    },
  },
});

Adding a warning so developers are aware and will not be confused why those settings are doing nothing.

@changeset-bot
Copy link

changeset-bot bot commented Feb 19, 2026

⚠️ No Changeset found

Latest commit: 64de960

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

Vertex AI Mock Responses Check ⚠️

A newer major version of the mock responses for Vertex AI unit tests is available. update_vertexai_responses.sh should be updated to clone the latest version of the responses: v16.2

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hsubox76, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the developer experience for users of the AI SDK's hybrid inference mode by introducing a warning system. It notifies developers when they attempt to configure top-level parameters, such as generationConfig, which are ignored in hybrid mode in favor of onDeviceParams and inCloudParams. This change aims to prevent confusion and ensure developers are aware of how their model configurations are being applied, ultimately improving clarity and reducing potential debugging efforts.

Highlights

  • Warning for Top-Level Parameters: Implemented a warning mechanism in getGenerativeModel to alert developers when top-level parameters are set in hybrid inference mode, as these parameters are ignored.
  • Improved Developer Experience: Enhanced developer experience by preventing potential confusion and explicitly notifying users that generationConfig and similar top-level settings are not applied when mode is set to a hybrid inference option.
  • Test Coverage: Added a new test case to api.test.ts to verify that the warning is correctly triggered when top-level parameters are provided in hybrid mode.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • packages/ai/src/api.test.ts
    • Imported InferenceMode, stub, logger, and sinonChai for testing purposes.
    • Configured chai to use sinonChai for enhanced stub assertions.
    • Added a new test to confirm that getGenerativeModel emits a warning when top-level parameters are passed in hybrid inference mode.
  • packages/ai/src/api.ts
    • Imported the logger utility for emitting warnings.
    • Modified getGenerativeModel to detect and warn about top-level parameters (excluding mode, onDeviceParams, inCloudParams) when hybrid inference mode is active, as these parameters are not utilized.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a helpful warning for developers using hybrid mode when they accidentally set top-level parameters that are ignored. The implementation is functional, but there are opportunities to improve the robustness of the tests and the efficiency of the parameter check. Specifically, the test stub for the logger should be restored to avoid side effects, and the parameter iteration should use Object.keys() to avoid potential issues with inherited properties.

Comment on lines 136 to 152
const hybridParamKeys: Array<keyof HybridParams> = [
'mode',
'onDeviceParams',
'inCloudParams'
];
for (const param in modelParams) {
if (!hybridParamKeys.includes(param as keyof HybridParams)) {
logger.warn(
`When a hybrid inference mode is specified (mode is currently set` +
` to ${hybridParams.mode}), "${param}" cannot be ` +
`configured at the top level. Configuration for in-cloud and ` +
`on-device must be done separately in inCloudParams and onDeviceParams. ` +
`Configuration values set outside of inCloudParams and onDeviceParams will` +
` be ignored.`
);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using for...in to iterate over object properties is generally discouraged as it includes inherited enumerable properties from the prototype chain. Additionally, the hybridParamKeys array is recreated on every function call. Consider using Object.keys() for safer iteration and defining the allowed keys more efficiently.

Suggested change
const hybridParamKeys: Array<keyof HybridParams> = [
'mode',
'onDeviceParams',
'inCloudParams'
];
for (const param in modelParams) {
if (!hybridParamKeys.includes(param as keyof HybridParams)) {
logger.warn(
`When a hybrid inference mode is specified (mode is currently set` +
` to ${hybridParams.mode}), "${param}" cannot be ` +
`configured at the top level. Configuration for in-cloud and ` +
`on-device must be done separately in inCloudParams and onDeviceParams. ` +
`Configuration values set outside of inCloudParams and onDeviceParams will` +
` be ignored.`
);
}
}
const hybridParamKeys: Array<keyof HybridParams> = [
'mode',
'onDeviceParams',
'inCloudParams'
];
for (const param of Object.keys(modelParams)) {
if (!hybridParamKeys.includes(param as keyof HybridParams)) {
logger.warn(
`When a hybrid inference mode is specified (mode is currently set` +
` to ${hybridParams.mode}), "${param}" cannot be ` +
`configured at the top level. Configuration for in-cloud and ` +
`on-device must be done separately in inCloudParams and onDeviceParams. ` +
`Configuration values set outside of inCloudParams and onDeviceParams will` +
` be ignored.`
);
}
}

@hsubox76 hsubox76 marked this pull request as ready for review February 20, 2026 18:20
@hsubox76 hsubox76 requested a review from a team as a code owner February 20, 2026 18:20
@hsubox76 hsubox76 requested a review from DellaBitta February 20, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant