Skip to content

Commit 1816a22

Browse files
jaycee-licopybara-github
authored andcommitted
feat: Add Tool.exa_ai_search for Gemini Enterprise API
feat: Add response_format and Translation_config in GenerationConfig PiperOrigin-RevId: 936848756
1 parent 563ff2e commit 1816a22

77 files changed

Lines changed: 2482 additions & 255 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ public CompletableFuture<DeleteModelResponse> delete(String model, DeleteModelCo
458458
* Asynchronously counts tokens given a GenAI model and a list of content.
459459
*
460460
* @param model the name of the GenAI model to use.
461-
* @param contents a {@link List<com.google.genai.types.Content>} to send to count tokens for.
461+
* @param contents a {@link List&lt;com.google.genai.types.Content&gt;} to send to count tokens
462+
* for.
462463
* @param config a {@link com.google.genai.types.CountTokensConfig} instance that specifies the
463464
* optional configurations
464465
* @return a {@link com.google.genai.types.CountTokensResponse} instance that contains tokens
@@ -493,7 +494,8 @@ public CompletableFuture<CountTokensResponse> countTokens(
493494
* Asynchronously computes tokens given a GenAI model and a list of content.
494495
*
495496
* @param model the name of the GenAI model to use.
496-
* @param contents a {@link List<com.google.genai.types.Content>} to send to compute tokens for.
497+
* @param contents a {@link List&lt;com.google.genai.types.Content&gt;} to send to compute tokens
498+
* for.
497499
* @param config a {@link com.google.genai.types.ComputeTokensConfig} instance that specifies the
498500
* optional configurations
499501
* @return a {@link com.google.genai.types.ComputeTokensResponse} instance that contains tokens

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,6 +2116,12 @@ ObjectNode toolToMldev(JsonNode fromObject, ObjectNode parentObject) {
21162116
Common.getValueByPath(fromObject, new String[] {"mcpServers"}));
21172117
}
21182118

2119+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"exaAiSearch"}))) {
2120+
throw new IllegalArgumentException(
2121+
"exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in"
2122+
+ " Gemini Developer API mode.");
2123+
}
2124+
21192125
return toObject;
21202126
}
21212127

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,12 @@ ObjectNode toolToMldev(JsonNode fromObject, ObjectNode parentObject) {
12171217
Common.getValueByPath(fromObject, new String[] {"mcpServers"}));
12181218
}
12191219

1220+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"exaAiSearch"}))) {
1221+
throw new IllegalArgumentException(
1222+
"exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in"
1223+
+ " Gemini Developer API mode.");
1224+
}
1225+
12201226
return toObject;
12211227
}
12221228

@@ -1314,6 +1320,13 @@ ObjectNode toolToVertex(JsonNode fromObject, ObjectNode parentObject) {
13141320
Common.setValueByPath(toObject, new String[] {"mcpServers"}, result);
13151321
}
13161322

1323+
if (Common.getValueByPath(fromObject, new String[] {"exaAiSearch"}) != null) {
1324+
Common.setValueByPath(
1325+
toObject,
1326+
new String[] {"exaAiSearch"},
1327+
Common.getValueByPath(fromObject, new String[] {"exaAiSearch"}));
1328+
}
1329+
13171330
return toObject;
13181331
}
13191332

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,19 @@ ObjectNode generationConfigToVertex(JsonNode fromObject, ObjectNode parentObject
502502
+ " in Gemini Enterprise Agent Platform mode.");
503503
}
504504

505+
if (Common.getValueByPath(fromObject, new String[] {"responseFormat"}) != null) {
506+
Common.setValueByPath(
507+
toObject,
508+
new String[] {"responseFormat"},
509+
Common.getValueByPath(fromObject, new String[] {"responseFormat"}));
510+
}
511+
512+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"translationConfig"}))) {
513+
throw new IllegalArgumentException(
514+
"translationConfig parameter is only supported in Gemini Developer API mode, not in"
515+
+ " Gemini Enterprise Agent Platform mode.");
516+
}
517+
505518
return toObject;
506519
}
507520

@@ -2115,6 +2128,12 @@ ObjectNode toolToMldev(JsonNode fromObject, ObjectNode parentObject) {
21152128
Common.getValueByPath(fromObject, new String[] {"mcpServers"}));
21162129
}
21172130

2131+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"exaAiSearch"}))) {
2132+
throw new IllegalArgumentException(
2133+
"exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in"
2134+
+ " Gemini Developer API mode.");
2135+
}
2136+
21182137
return toObject;
21192138
}
21202139

