Skip to content

Conversation

@hsubox76
Copy link
Contributor

Add thinking levels feature.

API proposal (internal): https://docs.google.com/document/d/16cdWurhdLDuNIDj0eJWNnL00any0tL_DjI-lAg7miP8/edit?tab=t.0

Added the param, plus an error if both thinkingLevel and thinkingBudget are set. This validation function may be used in the future to validate other common config issues.

Docs notes:

  • Copied text of documentation from Swift comments in API proposal doc (see above)
  • Some of the "removed" text in the md files is actually just removing them from the toc table at the top of the page, where they are unnecessary, and most of the text still remains in the entries below.

@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2025

🦋 Changeset detected

Latest commit: 87464b7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@firebase/ai Minor
firebase Minor

Not sure what this means? Click here to learn what changesets are.

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

@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 AI model configuration by introducing a thinkingLevel parameter, offering a simplified way to control the model's internal reasoning process. It ensures proper configuration through client-side validation and provides comprehensive documentation for the new feature.

Highlights

  • New thinkingLevel Parameter: Introduced a new thinkingLevel parameter within ThinkingConfig to allow users to specify a preset level for the model's 'thinking' process, with options like MINIMAL, LOW, MEDIUM, and HIGH.
  • Mutual Exclusivity Validation: Implemented client-side validation to prevent the simultaneous setting of both thinkingBudget and thinkingLevel in the GenerationConfig, throwing an AIErrorCode.UNSUPPORTED error if both are provided.
  • Documentation Updates: Updated API documentation and devsite markdown files to reflect the new ThinkingLevel type, its usage, and the updated ThinkingConfig interface, including notes on its interaction with thinkingBudget and model support.
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.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 12, 2025

Changeset File Check ✅

  • No modified packages are missing from the changeset file.
  • No changeset formatting errors detected.

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

This pull request introduces the thinkingLevel parameter to the thinkingConfig, providing users with presets to control the model's thinking process. The changes include updates to the ThinkingConfig interface, new type definitions for ThinkingLevel, and comprehensive documentation updates. A key addition is the client-side validation that prevents thinkingLevel and thinkingBudget from being set simultaneously, which is a great way to prevent invalid configurations. The associated test case for this validation is also well-implemented. Overall, the changes are solid. I have one minor suggestion to improve the readability of the validation logic.

