Skip to content

Commit 8e8146a

Browse files
matthew29tangcopybara-github
authored andcommitted
feat: Add Live Avatar new fields
PiperOrigin-RevId: 897239647
1 parent 7e2ced0 commit 8e8146a

8 files changed

Lines changed: 628 additions & 2 deletions

File tree

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

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

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

@@ -946,6 +965,20 @@ ObjectNode liveClientSetupToVertex(JsonNode fromObject, ObjectNode parentObject)
946965
Common.getValueByPath(fromObject, new String[] {"explicitVadSignal"}));
947966
}
948967

968+
if (Common.getValueByPath(fromObject, new String[] {"avatarConfig"}) != null) {
969+
Common.setValueByPath(
970+
toObject,
971+
new String[] {"avatarConfig"},
972+
Common.getValueByPath(fromObject, new String[] {"avatarConfig"}));
973+
}
974+
975+
if (Common.getValueByPath(fromObject, new String[] {"safetySettings"}) != null) {
976+
Common.setValueByPath(
977+
toObject,
978+
new String[] {"safetySettings"},
979+
Common.getValueByPath(fromObject, new String[] {"safetySettings"}));
980+
}
981+
949982
return toObject;
950983
}
951984

@@ -1104,6 +1137,25 @@ ObjectNode liveConnectConfigToMldev(JsonNode fromObject, ObjectNode parentObject
11041137
"explicitVadSignal parameter is not supported in Gemini API.");
11051138
}
11061139

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

@@ -1255,6 +1307,20 @@ ObjectNode liveConnectConfigToVertex(JsonNode fromObject, ObjectNode parentObjec
12551307
Common.getValueByPath(fromObject, new String[] {"explicitVadSignal"}));
12561308
}
12571309

1310+
if (Common.getValueByPath(fromObject, new String[] {"avatarConfig"}) != null) {
1311+
Common.setValueByPath(
1312+
parentObject,
1313+
new String[] {"setup", "avatarConfig"},
1314+
Common.getValueByPath(fromObject, new String[] {"avatarConfig"}));
1315+
}
1316+
1317+
if (Common.getValueByPath(fromObject, new String[] {"safetySettings"}) != null) {
1318+
Common.setValueByPath(
1319+
parentObject,
1320+
new String[] {"setup", "safetySettings"},
1321+
Common.getValueByPath(fromObject, new String[] {"safetySettings"}));
1322+
}
1323+
12581324
return toObject;
12591325
}
12601326

@@ -1787,6 +1853,30 @@ ObjectNode partToVertex(JsonNode fromObject, ObjectNode parentObject) {
17871853
return toObject;
17881854
}
17891855

1856+
@ExcludeFromGeneratedCoverageReport
1857+
ObjectNode safetySettingToMldev(JsonNode fromObject, ObjectNode parentObject) {
1858+
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
1859+
if (Common.getValueByPath(fromObject, new String[] {"category"}) != null) {
1860+
Common.setValueByPath(
1861+
toObject,
1862+
new String[] {"category"},
1863+
Common.getValueByPath(fromObject, new String[] {"category"}));
1864+
}
1865+
1866+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"method"}))) {
1867+
throw new IllegalArgumentException("method parameter is not supported in Gemini API.");
1868+
}
1869+
1870+
if (Common.getValueByPath(fromObject, new String[] {"threshold"}) != null) {
1871+
Common.setValueByPath(
1872+
toObject,
1873+
new String[] {"threshold"},
1874+
Common.getValueByPath(fromObject, new String[] {"threshold"}));
1875+
}
1876+
1877+
return toObject;
1878+
}
1879+
17901880
@ExcludeFromGeneratedCoverageReport
17911881
ObjectNode sessionResumptionConfigToMldev(JsonNode fromObject, ObjectNode parentObject) {
17921882
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)