Skip to content

Commit b72f703

Browse files
BenjaminKazemicopybara-github
authored andcommitted
feat: Add minimal and medium thinking levels.
PiperOrigin-RevId: 844894275
1 parent c50e47b commit b72f703

File tree

6 files changed

+184
-11
lines changed

6 files changed

+184
-11
lines changed

src/main/java/com/google/genai/Batches.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.fasterxml.jackson.databind.node.ArrayNode;
2424
import com.fasterxml.jackson.databind.node.ObjectNode;
2525
import com.google.common.collect.ImmutableMap;
26+
import com.google.common.collect.ImmutableSet;
2627
import com.google.genai.Common.BuiltRequest;
2728
import com.google.genai.errors.GenAiIOException;
2829
import com.google.genai.types.BatchJob;
@@ -64,6 +65,15 @@ public Batches(ApiClient apiClient) {
6465
this.apiClient = apiClient;
6566
}
6667

68+
@ExcludeFromGeneratedCoverageReport
69+
void thinkingLevelMldevEnumValidate(Object enumValue) {
70+
ImmutableSet<String> invalidEnumValues = ImmutableSet.of("MEDIUM", "MINIMAL");
71+
if (invalidEnumValues.contains(enumValue.toString().replace("\"", ""))) {
72+
throw new IllegalArgumentException(
73+
String.format("%s enum value is not supported in Gemini API.", enumValue));
74+
}
75+
}
76+
6777
@ExcludeFromGeneratedCoverageReport
6878
ObjectNode batchJobDestinationFromMldev(JsonNode fromObject, ObjectNode parentObject) {
6979
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
@@ -1237,7 +1247,10 @@ ObjectNode generateContentConfigToMldev(
12371247
Common.setValueByPath(
12381248
toObject,
12391249
new String[] {"thinkingConfig"},
1240-
Common.getValueByPath(fromObject, new String[] {"thinkingConfig"}));
1250+
thinkingConfigToMldev(
1251+
JsonSerializable.toJsonNode(
1252+
Common.getValueByPath(fromObject, new String[] {"thinkingConfig"})),
1253+
toObject));
12411254
}
12421255

