Skip to content

Commit 4745974

Browse files
wanlin31copybara-github
authored andcommitted
feat: [GenerateContentConfig] Add GenerationConfig.audio_transcription_config and Part.audio_transcription.
PiperOrigin-RevId: 952236427
1 parent 08f0388 commit 4745974

12 files changed

Lines changed: 596 additions & 0 deletions

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,60 @@ public Batches(ApiClient apiClient) {
6464
this.apiClient = apiClient;
6565
}
6666

67+
@ExcludeFromGeneratedCoverageReport
68+
ObjectNode audioTranscriptionConfigToMldev(JsonNode fromObject, ObjectNode parentObject) {
69+
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
70+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"languageCodes"}))) {
71+
throw new IllegalArgumentException(
72+
"languageCodes parameter is only supported in Gemini Enterprise Agent Platform mode, not"
73+
+ " in Gemini Developer API mode.");
74+
}
75+
76+
if (Common.getValueByPath(fromObject, new String[] {"languageAuto"}) != null) {
77+
Common.setValueByPath(
78+
toObject,
79+
new String[] {"languageAuto"},
80+
Common.getValueByPath(fromObject, new String[] {"languageAuto"}));
81+
}
82+
83+
if (Common.getValueByPath(fromObject, new String[] {"languageHints"}) != null) {
84+
Common.setValueByPath(
85+
toObject,
86+
new String[] {"languageHints"},
87+
Common.getValueByPath(fromObject, new String[] {"languageHints"}));
88+
}
89+
90+
if (Common.getValueByPath(fromObject, new String[] {"customVocabulary"}) != null) {
91+
Common.setValueByPath(
92+
toObject,
93+
new String[] {"customVocabulary"},
94+
Common.getValueByPath(fromObject, new String[] {"customVocabulary"}));
95+
}
96+
97+
if (Common.getValueByPath(fromObject, new String[] {"adaptationPhrases"}) != null) {
98+
Common.setValueByPath(
99+
toObject,
100+
new String[] {"adaptationPhrases"},
101+
Common.getValueByPath(fromObject, new String[] {"adaptationPhrases"}));
102+
}
103+
104+
if (Common.getValueByPath(fromObject, new String[] {"diarization"}) != null) {
105+
Common.setValueByPath(
106+
toObject,
107+
new String[] {"diarization"},
108+
Common.getValueByPath(fromObject, new String[] {"diarization"}));
109+
}
110+
111+
if (Common.getValueByPath(fromObject, new String[] {"wordTimestamp"}) != null) {
112+
Common.setValueByPath(
113+
toObject,
114+
new String[] {"wordTimestamp"},
115+
Common.getValueByPath(fromObject, new String[] {"wordTimestamp"}));
116+
}
117+
118+
return toObject;
119+
}
120+
67121
@ExcludeFromGeneratedCoverageReport
68122
ObjectNode authConfigToMldev(JsonNode fromObject, ObjectNode parentObject) {
69123
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
@@ -1430,6 +1484,16 @@ ObjectNode generateContentConfigToMldev(
14301484
Common.getValueByPath(fromObject, new String[] {"serviceTier"}));
14311485
}
14321486

1487+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscriptionConfig"}) != null) {
1488+
Common.setValueByPath(
1489+
toObject,
1490+
new String[] {"audioTranscriptionConfig"},
1491+
audioTranscriptionConfigToMldev(
1492+
JsonSerializable.toJsonNode(
1493+
Common.getValueByPath(fromObject, new String[] {"audioTranscriptionConfig"})),
1494+
toObject));
1495+
}
1496+
14331497
return toObject;
14341498
}
14351499

@@ -1966,6 +2030,13 @@ ObjectNode partToMldev(JsonNode fromObject, ObjectNode parentObject) {
19662030
Common.getValueByPath(fromObject, new String[] {"partMetadata"}));
19672031
}
19682032

