Skip to content

Commit fe5d322

Browse files
matthew29tangcopybara-github
authored andcommitted
feat: Add Live Avatar new fields
PiperOrigin-RevId: 891963096
1 parent eadce20 commit fe5d322

File tree

8 files changed

+625
-2
lines changed

8 files changed

+625
-2
lines changed

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

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,25 @@ ObjectNode liveClientSetupToMldev(JsonNode fromObject, ObjectNode parentObject)
853853
"explicitVadSignal parameter is not supported in Gemini API.");
854854
}
855855

856+
if (Common.getValueByPath(fromObject, new String[] {"avatarConfig"}) != null) {
857+
Common.setValueByPath(
858+
toObject,
859+
new String[] {"avatarConfig"},
860+
Common.getValueByPath(fromObject, new String[] {"avatarConfig"}));
861+
}
862+
863+
if (Common.getValueByPath(fromObject, new String[] {"safetySettings"}) != null) {
864+
ArrayNode keyArray =
865+
(ArrayNode) Common.getValueByPath(fromObject, new String[] {"safetySettings"});
866+
ObjectMapper objectMapper = new ObjectMapper();
867+
ArrayNode result = objectMapper.createArrayNode();
868+
869+
for (JsonNode item : keyArray) {
870+
result.add(safetySettingToMldev(JsonSerializable.toJsonNode(item), toObject));
871+
}
872+
Common.setValueByPath(toObject, new String[] {"safetySettings"}, result);
873+
}
874+
856875
return toObject;
857876
}
858877

@@ -949,6 +968,20 @@ ObjectNode liveClientSetupToVertex(JsonNode fromObject, ObjectNode parentObject)
949968
Common.getValueByPath(fromObject, new String[] {"explicitVadSignal"}));
950969
}
951970

971+
if (Common.getValueByPath(fromObject, new String[] {"avatarConfig"}) != null) {
972+
Common.setValueByPath(
973+
toObject,
974+
new String[] {"avatarConfig"},
975+
Common.getValueByPath(fromObject, new String[] {"avatarConfig"}));
976+
}
977+
978+
if (Common.getValueByPath(fromObject, new String[] {"safetySettings"}) != null) {
979+
Common.setValueByPath(
980+
toObject,
981+
new String[] {"safetySettings"},
982+
Common.getValueByPath(fromObject, new String[] {"safetySettings"}));
983+
}
984+
952985
return toObject;
953986
}
954987

@@ -1107,6 +1140,25 @@ ObjectNode liveConnectConfigToMldev(JsonNode fromObject, ObjectNode parentObject
11071140
"explicitVadSignal parameter is not supported in Gemini API.");
11081141
}
11091142

1143+
if (Common.getValueByPath(fromObject, new String[] {"avatarConfig"}) != null) {
1144+
Common.setValueByPath(
1145+
parentObject,
1146+
new String[] {"setup", "avatarConfig"},
1147+
Common.getValueByPath(fromObject, new String[] {"avatarConfig"}));
1148+
}
1149+
1150+
if (Common.getValueByPath(fromObject, new String[] {"safetySettings"}) != null) {
1151+
ArrayNode keyArray =
1152+
(ArrayNode) Common.getValueByPath(fromObject, new String[] {"safetySettings"});
1153+
ObjectMapper objectMapper = new ObjectMapper();
1154+
ArrayNode result = objectMapper.createArrayNode();
1155+
1156+
for (JsonNode item : keyArray) {
1157+
result.add(safetySettingToMldev(JsonSerializable.toJsonNode(item), toObject));
1158+
}
1159+
Common.setValueByPath(parentObject, new String[] {"setup", "safetySettings"}, result);
1160+
}
1161+
11101162
return toObject;
11111163
}
11121164

@@ -1261,6 +1313,20 @@ ObjectNode liveConnectConfigToVertex(JsonNode fromObject, ObjectNode parentObjec
12611313
Common.getValueByPath(fromObject, new String[] {"explicitVadSignal"}));
12621314
}
12631315

1316+
if (Common.getValueByPath(fromObject, new String[] {"avatarConfig"}) != null) {
1317+
Common.setValueByPath(
1318+
parentObject,
1319+
new String[] {"setup", "avatarConfig"},
1320+
Common.getValueByPath(fromObject, new String[] {"avatarConfig"}));
1321+
}
1322+
1323+
if (Common.getValueByPath(fromObject, new String[] {"safetySettings"}) != null) {
1324+
Common.setValueByPath(
1325+
parentObject,
1326+
new String[] {"setup", "safetySettings"},
1327+
Common.getValueByPath(fromObject, new String[] {"safetySettings"}));
1328+
}
1329+
12641330
return toObject;
12651331
}
12661332