12431256
if (Common.getValueByPath(fromObject, new String[] {"imageConfig"}) != null) {
@@ -1748,6 +1761,35 @@ ObjectNode safetySettingToMldev(JsonNode fromObject, ObjectNode parentObject) {
17481761
return toObject;
17491762
}
17501763

1764+
@ExcludeFromGeneratedCoverageReport
1765+
ObjectNode thinkingConfigToMldev(JsonNode fromObject, ObjectNode parentObject) {
1766+
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
1767+
if (Common.getValueByPath(fromObject, new String[] {"includeThoughts"}) != null) {
1768+
Common.setValueByPath(
1769+
toObject,
1770+
new String[] {"includeThoughts"},
1771+
Common.getValueByPath(fromObject, new String[] {"includeThoughts"}));
1772+
}
1773+
1774+
if (Common.getValueByPath(fromObject, new String[] {"thinkingBudget"}) != null) {
1775+
Common.setValueByPath(
1776+
toObject,
1777+
new String[] {"thinkingBudget"},
1778+
Common.getValueByPath(fromObject, new String[] {"thinkingBudget"}));
1779+
}
1780+
1781+
if (Common.getValueByPath(fromObject, new String[] {"thinkingLevel"}) != null) {
1782+
thinkingLevelMldevEnumValidate(
1783+
Common.getValueByPath(fromObject, new String[] {"thinkingLevel"}));
1784+
Common.setValueByPath(
1785+
toObject,
1786+
new String[] {"thinkingLevel"},
1787+
Common.getValueByPath(fromObject, new String[] {"thinkingLevel"}));
1788+
}
1789+
1790+
return toObject;
1791+
}
1792+
17511793
@ExcludeFromGeneratedCoverageReport
17521794
ObjectNode toolConfigToMldev(JsonNode fromObject, ObjectNode parentObject) {
17531795
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();

src/main/java/com/google/genai/LiveConverters.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.fasterxml.jackson.databind.ObjectMapper;
2323
import com.fasterxml.jackson.databind.node.ArrayNode;
2424
import com.fasterxml.jackson.databind.node.ObjectNode;
25+
import com.google.common.collect.ImmutableSet;
2526

2627
/** Internal SDK converter functions. */
2728
final class LiveConverters {
@@ -31,6 +32,15 @@ public LiveConverters(ApiClient apiClient) {
3132
this.apiClient = apiClient;
3233
}
3334

35+
@ExcludeFromGeneratedCoverageReport
36+
void thinkingLevelMldevEnumValidate(Object enumValue) {
37+
ImmutableSet<String> invalidEnumValues = ImmutableSet.of("MEDIUM", "MINIMAL");
38+
if (invalidEnumValues.contains(enumValue.toString().replace("\"", ""))) {
39+
throw new IllegalArgumentException(
40+
String.format("%s enum value is not supported in Gemini API.", enumValue));
41+
}
42+
}
43+
3444
@ExcludeFromGeneratedCoverageReport
3545
ObjectNode blobToMldev(JsonNode fromObject, ObjectNode parentObject) {
3646
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
@@ -891,7 +901,10 @@ ObjectNode liveConnectConfigToMldev(JsonNode fromObject, ObjectNode parentObject
891901
Common.setValueByPath(
892902
parentObject,
893903
new String[] {"setup", "generationConfig", "thinkingConfig"},
894-
Common.getValueByPath(fromObject, new String[] {"thinkingConfig"}));
904+
thinkingConfigToMldev(
905+
JsonSerializable.toJsonNode(
906+
Common.getValueByPath(fromObject, new String[] {"thinkingConfig"})),
907+
toObject));
895908
}
896909

897910
if (Common.getValueByPath(fromObject, new String[] {"enableAffectiveDialog"}) != null) {
@@ -1474,6 +1487,35 @@ ObjectNode sessionResumptionConfigToMldev(JsonNode fromObject, ObjectNode parent
14741487
return toObject;
14751488
}
14761489

1490+
@ExcludeFromGeneratedCoverageReport
1491+
ObjectNode thinkingConfigToMldev(JsonNode fromObject, ObjectNode parentObject) {
1492+
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
1493+
if (Common.getValueByPath(fromObject, new String[] {"includeThoughts"}) != null) {
1494+
Common.setValueByPath(
1495+
toObject,
1496+
new String[] {"includeThoughts"},
1497+
Common.getValueByPath(fromObject, new String[] {"includeThoughts"}));
1498+
}
1499+
1500+
if (Common.getValueByPath(fromObject, new String[] {"thinkingBudget"}) != null) {
1501+
Common.setValueByPath(
1502+
toObject,
1503+
new String[] {"thinkingBudget"},
1504+
Common.getValueByPath(fromObject, new String[] {"thinkingBudget"}));
1505+
}
1506+
1507+
if (Common.getValueByPath(fromObject, new String[] {"thinkingLevel"}) != null) {
1508+
thinkingLevelMldevEnumValidate(
1509+
Common.getValueByPath(fromObject, new String[] {"thinkingLevel"}));
1510+
Common.setValueByPath(
1511+
toObject,
1512+
new String[] {"thinkingLevel"},
1513+
Common.getValueByPath(fromObject, new String[] {"thinkingLevel"}));
1514+
}
1515+
1516+
return toObject;
1517+
}
1518+
14771519
@ExcludeFromGeneratedCoverageReport
14781520
ObjectNode toolToMldev(JsonNode fromObject, ObjectNode parentObject) {
14791521
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();

src/main/java/com/google/genai/Models.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ void safetyFilterLevelMldevEnumValidate(Object enumValue) {
125125
}
126126
}
127127

128+
@ExcludeFromGeneratedCoverageReport
129+
void thinkingLevelMldevEnumValidate(Object enumValue) {
130+
ImmutableSet<String> invalidEnumValues = ImmutableSet.of("MEDIUM", "MINIMAL");
131+
if (invalidEnumValues.contains(enumValue.toString().replace("\"", ""))) {
132+
throw new IllegalArgumentException(
133+
String.format("%s enum value is not supported in Gemini API.", enumValue));
134+
}
135+
}
136+
128137
@ExcludeFromGeneratedCoverageReport
129138
void videoGenerationReferenceTypeMldevEnumValidate(Object enumValue) {
130139
ImmutableSet<String> invalidEnumValues = ImmutableSet.of("STYLE");
@@ -1359,7 +1368,10 @@ ObjectNode generateContentConfigToMldev(
13591368
Common.setValueByPath(
13601369
toObject,
13611370
new String[] {"thinkingConfig"},
1362-
Common.getValueByPath(fromObject, new String[] {"thinkingConfig"}));
1371+
thinkingConfigToMldev(
1372+
JsonSerializable.toJsonNode(
1373+
Common.getValueByPath(fromObject, new String[] {"thinkingConfig"})),
1374+
toObject));
13631375
}
13641376

13651377
if (Common.getValueByPath(fromObject, new String[] {"imageConfig"}) != null) {
@@ -4202,6 +4214,35 @@ ObjectNode segmentImageSourceToVertex(JsonNode fromObject, ObjectNode parentObje
42024214
return toObject;
42034215
}
42044216

4217+
@ExcludeFromGeneratedCoverageReport
4218+
ObjectNode thinkingConfigToMldev(JsonNode fromObject, ObjectNode parentObject) {
4219+
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
4220+
if (Common.getValueByPath(fromObject, new String[] {"includeThoughts"}) != null) {
4221+
Common.setValueByPath(
4222+
toObject,
4223+
new String[] {"includeThoughts"},
4224+
Common.getValueByPath(fromObject, new String[] {"includeThoughts"}));
4225+
}
4226+
4227+
if (Common.getValueByPath(fromObject, new String[] {"thinkingBudget"}) != null) {
4228+
Common.setValueByPath(
4229+
toObject,
4230+
new String[] {"thinkingBudget"},
4231+
Common.getValueByPath(fromObject, new String[] {"thinkingBudget"}));
4232+
}
4233+
4234+
if (Common.getValueByPath(fromObject, new String[] {"thinkingLevel"}) != null) {
4235+
thinkingLevelMldevEnumValidate(
4236+
Common.getValueByPath(fromObject, new String[] {"thinkingLevel"}));
4237+
Common.setValueByPath(
4238+
toObject,
4239+
new String[] {"thinkingLevel"},
4240+
Common.getValueByPath(fromObject, new String[] {"thinkingLevel"}));
4241+
}
4242+
4243+
return toObject;
4244+
}
4245+
42054246
@ExcludeFromGeneratedCoverageReport
42064247
ObjectNode toolConfigToMldev(JsonNode fromObject, ObjectNode parentObject) {
42074248
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();

src/main/java/com/google/genai/TokensConverters.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.fasterxml.jackson.databind.ObjectMapper;
2323
import com.fasterxml.jackson.databind.node.ArrayNode;
2424
import com.fasterxml.jackson.databind.node.ObjectNode;
25+
import com.google.common.collect.ImmutableSet;
2526

2627
/** Internal SDK converter functions. */
2728
final class TokensConverters {
@@ -31,6 +32,15 @@ public TokensConverters(ApiClient apiClient) {
3132
this.apiClient = apiClient;
3233
}
3334

35+
@ExcludeFromGeneratedCoverageReport
36+
void thinkingLevelMldevEnumValidate(Object enumValue) {
37+
ImmutableSet<String> invalidEnumValues = ImmutableSet.of("MEDIUM", "MINIMAL");
38+
if (invalidEnumValues.contains(enumValue.toString().replace("\"", ""))) {
39+
throw new IllegalArgumentException(
40+
String.format("%s enum value is not supported in Gemini API.", enumValue));
41+
}
42+
}
43+
3444
@ExcludeFromGeneratedCoverageReport
3545
ObjectNode blobToMldev(JsonNode fromObject, ObjectNode parentObject) {
3646
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
@@ -316,7 +326,10 @@ ObjectNode liveConnectConfigToMldev(JsonNode fromObject, ObjectNode parentObject
316326
Common.setValueByPath(
317327
parentObject,
318328
new String[] {"setup", "generationConfig", "thinkingConfig"},
319-
Common.getValueByPath(fromObject, new String[] {"thinkingConfig"}));
329+
thinkingConfigToMldev(
330+
JsonSerializable.toJsonNode(
331+
Common.getValueByPath(fromObject, new String[] {"thinkingConfig"})),
332+
toObject));
320333
}
321334

322335
if (Common.getValueByPath(fromObject, new String[] {"enableAffectiveDialog"}) != null) {
@@ -537,6 +550,35 @@ ObjectNode sessionResumptionConfigToMldev(JsonNode fromObject, ObjectNode parent
537550
return toObject;
538551
}
539552

553+
@ExcludeFromGeneratedCoverageReport
554+
ObjectNode thinkingConfigToMldev(JsonNode fromObject, ObjectNode parentObject) {
555+
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
556+
if (Common.getValueByPath(fromObject, new String[] {"includeThoughts"}) != null) {
557+
Common.setValueByPath(
558+
toObject,
559+
new String[] {"includeThoughts"},
560+
Common.getValueByPath(fromObject, new String[] {"includeThoughts"}));
561+
}
562+
563+
if (Common.getValueByPath(fromObject, new String[] {"thinkingBudget"}) != null) {
564+
Common.setValueByPath(
565+
toObject,
566+
new String[] {"thinkingBudget"},
567+
Common.getValueByPath(fromObject, new String[] {"thinkingBudget"}));
568+
}
569+
570+
if (Common.getValueByPath(fromObject, new String[] {"thinkingLevel"}) != null) {
571+
thinkingLevelMldevEnumValidate(
572+
Common.getValueByPath(fromObject, new String[] {"thinkingLevel"}));
573+
Common.setValueByPath(
574+
toObject,
575+
new String[] {"thinkingLevel"},
576+
Common.getValueByPath(fromObject, new String[] {"thinkingLevel"}));
577+
}
578+
579+
return toObject;
580+
}
581+
540582
@ExcludeFromGeneratedCoverageReport
541583
ObjectNode toolToMldev(JsonNode fromObject, ObjectNode parentObject) {
542584
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();

src/main/java/com/google/genai/types/ThinkingConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public abstract class ThinkingConfig extends JsonSerializable {
4444
@JsonProperty("thinkingBudget")
4545
public abstract Optional<Integer> thinkingBudget();
4646

47-
/** Optional. The level of thoughts tokens that the model should generate. */
47+
/** Optional. The number of thoughts tokens that the model should generate. */
4848
@JsonProperty("thinkingLevel")
4949
public abstract Optional<ThinkingLevel> thinkingLevel();
5050

@@ -107,7 +107,7 @@ public Builder clearThinkingBudget() {
107107
/**
108108
* Setter for thinkingLevel.
109109
*
110-
* <p>thinkingLevel: Optional. The level of thoughts tokens that the model should generate.
110+
* <p>thinkingLevel: Optional. The number of thoughts tokens that the model should generate.
111111
*/
112112
@JsonProperty("thinkingLevel")
113113
public abstract Builder thinkingLevel(ThinkingLevel thinkingLevel);
@@ -125,7 +125,7 @@ public Builder clearThinkingLevel() {
125125
/**
126126
* Setter for thinkingLevel given a known enum.
127127
*
128-
* <p>thinkingLevel: Optional. The level of thoughts tokens that the model should generate.
128+
* <p>thinkingLevel: Optional. The number of thoughts tokens that the model should generate.
129129
*/
130130
@CanIgnoreReturnValue
131131
public Builder thinkingLevel(ThinkingLevel.Known knownType) {
@@ -135,7 +135,7 @@ public Builder thinkingLevel(ThinkingLevel.Known knownType) {
135135
/**
136136
* Setter for thinkingLevel given a string.
137137
*
138-
* <p>thinkingLevel: Optional. The level of thoughts tokens that the model should generate.
138+
* <p>thinkingLevel: Optional. The number of thoughts tokens that the model should generate.
139139
*/
140140
@CanIgnoreReturnValue
141141
public Builder thinkingLevel(String thinkingLevel) {

src/main/java/com/google/genai/types/ThinkingLevel.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,25 @@
2323
import com.google.common.base.Ascii;
2424
import java.util.Objects;
2525

26-
/** The level of thoughts tokens that the model should generate. */
26+
/** The number of thoughts tokens that the model should generate. */
2727
public class ThinkingLevel {
2828

2929
/** Enum representing the known values for ThinkingLevel. */
3030
public enum Known {
31-
/** Default value. */
31+
/** Unspecified thinking level. */
3232
THINKING_LEVEL_UNSPECIFIED,
3333

3434
/** Low thinking level. */
3535
LOW,
3636

3737
/** High thinking level. */
38-
HIGH
38+
HIGH,
39+
40+
/** Medium thinking level. This enum value is not supported in Gemini API. */
41+
MEDIUM,
42+
43+
/** MINIMAL thinking level. This enum value is not supported in Gemini API. */
44+
MINIMAL
3945
}
4046

4147
private Known thinkingLevelEnum;

0 commit comments

Comments
 (0)