-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ML] Support Gemini thinking budget in inference API #133599
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
DonalEvans
merged 19 commits into
elastic:main
from
DonalEvans:add-gemini-thinking-budget
Sep 4, 2025
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6e9eca0
Support Gemini thinking budget in inference API
DonalEvans bd109a0
Merge branch 'main' into add-gemini-thinking-budget
DonalEvans a39936f
Apply review feedback
DonalEvans 819aac6
Merge branch 'main' into add-gemini-thinking-budget
DonalEvans 9e42997
Fix transport versions
DonalEvans a61a649
Merge branch 'main' into add-gemini-thinking-budget
DonalEvans 95160b5
Merge branch 'main' into add-gemini-thinking-budget
DonalEvans 56fbae2
Update docs/changelog/133599.yaml
DonalEvans 5436712
Merge branch 'main' into add-gemini-thinking-budget
DonalEvans 4171c69
Merge branch 'main' into add-gemini-thinking-budget
DonalEvans 546f5ad
Move thinking config settings into task settings
DonalEvans b10aed9
Remove unnecessary override from test
DonalEvans 90e2a95
Remove transport version checks for task settings class
DonalEvans ef70439
Merge branch 'main' into add-gemini-thinking-budget
DonalEvans b458892
Merge branch 'main' into add-gemini-thinking-budget
DonalEvans ac00f5b
Merge branch 'main' into add-gemini-thinking-budget
DonalEvans 0f03736
Merge branch 'main' into add-gemini-thinking-budget
DonalEvans 779819a
Merge branch 'main' into add-gemini-thinking-budget
DonalEvans 83e5135
Merge branch 'main' into add-gemini-thinking-budget
DonalEvans 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 133599 | ||
summary: Support Gemini thinking budget in inference API | ||
area: Machine Learning | ||
type: enhancement | ||
issues: [] |
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
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
123 changes: 123 additions & 0 deletions
123
...nference/services/googlevertexai/completion/GoogleVertexAiChatCompletionTaskSettings.java
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,123 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.inference.services.googlevertexai.completion; | ||
|
||
import org.elasticsearch.TransportVersion; | ||
import org.elasticsearch.TransportVersions; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.ValidationException; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.inference.TaskSettings; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class GoogleVertexAiChatCompletionTaskSettings implements TaskSettings { | ||
public static final String NAME = "google_vertex_ai_chatcompletion_task_settings"; | ||
|
||
private final ThinkingConfig thinkingConfig; | ||
|
||
public static final GoogleVertexAiChatCompletionTaskSettings EMPTY_SETTINGS = new GoogleVertexAiChatCompletionTaskSettings(); | ||
private static final ThinkingConfig EMPTY_THINKING_CONFIG = new ThinkingConfig(); | ||
|
||
public GoogleVertexAiChatCompletionTaskSettings() { | ||
thinkingConfig = EMPTY_THINKING_CONFIG; | ||
} | ||
|
||
public GoogleVertexAiChatCompletionTaskSettings(ThinkingConfig thinkingConfig) { | ||
this.thinkingConfig = Objects.requireNonNullElse(thinkingConfig, EMPTY_THINKING_CONFIG); | ||
} | ||
|
||
public GoogleVertexAiChatCompletionTaskSettings(StreamInput in) throws IOException { | ||
thinkingConfig = new ThinkingConfig(in); | ||
} | ||
|
||
public static GoogleVertexAiChatCompletionTaskSettings fromMap(Map<String, Object> taskSettings) { | ||
ValidationException validationException = new ValidationException(); | ||
|
||
// Extract optional thinkingConfig settings | ||
ThinkingConfig thinkingConfig = ThinkingConfig.fromMap(taskSettings, validationException); | ||
|
||
if (validationException.validationErrors().isEmpty() == false) { | ||
throw validationException; | ||
} | ||
|
||
return new GoogleVertexAiChatCompletionTaskSettings(thinkingConfig); | ||
} | ||
|
||
public static GoogleVertexAiChatCompletionTaskSettings of( | ||
GoogleVertexAiChatCompletionTaskSettings originalTaskSettings, | ||
GoogleVertexAiChatCompletionTaskSettings newTaskSettings | ||
) { | ||
ThinkingConfig thinkingConfig = newTaskSettings.thinkingConfig().isEmpty() | ||
? originalTaskSettings.thinkingConfig() | ||
: newTaskSettings.thinkingConfig(); | ||
return new GoogleVertexAiChatCompletionTaskSettings(thinkingConfig); | ||
} | ||
|
||
public ThinkingConfig thinkingConfig() { | ||
return thinkingConfig; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return thinkingConfig.isEmpty(); | ||
} | ||
|
||
@Override | ||
public TaskSettings updatedTaskSettings(Map<String, Object> newSettings) { | ||
GoogleVertexAiChatCompletionTaskSettings newTaskSettings = GoogleVertexAiChatCompletionTaskSettings.fromMap( | ||
new HashMap<>(newSettings) | ||
); | ||
return GoogleVertexAiChatCompletionTaskSettings.of(this, newTaskSettings); | ||
} | ||
|
||
@Override | ||
public String getWriteableName() { | ||
return NAME; | ||
} | ||
|
||
@Override | ||
public TransportVersion getMinimalSupportedVersion() { | ||
return TransportVersions.GEMINI_THINKING_BUDGET_ADDED; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
thinkingConfig.writeTo(out); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
thinkingConfig.toXContent(builder, params); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == null || getClass() != o.getClass()) return false; | ||
GoogleVertexAiChatCompletionTaskSettings that = (GoogleVertexAiChatCompletionTaskSettings) o; | ||
return Objects.equals(thinkingConfig, that.thinkingConfig); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(thinkingConfig); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Strings.toString(this); | ||
} | ||
} |
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.