@@ -1831,6 +1897,30 @@ ObjectNode replicatedVoiceConfigToVertex(JsonNode fromObject, ObjectNode parentO
18311897
return toObject;
18321898
}
18331899

1900+
@ExcludeFromGeneratedCoverageReport
1901+
ObjectNode safetySettingToMldev(JsonNode fromObject, ObjectNode parentObject) {
1902+
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
1903+
if (Common.getValueByPath(fromObject, new String[] {"category"}) != null) {
1904+
Common.setValueByPath(
1905+
toObject,
1906+
new String[] {"category"},
1907+
Common.getValueByPath(fromObject, new String[] {"category"}));
1908+
}
1909+
1910+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"method"}))) {
1911+
throw new IllegalArgumentException("method parameter is not supported in Gemini API.");
1912+
}
1913+
1914+
if (Common.getValueByPath(fromObject, new String[] {"threshold"}) != null) {
1915+
Common.setValueByPath(
1916+
toObject,
1917+
new String[] {"threshold"},
1918+
Common.getValueByPath(fromObject, new String[] {"threshold"}));
1919+
}
1920+
1921+
return toObject;
1922+
}
1923+
18341924
@ExcludeFromGeneratedCoverageReport
18351925
ObjectNode sessionResumptionConfigToMldev(JsonNode fromObject, ObjectNode parentObject) {
18361926
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,25 @@ ObjectNode liveConnectConfigToMldev(JsonNode fromObject, ObjectNode parentObject
469469
"explicitVadSignal parameter is not supported in Gemini API.");
470470
}
471471

472+
if (Common.getValueByPath(fromObject, new String[] {"avatarConfig"}) != null) {
473+
Common.setValueByPath(
474+
parentObject,
475+
new String[] {"setup", "avatarConfig"},
476+
Common.getValueByPath(fromObject, new String[] {"avatarConfig"}));
477+
}
478+
479+
if (Common.getValueByPath(fromObject, new String[] {"safetySettings"}) != null) {
480+
ArrayNode keyArray =
481+
(ArrayNode) Common.getValueByPath(fromObject, new String[] {"safetySettings"});
482+
ObjectMapper objectMapper = new ObjectMapper();
483+
ArrayNode result = objectMapper.createArrayNode();
484+
485+
for (JsonNode item : keyArray) {
486+
result.add(safetySettingToMldev(JsonSerializable.toJsonNode(item), toObject));
487+
}
488+
Common.setValueByPath(parentObject, new String[] {"setup", "safetySettings"}, result);
489+
}
490+
472491
return toObject;
473492
}
474493

@@ -610,6 +629,30 @@ ObjectNode partToMldev(JsonNode fromObject, ObjectNode parentObject) {
610629
return toObject;
611630
}
612631