@@ -2212,6 +2231,13 @@ ObjectNode toolToVertex(JsonNode fromObject, ObjectNode parentObject) {
22122231
Common.setValueByPath(toObject, new String[] {"mcpServers"}, result);
22132232
}
22142233

2234+
if (Common.getValueByPath(fromObject, new String[] {"exaAiSearch"}) != null) {
2235+
Common.setValueByPath(
2236+
toObject,
2237+
new String[] {"exaAiSearch"},
2238+
Common.getValueByPath(fromObject, new String[] {"exaAiSearch"}));
2239+
}
2240+
22152241
return toObject;
22162242
}
22172243

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,6 +3547,19 @@ ObjectNode generationConfigToVertex(
35473547
+ " in Gemini Enterprise Agent Platform mode.");
35483548
}
35493549

3550+
if (Common.getValueByPath(fromObject, new String[] {"responseFormat"}) != null) {
3551+
Common.setValueByPath(
3552+
toObject,
3553+
new String[] {"responseFormat"},
3554+
Common.getValueByPath(fromObject, new String[] {"responseFormat"}));
3555+
}
3556+
3557+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"translationConfig"}))) {
3558+
throw new IllegalArgumentException(
3559+
"translationConfig parameter is only supported in Gemini Developer API mode, not in"
3560+
+ " Gemini Enterprise Agent Platform mode.");
3561+
}
3562+
35503563
return toObject;
35513564
}
35523565

@@ -5126,6 +5139,12 @@ ObjectNode toolToMldev(JsonNode fromObject, ObjectNode parentObject, JsonNode ro
51265139
Common.getValueByPath(fromObject, new String[] {"mcpServers"}));
51275140
}
51285141

5142+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"exaAiSearch"}))) {
5143+
throw new IllegalArgumentException(
5144+
"exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in"
5145+
+ " Gemini Developer API mode.");
5146+
}
5147+
51295148
return toObject;
51305149
}
51315150

@@ -5224,6 +5243,13 @@ ObjectNode toolToVertex(JsonNode fromObject, ObjectNode parentObject, JsonNode r
52245243
Common.setValueByPath(toObject, new String[] {"mcpServers"}, result);
52255244
}
52265245

5246+
if (Common.getValueByPath(fromObject, new String[] {"exaAiSearch"}) != null) {
5247+
Common.setValueByPath(
5248+
toObject,
5249+
new String[] {"exaAiSearch"},
5250+
Common.getValueByPath(fromObject, new String[] {"exaAiSearch"}));
5251+
}
5252+
52275253
return toObject;
52285254
}
52295255

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,12 @@ ObjectNode toolToMldev(JsonNode fromObject, ObjectNode parentObject) {
817817
Common.getValueByPath(fromObject, new String[] {"mcpServers"}));
818818
}
819819

820+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"exaAiSearch"}))) {
821+
throw new IllegalArgumentException(
822+
"exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in"
823+
+ " Gemini Developer API mode.");
824+
}
825+
820826
return toObject;
821827
}
822828
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,13 @@ ObjectNode generationConfigFromVertex(
12191219
Common.getValueByPath(fromObject, new String[] {"topP"}));
12201220
}
12211221

1222+
if (Common.getValueByPath(fromObject, new String[] {"responseFormat"}) != null) {
1223+
Common.setValueByPath(
1224+
toObject,
1225+
new String[] {"responseFormat"},
1226+
Common.getValueByPath(fromObject, new String[] {"responseFormat"}));
1227+
}
1228+
12221229
return toObject;
12231230
}
12241231

@@ -1387,6 +1394,19 @@ ObjectNode generationConfigToVertex(
13871394
+ " in Gemini Enterprise Agent Platform mode.");
13881395
}
13891396