2033+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscription"}) != null) {
2034+
Common.setValueByPath(
2035+
toObject,
2036+
new String[] {"audioTranscription"},
2037+
Common.getValueByPath(fromObject, new String[] {"audioTranscription"}));
2038+
}
2039+
19692040
return toObject;
19702041
}
19712042

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,13 @@ ObjectNode partToMldev(JsonNode fromObject, ObjectNode parentObject) {
959959
Common.getValueByPath(fromObject, new String[] {"partMetadata"}));
960960
}
961961

962+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscription"}) != null) {
963+
Common.setValueByPath(
964+
toObject,
965+
new String[] {"audioTranscription"},
966+
Common.getValueByPath(fromObject, new String[] {"audioTranscription"}));
967+
}
968+
962969
return toObject;
963970
}
964971

@@ -1066,6 +1073,13 @@ ObjectNode partToVertex(JsonNode fromObject, ObjectNode parentObject) {
10661073
+ " Enterprise Agent Platform mode.");
10671074
}
10681075

1076+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscription"}) != null) {
1077+
Common.setValueByPath(
1078+
toObject,
1079+
new String[] {"audioTranscription"},
1080+
Common.getValueByPath(fromObject, new String[] {"audioTranscription"}));
1081+
}
1082+
10691083
return toObject;
10701084
}
10711085

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ ObjectNode audioTranscriptionConfigToMldev(JsonNode fromObject, ObjectNode paren
6868
Common.getValueByPath(fromObject, new String[] {"adaptationPhrases"}));
6969
}
7070

71+
if (Common.getValueByPath(fromObject, new String[] {"diarization"}) != null) {
72+
Common.setValueByPath(
73+
toObject,
74+
new String[] {"diarization"},
75+
Common.getValueByPath(fromObject, new String[] {"diarization"}));
76+
}
77+
78+
if (Common.getValueByPath(fromObject, new String[] {"wordTimestamp"}) != null) {
79+
Common.setValueByPath(
80+
toObject,
81+
new String[] {"wordTimestamp"},
82+
Common.getValueByPath(fromObject, new String[] {"wordTimestamp"}));
83+
}
84+
7185
return toObject;
7286
}
7387

@@ -525,6 +539,13 @@ ObjectNode generationConfigToVertex(JsonNode fromObject, ObjectNode parentObject
525539
+ " Gemini Enterprise Agent Platform mode.");
526540
}
527541

542+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscriptionConfig"}) != null) {
543+
Common.setValueByPath(
544+
toObject,
545+
new String[] {"audioTranscriptionConfig"},
546+
Common.getValueByPath(fromObject, new String[] {"audioTranscriptionConfig"}));
547+
}
548+
528549
return toObject;
529550
}
530551

@@ -1928,6 +1949,13 @@ ObjectNode partToMldev(JsonNode fromObject, ObjectNode parentObject) {
19281949
Common.getValueByPath(fromObject, new String[] {"partMetadata"}));
19291950
}
19301951

1952+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscription"}) != null) {
1953+
Common.setValueByPath(
1954+
toObject,
1955+
new String[] {"audioTranscription"},
1956+
Common.getValueByPath(fromObject, new String[] {"audioTranscription"}));
1957+
}
1958+
19311959
return toObject;
19321960
}
19331961

@@ -2035,6 +2063,13 @@ ObjectNode partToVertex(JsonNode fromObject, ObjectNode parentObject) {
20352063
+ " Enterprise Agent Platform mode.");
20362064
}
20372065

2066+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscription"}) != null) {
2067+
Common.setValueByPath(
2068+
toObject,
2069+
new String[] {"audioTranscription"},
2070+
Common.getValueByPath(fromObject, new String[] {"audioTranscription"}));
2071+
}
2072+
20382073
return toObject;
20392074
}
20402075

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

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,61 @@ void videoGenerationReferenceTypeMldevEnumValidate(Object enumValue) {
145145
}
146146
}
147147

