-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[Firebase AI] Add support for configuring a thinking budget #14909
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7cc81af
[Firebase AI] Add support for configuring a thinking budget
andrewheard cd2a256
Merge branch 'main' into ah/firebaseai-thinkingbudget
andrewheard 5290bc7
Add `thinkingConfig` to `CodingKeys`
andrewheard b8e0573
Merge branch 'main' into ah/firebaseai-thinkingbudget
andrewheard 8777178
Add thinking budget integration tests
andrewheard 13b1237
Added documentation to `ThinkingConfig`.
andrewheard ba64805
Add changelog entry
andrewheard be4d1ac
Add documentation to `UsageMetadata.thoughtsTokenCount`
andrewheard 73fa656
Add documentation for thinking config in `GenerationConfig`
andrewheard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/// Configuration for controlling the "thinking" behavior of compatible Gemini models. | ||
/// | ||
/// Certain models, like Gemini 2.5 Flash and Pro, utilize a thinking process before generating a | ||
paulb777 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// response. This allows them to reason through complex problems and plan a more coherent and | ||
/// accurate answer. | ||
public struct ThinkingConfig: Sendable { | ||
/// The thinking budget in tokens. | ||
/// | ||
/// This parameter sets an upper limit on the number of tokens the model can use for its internal | ||
/// "thinking" process. A higher budget may result in better quality responses for complex tasks | ||
/// but can also increase latency and cost. | ||
/// | ||
/// If you don't specify a budget (`nil`), the model will automatically determine the appropriate | ||
/// amount of thinking based on the complexity of the prompt. | ||
/// | ||
/// **Model-Specific Behavior:** | ||
/// - **Gemini 2.5 Flash:** The budget can range from `0` to `24576`. Setting the budget to `0` | ||
/// disables the thinking process, which prioritizes the lowest latency and cost. | ||
/// - **Gemini 2.5 Pro:** The budget must be an integer between `128` and `32768`. Thinking cannot | ||
/// be disabled for this model. | ||
/// | ||
/// An error will be thrown if you set a thinking budget for a model that does not support this | ||
/// feature or if the specified budget is not within the model's supported range. | ||
let thinkingBudget: Int? | ||
|
||
/// Initializes a new `ThinkingConfig`. | ||
/// | ||
/// - Parameters: | ||
/// - thinkingBudget: The maximum number of tokens to be used for the model's thinking process. | ||
public init(thinkingBudget: Int? = nil) { | ||
self.thinkingBudget = thinkingBudget | ||
} | ||
} | ||
|
||
// MARK: - Codable Conformances | ||
|
||
extension ThinkingConfig: Encodable {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.