Comment on lines 175 to 186
function validateGenerationConfig(generationConfig: GenerationConfig): void {
if (
// != allows for null and undefined. 0 is considered "set" by the model
generationConfig.thinkingConfig?.thinkingBudget != null &&
generationConfig.thinkingConfig.thinkingLevel
) {
throw new AIError(
AIErrorCode.UNSUPPORTED,
`Cannot set both thinkingBudget and thinkingLevel in a config.`
);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While the current logic is correct due to && short-circuiting, it's a bit subtle. Accessing generationConfig.thinkingConfig.thinkingLevel could be misinterpreted as unsafe if one overlooks the short-circuiting behavior. Refactoring to first check for thinkingConfig's existence improves readability and maintainability.

Suggested change
function validateGenerationConfig(generationConfig: GenerationConfig): void {
if (
// != allows for null and undefined. 0 is considered "set" by the model
generationConfig.thinkingConfig?.thinkingBudget != null &&
generationConfig.thinkingConfig.thinkingLevel
) {
throw new AIError(
AIErrorCode.UNSUPPORTED,
`Cannot set both thinkingBudget and thinkingLevel in a config.`
);
}
}
function validateGenerationConfig(generationConfig: GenerationConfig): void {
const { thinkingConfig } = generationConfig;
if (
thinkingConfig &&
// != allows for null and undefined. 0 is considered "set" by the model
thinkingConfig.thinkingBudget != null &&
thinkingConfig.thinkingLevel
) {
throw new AIError(
AIErrorCode.UNSUPPORTED,
`Cannot set both thinkingBudget and thinkingLevel in a config.`
);
}
}

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Dec 12, 2025

Size Report 1

Affected Products

  • @firebase/ai

    TypeBase (bc2b2cd)Merge (4d7a47b)Diff
    browser67.4 kB67.8 kB+406 B (+0.6%)
    main71.7 kB72.2 kB+483 B (+0.7%)
    module67.4 kB67.8 kB+406 B (+0.6%)
  • firebase

    TypeBase (bc2b2cd)Merge (4d7a47b)Diff
    firebase-ai.js52.8 kB53.1 kB+312 B (+0.6%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/gmZ043F2ec.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Dec 12, 2025

Size Analysis Report 1

Affected Products

  • @firebase/ai

    • GenerativeModel

      Size

      TypeBase (bc2b2cd)Merge (4d7a47b)Diff
      size26.1 kB26.3 kB+209 B (+0.8%)
      size-with-ext-deps43.9 kB44.1 kB+211 B (+0.5%)

      Dependency

      TypeBase (bc2b2cd)Merge (4d7a47b)Diff
      functions

      39 dependencies

      addHelpers
      aggregateResponses
      assignRoleToPartsAndValidateSendMessageRequest
      callCloudOrDevice
      chromeAdapterFactory
      countTokens
      countTokensOnCloud
      createEnhancedContentResponse
      decodeInstanceIdentifier
      factory
      formatBlockErrorMessage
      formatGenerateContentInput
      formatNewContent
      formatSystemInstruction
      generateContent
      generateContentOnCloud
      generateContentStream
      generateContentStreamOnCloud
      generateResponseSequence
      getClientHeaders
      getFunctionCalls
      getHeaders
      getInlineDataParts
      getResponsePromise
      getResponseStream
      getText
      hadBadFinishReason
      hasValidCandidates
      initApiSettings
      makeRequest
      mapCountTokensRequest
      mapGenerateContentCandidates
      mapGenerateContentRequest
      mapGenerateContentResponse
      mapPromptFeedback
      processGenerateContentResponse
      processStream
      registerAI
      validateChatHistory

      40 dependencies

      addHelpers
      aggregateResponses
      assignRoleToPartsAndValidateSendMessageRequest
      callCloudOrDevice
      chromeAdapterFactory
      countTokens
      countTokensOnCloud
      createEnhancedContentResponse
      decodeInstanceIdentifier
      factory
      formatBlockErrorMessage
      formatGenerateContentInput
      formatNewContent
      formatSystemInstruction
      generateContent
      generateContentOnCloud
      generateContentStream
      generateContentStreamOnCloud
      generateResponseSequence
      getClientHeaders
      getFunctionCalls
      getHeaders
      getInlineDataParts
      getResponsePromise
      getResponseStream
      getText
      hadBadFinishReason
      hasValidCandidates
      initApiSettings
      makeRequest
      mapCountTokensRequest
      mapGenerateContentCandidates
      mapGenerateContentRequest
      mapGenerateContentResponse
      mapPromptFeedback
      processGenerateContentResponse
      processStream
      registerAI
      validateChatHistory
      validateGenerationConfig

      + validateGenerationConfig

    • ThinkingLevel

      Size

      TypeBase (bc2b2cd)Merge (4d7a47b)Diff
      size?7.01 kB? (?)
      size-with-ext-deps?24.6 kB? (?)

      Dependency

      TypeBase (bc2b2cd)Merge (4d7a47b)Diff
      functions?

      chromeAdapterFactory
      decodeInstanceIdentifier
      factory
      registerAI

      ?
      classes?

      AIError
      AIService
      Backend
      ChromeAdapterImpl
      GoogleAIBackend
      VertexAIBackend

      ?
      variables?

      12 dependencies

      AIErrorCode
      AI_TYPE
      Availability
      BackendType
      DEFAULT_API_VERSION
      DEFAULT_LOCATION
      InferenceMode
      ThinkingLevel
      defaultExpectedInputs
      logger
      name
      version

      ?
      enums??

      External Dependency

      ModuleBase (bc2b2cd)Merge (4d7a47b)Diff
      @firebase/app?

      _registerComponent
      registerVersion

      ?
      @firebase/component?

      Component

      ?
      @firebase/logger?

      Logger

      ?
      @firebase/util?

      FirebaseError

      ?
    • getGenerativeModel

      Size

      TypeBase (bc2b2cd)Merge (4d7a47b)Diff
      size26.4 kB26.6 kB+209 B (+0.8%)
      size-with-ext-deps44.2 kB44.4 kB+211 B (+0.5%)

      Dependency

      TypeBase (bc2b2cd)Merge (4d7a47b)Diff
      functions

      40 dependencies

      addHelpers
      aggregateResponses
      assignRoleToPartsAndValidateSendMessageRequest
      callCloudOrDevice
      chromeAdapterFactory
      countTokens
      countTokensOnCloud
      createEnhancedContentResponse
      decodeInstanceIdentifier
      factory
      formatBlockErrorMessage
      formatGenerateContentInput
      formatNewContent
      formatSystemInstruction
      generateContent
      generateContentOnCloud
      generateContentStream
      generateContentStreamOnCloud
      generateResponseSequence
      getClientHeaders
      getFunctionCalls
      getGenerativeModel
      getHeaders
      getInlineDataParts
      getResponsePromise
      getResponseStream
      getText
      hadBadFinishReason
      hasValidCandidates
      initApiSettings
      makeRequest
      mapCountTokensRequest
      mapGenerateContentCandidates
      mapGenerateContentRequest
      mapGenerateContentResponse
      mapPromptFeedback
      processGenerateContentResponse
      processStream
      registerAI
      validateChatHistory

      41 dependencies

      addHelpers
      aggregateResponses
      assignRoleToPartsAndValidateSendMessageRequest
      callCloudOrDevice
      chromeAdapterFactory
      countTokens
      countTokensOnCloud
      createEnhancedContentResponse
      decodeInstanceIdentifier
      factory
      formatBlockErrorMessage
      formatGenerateContentInput
      formatNewContent
      formatSystemInstruction
      generateContent
      generateContentOnCloud
      generateContentStream
      generateContentStreamOnCloud
      generateResponseSequence
      getClientHeaders
      getFunctionCalls
      getGenerativeModel
      getHeaders
      getInlineDataParts
      getResponsePromise
      getResponseStream
      getText
      hadBadFinishReason
      hasValidCandidates
      initApiSettings
      makeRequest
      mapCountTokensRequest
      mapGenerateContentCandidates
      mapGenerateContentRequest
      mapGenerateContentResponse
      mapPromptFeedback
      processGenerateContentResponse
      processStream
      registerAI
      validateChatHistory
      validateGenerationConfig

      + validateGenerationConfig

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/9KGDGIu9Bx.html

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.

2 participants