148+
@ExcludeFromGeneratedCoverageReport
149+
ObjectNode audioTranscriptionConfigToMldev(
150+
JsonNode fromObject, ObjectNode parentObject, JsonNode rootObject) {
151+
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
152+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"languageCodes"}))) {
153+
throw new IllegalArgumentException(
154+
"languageCodes parameter is only supported in Gemini Enterprise Agent Platform mode, not"
155+
+ " in Gemini Developer API mode.");
156+
}
157+
158+
if (Common.getValueByPath(fromObject, new String[] {"languageAuto"}) != null) {
159+
Common.setValueByPath(
160+
toObject,
161+
new String[] {"languageAuto"},
162+
Common.getValueByPath(fromObject, new String[] {"languageAuto"}));
163+
}
164+
165+
if (Common.getValueByPath(fromObject, new String[] {"languageHints"}) != null) {
166+
Common.setValueByPath(
167+
toObject,
168+
new String[] {"languageHints"},
169+
Common.getValueByPath(fromObject, new String[] {"languageHints"}));
170+
}
171+
172+
if (Common.getValueByPath(fromObject, new String[] {"customVocabulary"}) != null) {
173+
Common.setValueByPath(
174+
toObject,
175+
new String[] {"customVocabulary"},
176+
Common.getValueByPath(fromObject, new String[] {"customVocabulary"}));
177+
}
178+
179+
if (Common.getValueByPath(fromObject, new String[] {"adaptationPhrases"}) != null) {
180+
Common.setValueByPath(
181+
toObject,
182+
new String[] {"adaptationPhrases"},
183+
Common.getValueByPath(fromObject, new String[] {"adaptationPhrases"}));
184+
}
185+
186+
if (Common.getValueByPath(fromObject, new String[] {"diarization"}) != null) {
187+
Common.setValueByPath(
188+
toObject,
189+
new String[] {"diarization"},
190+
Common.getValueByPath(fromObject, new String[] {"diarization"}));
191+
}
192+
193+
if (Common.getValueByPath(fromObject, new String[] {"wordTimestamp"}) != null) {
194+
Common.setValueByPath(
195+
toObject,
196+
new String[] {"wordTimestamp"},
197+
Common.getValueByPath(fromObject, new String[] {"wordTimestamp"}));
198+
}
199+
200+
return toObject;
201+
}
202+
148203
@ExcludeFromGeneratedCoverageReport
149204
ObjectNode authConfigToMldev(JsonNode fromObject, ObjectNode parentObject, JsonNode rootObject) {
150205
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
@@ -1757,6 +1812,17 @@ ObjectNode generateContentConfigToMldev(
17571812
Common.getValueByPath(fromObject, new String[] {"serviceTier"}));
17581813
}
17591814

1815+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscriptionConfig"}) != null) {
1816+
Common.setValueByPath(
1817+
toObject,
1818+
new String[] {"audioTranscriptionConfig"},
1819+
audioTranscriptionConfigToMldev(
1820+
JsonSerializable.toJsonNode(
1821+
Common.getValueByPath(fromObject, new String[] {"audioTranscriptionConfig"})),
1822+
toObject,
1823+
rootObject));
1824+
}
1825+
17601826
return toObject;
17611827
}
17621828

@@ -2009,6 +2075,13 @@ ObjectNode generateContentConfigToVertex(
20092075
Common.getValueByPath(fromObject, new String[] {"serviceTier"}));
20102076
}
20112077

2078+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscriptionConfig"}) != null) {
2079+
Common.setValueByPath(
2080+
toObject,
2081+
new String[] {"audioTranscriptionConfig"},
2082+
Common.getValueByPath(fromObject, new String[] {"audioTranscriptionConfig"}));
2083+
}
2084+
20122085
return toObject;
20132086
}
20142087

@@ -3579,6 +3652,13 @@ ObjectNode generationConfigToVertex(
35793652
+ " Gemini Enterprise Agent Platform mode.");
35803653
}
35813654