1397+
if (Common.getValueByPath(fromObject, new String[] {"responseFormat"}) != null) {
1398+
Common.setValueByPath(
1399+
toObject,
1400+
new String[] {"responseFormat"},
1401+
Common.getValueByPath(fromObject, new String[] {"responseFormat"}));
1402+
}
1403+
1404+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"translationConfig"}))) {
1405+
throw new IllegalArgumentException(
1406+
"translationConfig parameter is only supported in Gemini Developer API mode, not in"
1407+
+ " Gemini Enterprise Agent Platform mode.");
1408+
}
1409+
13901410
return toObject;
13911411
}
13921412

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Auto-generated code. Do not edit.
18+
19+
package com.google.genai.types;
20+
21+
import com.fasterxml.jackson.annotation.JsonCreator;
22+
import com.fasterxml.jackson.annotation.JsonValue;
23+
import com.google.common.base.Ascii;
24+
import java.util.Objects;
25+
26+
/** The aspect ratio for the image output. */
27+
public class AspectRatio {
28+
29+
/** Enum representing the known values for AspectRatio. */
30+
public enum Known {
31+
/** Default value. This value is unused. */
32+
ASPECT_RATIO_UNSPECIFIED,
33+
34+
/** 1:1 aspect ratio. */
35+
ASPECT_RATIO_ONE_BY_ONE,
36+
37+
/** 2:3 aspect ratio. */
38+
ASPECT_RATIO_TWO_BY_THREE,
39+
40+
/** 3:2 aspect ratio. */
41+
ASPECT_RATIO_THREE_BY_TWO,
42+
43+
/** 3:4 aspect ratio. */
44+
ASPECT_RATIO_THREE_BY_FOUR,
45+
46+
/** 4:3 aspect ratio. */
47+
ASPECT_RATIO_FOUR_BY_THREE,
48+
49+
/** 4:5 aspect ratio. */
50+
ASPECT_RATIO_FOUR_BY_FIVE,
51+
52+
/** 5:4 aspect ratio. */
53+
ASPECT_RATIO_FIVE_BY_FOUR,
54+
55+
/** 9:16 aspect ratio. */
56+
ASPECT_RATIO_NINE_BY_SIXTEEN,
57+
58+
/** 16:9 aspect ratio. */
59+
ASPECT_RATIO_SIXTEEN_BY_NINE,
60+
61+
/** 21:9 aspect ratio. */
62+
ASPECT_RATIO_TWENTY_ONE_BY_NINE,
63+
64+
/** 1:8 aspect ratio. */
65+
ASPECT_RATIO_ONE_BY_EIGHT,
66+
67+
/** 8:1 aspect ratio. */
68+
ASPECT_RATIO_EIGHT_BY_ONE,
69+
70+
/** 1:4 aspect ratio. */
71+
ASPECT_RATIO_ONE_BY_FOUR,
72+
73+
/** 4:1 aspect ratio. */
74+
ASPECT_RATIO_FOUR_BY_ONE
75+
}
76+
77+
private Known aspectRatioEnum;
78+
private final String value;
79+
80+
@JsonCreator
81+
public AspectRatio(String value) {
82+
this.value = value;
83+
for (Known aspectRatioEnum : Known.values()) {
84+
if (Ascii.equalsIgnoreCase(aspectRatioEnum.toString(), value)) {
85+
this.aspectRatioEnum = aspectRatioEnum;
86+
break;
87+
}
88+
}
89+
if (this.aspectRatioEnum == null) {
90+
this.aspectRatioEnum = Known.ASPECT_RATIO_UNSPECIFIED;
91+
}
92+
}
93+
94+
public AspectRatio(Known knownValue) {
95+
this.aspectRatioEnum = knownValue;
96+
this.value = knownValue.toString();
97+
}
98+
99+
@ExcludeFromGeneratedCoverageReport
100+
@Override
101+
@JsonValue
102+
public String toString() {
103+
return this.value;
104+
}
105+
106+
@ExcludeFromGeneratedCoverageReport
107+
@SuppressWarnings("PatternMatchingInstanceof")
108+
@Override
109+
public boolean equals(Object o) {
110+
if (this == o) {
111+
return true;
112+
}
113+
if (o == null) {
114+
return false;
115+
}
116+
117+
if (!(o instanceof AspectRatio)) {
118+
return false;
119+
}
120+
121+
AspectRatio other = (AspectRatio) o;
122+
123+
if (this.aspectRatioEnum != Known.ASPECT_RATIO_UNSPECIFIED
124+
&& other.aspectRatioEnum != Known.ASPECT_RATIO_UNSPECIFIED) {
125+
return this.aspectRatioEnum == other.aspectRatioEnum;
126+
} else if (this.aspectRatioEnum == Known.ASPECT_RATIO_UNSPECIFIED
127+
&& other.aspectRatioEnum == Known.ASPECT_RATIO_UNSPECIFIED) {
128+
return this.value.equals(other.value);
129+
}
130+
return false;
131+
}
132+
133+
@ExcludeFromGeneratedCoverageReport
134+
@Override
135+
public int hashCode() {
136+
if (this.aspectRatioEnum != Known.ASPECT_RATIO_UNSPECIFIED) {
137+
return this.aspectRatioEnum.hashCode();
138+
} else {
139+
return Objects.hashCode(this.value);
140+
}
141+
}
142+
143+
@ExcludeFromGeneratedCoverageReport
144+
public Known knownEnum() {
145+
return this.aspectRatioEnum;
146+
}
147+
}

0 commit comments

Comments
 (0)