632+
@ExcludeFromGeneratedCoverageReport
633+
ObjectNode safetySettingToMldev(JsonNode fromObject, ObjectNode parentObject) {
634+
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
635+
if (Common.getValueByPath(fromObject, new String[] {"category"}) != null) {
636+
Common.setValueByPath(
637+
toObject,
638+
new String[] {"category"},
639+
Common.getValueByPath(fromObject, new String[] {"category"}));
640+
}
641+
642+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"method"}))) {
643+
throw new IllegalArgumentException("method parameter is not supported in Gemini API.");
644+
}
645+
646+
if (Common.getValueByPath(fromObject, new String[] {"threshold"}) != null) {
647+
Common.setValueByPath(
648+
toObject,
649+
new String[] {"threshold"},
650+
Common.getValueByPath(fromObject, new String[] {"threshold"}));
651+
}
652+
653+
return toObject;
654+
}
655+
613656
@ExcludeFromGeneratedCoverageReport
614657
ObjectNode sessionResumptionConfigToMldev(JsonNode fromObject, ObjectNode parentObject) {
615658
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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.JsonProperty;
23+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
24+
import com.google.auto.value.AutoValue;
25+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
26+
import com.google.genai.JsonSerializable;
27+
import java.util.Optional;
28+
29+
/** Configures the avatar to be used in the session. */
30+
@AutoValue
31+
@JsonDeserialize(builder = AvatarConfig.Builder.class)
32+
public abstract class AvatarConfig extends JsonSerializable {
33+
/** Pre-built avatar id. */
34+
@JsonProperty("avatarName")
35+
public abstract Optional<String> avatarName();
36+
37+
/** Customized avatar appearance with a reference image. */
38+
@JsonProperty("customizedAvatar")
39+
public abstract Optional<CustomizedAvatar> customizedAvatar();
40+
41+
/** The bitrate of compressed audio. */
42+
@JsonProperty("audioBitrateBps")
43+
public abstract Optional<Integer> audioBitrateBps();
44+
45+
/** The bitrate of compressed video output. */
46+
@JsonProperty("videoBitrateBps")
47+
public abstract Optional<Integer> videoBitrateBps();
48+
49+
/** Instantiates a builder for AvatarConfig. */
50+
@ExcludeFromGeneratedCoverageReport
51+
public static Builder builder() {
52+
return new AutoValue_AvatarConfig.Builder();
53+
}
54+
55+
/** Creates a builder with the same values as this instance. */
56+
public abstract Builder toBuilder();
57+
58+
/** Builder for AvatarConfig. */
59+
@AutoValue.Builder
60+
public abstract static class Builder {
61+
/** For internal usage. Please use `AvatarConfig.builder()` for instantiation. */
62+
@JsonCreator
63+
private static Builder create() {
64+
return new AutoValue_AvatarConfig.Builder();
65+
}
66+
67+
/**
68+
* Setter for avatarName.
69+
*
70+
* <p>avatarName: Pre-built avatar id.
71+
*/
72+
@JsonProperty("avatarName")
73+
public abstract Builder avatarName(String avatarName);
74+
75+
@ExcludeFromGeneratedCoverageReport
76+
abstract Builder avatarName(Optional<String> avatarName);
77+
78+
/** Clears the value of avatarName field. */
79+
@ExcludeFromGeneratedCoverageReport
80+
@CanIgnoreReturnValue
81+
public Builder clearAvatarName() {
82+
return avatarName(Optional.empty());
83+
}
84+
85+
/**
86+
* Setter for customizedAvatar.
87+
*
88+
* <p>customizedAvatar: Customized avatar appearance with a reference image.
89+
*/
90+
@JsonProperty("customizedAvatar")
91+
public abstract Builder customizedAvatar(CustomizedAvatar customizedAvatar);
92+
93+
/**
94+
* Setter for customizedAvatar builder.
95+
*
96+
* <p>customizedAvatar: Customized avatar appearance with a reference image.
97+
*/
98+
@CanIgnoreReturnValue
99+
public Builder customizedAvatar(CustomizedAvatar.Builder customizedAvatarBuilder) {
100+
return customizedAvatar(customizedAvatarBuilder.build());
101+
}
102+
103+
@ExcludeFromGeneratedCoverageReport
104+
abstract Builder customizedAvatar(Optional<CustomizedAvatar> customizedAvatar);
105+
106+
/** Clears the value of customizedAvatar field. */
107+
@ExcludeFromGeneratedCoverageReport
108+
@CanIgnoreReturnValue
109+
public Builder clearCustomizedAvatar() {
110+
return customizedAvatar(Optional.empty());
111+
}
112+
113+
/**
114+
* Setter for audioBitrateBps.
115+
*
116+
* <p>audioBitrateBps: The bitrate of compressed audio.
117+
*/
118+
@JsonProperty("audioBitrateBps")
119+
public abstract Builder audioBitrateBps(Integer audioBitrateBps);
120+
121+
@ExcludeFromGeneratedCoverageReport
122+
abstract Builder audioBitrateBps(Optional<Integer> audioBitrateBps);
123+
124+
/** Clears the value of audioBitrateBps field. */
125+
@ExcludeFromGeneratedCoverageReport
126+
@CanIgnoreReturnValue
127+
public Builder clearAudioBitrateBps() {
128+
return audioBitrateBps(Optional.empty());
129+
}
130+
131+
/**
132+
* Setter for videoBitrateBps.
133+
*
134+
* <p>videoBitrateBps: The bitrate of compressed video output.
135+
*/
136+
@JsonProperty("videoBitrateBps")
137+
public abstract Builder videoBitrateBps(Integer videoBitrateBps);
138+
139+
@ExcludeFromGeneratedCoverageReport
140+
abstract Builder videoBitrateBps(Optional<Integer> videoBitrateBps);
141+
142+
/** Clears the value of videoBitrateBps field. */
143+
@ExcludeFromGeneratedCoverageReport
144+
@CanIgnoreReturnValue
145+
public Builder clearVideoBitrateBps() {
146+
return videoBitrateBps(Optional.empty());
147+
}
148+
149+
public abstract AvatarConfig build();
150+
}
151+
152+
/** Deserializes a JSON string to a AvatarConfig object. */
153+
@ExcludeFromGeneratedCoverageReport
154+
public static AvatarConfig fromJson(String jsonString) {
155+
return JsonSerializable.fromJsonString(jsonString, AvatarConfig.class);
156+
}
157+
}

0 commit comments

Comments
 (0)