3655+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscriptionConfig"}) != null) {
3656+
Common.setValueByPath(
3657+
toObject,
3658+
new String[] {"audioTranscriptionConfig"},
3659+
Common.getValueByPath(fromObject, new String[] {"audioTranscriptionConfig"}));
3660+
}
3661+
35823662
return toObject;
35833663
}
35843664

@@ -4412,6 +4492,13 @@ ObjectNode partToMldev(JsonNode fromObject, ObjectNode parentObject, JsonNode ro
44124492
Common.getValueByPath(fromObject, new String[] {"partMetadata"}));
44134493
}
44144494

4495+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscription"}) != null) {
4496+
Common.setValueByPath(
4497+
toObject,
4498+
new String[] {"audioTranscription"},
4499+
Common.getValueByPath(fromObject, new String[] {"audioTranscription"}));
4500+
}
4501+
44154502
return toObject;
44164503
}
44174504

@@ -4521,6 +4608,13 @@ ObjectNode partToVertex(JsonNode fromObject, ObjectNode parentObject, JsonNode r
45214608
+ " Enterprise Agent Platform mode.");
45224609
}
45234610

4611+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscription"}) != null) {
4612+
Common.setValueByPath(
4613+
toObject,
4614+
new String[] {"audioTranscription"},
4615+
Common.getValueByPath(fromObject, new String[] {"audioTranscription"}));
4616+
}
4617+
45244618
return toObject;
45254619
}
45264620

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ ObjectNode audioTranscriptionConfigToMldev(JsonNode fromObject, ObjectNode paren
6868
Common.getValueByPath(fromObject, new String[] {"adaptationPhrases"}));
6969
}
7070

71+
if (Common.getValueByPath(fromObject, new String[] {"diarization"}) != null) {
72+
Common.setValueByPath(
73+
toObject,
74+
new String[] {"diarization"},
75+
Common.getValueByPath(fromObject, new String[] {"diarization"}));
76+
}
77+
78+
if (Common.getValueByPath(fromObject, new String[] {"wordTimestamp"}) != null) {
79+
Common.setValueByPath(
80+
toObject,
81+
new String[] {"wordTimestamp"},
82+
Common.getValueByPath(fromObject, new String[] {"wordTimestamp"}));
83+
}
84+
7185
return toObject;
7286
}
7387

@@ -686,6 +700,13 @@ ObjectNode partToMldev(JsonNode fromObject, ObjectNode parentObject) {
686700
Common.getValueByPath(fromObject, new String[] {"partMetadata"}));
687701
}
688702

703+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscription"}) != null) {
704+
Common.setValueByPath(
705+
toObject,
706+
new String[] {"audioTranscription"},
707+
Common.getValueByPath(fromObject, new String[] {"audioTranscription"}));
708+
}
709+
689710
return toObject;
690711
}
691712

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,13 @@ ObjectNode generationConfigFromVertex(
12261226
Common.getValueByPath(fromObject, new String[] {"responseFormat"}));
12271227
}
12281228

1229+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscriptionConfig"}) != null) {
1230+
Common.setValueByPath(
1231+
toObject,
1232+
new String[] {"audioTranscriptionConfig"},
1233+
Common.getValueByPath(fromObject, new String[] {"audioTranscriptionConfig"}));
1234+
}
1235+
12291236
return toObject;
12301237
}
12311238

@@ -1411,6 +1418,13 @@ ObjectNode generationConfigToVertex(
14111418
+ " Gemini Enterprise Agent Platform mode.");
14121419
}
14131420

1421+
if (Common.getValueByPath(fromObject, new String[] {"audioTranscriptionConfig"}) != null) {
1422+
Common.setValueByPath(
1423+
toObject,
1424+
new String[] {"audioTranscriptionConfig"},
1425+
Common.getValueByPath(fromObject, new String[] {"audioTranscriptionConfig"}));
1426+
}
1427+
14141428
return toObject;
14151429
}
14161430

0 commit comments

Comments
 (0)