Skip to content

Commit 38703c7

Browse files
wanlin31copybara-github
authored andcommitted
feat: generate the function_call class's converters
PiperOrigin-RevId: 804427760
1 parent cad8df9 commit 38703c7

File tree

5 files changed

+438
-156
lines changed

5 files changed

+438
-156
lines changed

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

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,31 @@ ObjectNode fileDataToMldev(JsonNode fromObject, ObjectNode parentObject) {
131131
return toObject;
132132
}
133133

134+
@ExcludeFromGeneratedCoverageReport
135+
ObjectNode functionCallToMldev(JsonNode fromObject, ObjectNode parentObject) {
136+
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
137+
if (Common.getValueByPath(fromObject, new String[] {"id"}) != null) {
138+
Common.setValueByPath(
139+
toObject, new String[] {"id"}, Common.getValueByPath(fromObject, new String[] {"id"}));
140+
}
141+
142+
if (Common.getValueByPath(fromObject, new String[] {"args"}) != null) {
143+
Common.setValueByPath(
144+
toObject,
145+
new String[] {"args"},
146+
Common.getValueByPath(fromObject, new String[] {"args"}));
147+
}
148+
149+
if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) {
150+
Common.setValueByPath(
151+
toObject,
152+
new String[] {"name"},
153+
Common.getValueByPath(fromObject, new String[] {"name"}));
154+
}
155+
156+
return toObject;
157+
}
158+
134159
@ExcludeFromGeneratedCoverageReport
135160
ObjectNode partToMldev(JsonNode fromObject, ObjectNode parentObject) {
136161
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
@@ -178,6 +203,16 @@ ObjectNode partToMldev(JsonNode fromObject, ObjectNode parentObject) {
178203
Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}));
179204
}
180205

206+
if (Common.getValueByPath(fromObject, new String[] {"functionCall"}) != null) {
207+
Common.setValueByPath(
208+
toObject,
209+
new String[] {"functionCall"},
210+
functionCallToMldev(
211+
JsonSerializable.toJsonNode(
212+
Common.getValueByPath(fromObject, new String[] {"functionCall"})),
213+
toObject));
214+
}
215+
181216
if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) {
182217
Common.setValueByPath(
183218
toObject,
@@ -192,13 +227,6 @@ ObjectNode partToMldev(JsonNode fromObject, ObjectNode parentObject) {
192227
Common.getValueByPath(fromObject, new String[] {"executableCode"}));
193228
}
194229

195-
if (Common.getValueByPath(fromObject, new String[] {"functionCall"}) != null) {
196-
Common.setValueByPath(
197-
toObject,
198-
new String[] {"functionCall"},
199-
Common.getValueByPath(fromObject, new String[] {"functionCall"}));
200-
}
201-
202230
if (Common.getValueByPath(fromObject, new String[] {"functionResponse"}) != null) {
203231
Common.setValueByPath(
204232
toObject,
@@ -1633,6 +1661,31 @@ ObjectNode fileDataFromMldev(JsonNode fromObject, ObjectNode parentObject) {
16331661
return toObject;
16341662
}
16351663

1664+
@ExcludeFromGeneratedCoverageReport
1665+
ObjectNode functionCallFromMldev(JsonNode fromObject, ObjectNode parentObject) {
1666+
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
1667+
if (Common.getValueByPath(fromObject, new String[] {"id"}) != null) {
1668+
Common.setValueByPath(
1669+
toObject, new String[] {"id"}, Common.getValueByPath(fromObject, new String[] {"id"}));
1670+
}
1671+
1672+
if (Common.getValueByPath(fromObject, new String[] {"args"}) != null) {
1673+
Common.setValueByPath(
1674+
toObject,
1675+
new String[] {"args"},
1676+
Common.getValueByPath(fromObject, new String[] {"args"}));
1677+
}
1678+
1679+
if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) {
1680+
Common.setValueByPath(
1681+
toObject,
1682+
new String[] {"name"},
1683+
Common.getValueByPath(fromObject, new String[] {"name"}));
1684+
}
1685+
1686+
return toObject;
1687+
}
1688+
16361689
@ExcludeFromGeneratedCoverageReport
16371690
ObjectNode partFromMldev(JsonNode fromObject, ObjectNode parentObject) {
16381691
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
@@ -1680,6 +1733,16 @@ ObjectNode partFromMldev(JsonNode fromObject, ObjectNode parentObject) {
16801733
Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}));
16811734
}
16821735

1736+
if (Common.getValueByPath(fromObject, new String[] {"functionCall"}) != null) {
1737+
Common.setValueByPath(
1738+
toObject,
1739+
new String[] {"functionCall"},
1740+
functionCallFromMldev(
1741+
JsonSerializable.toJsonNode(
1742+
Common.getValueByPath(fromObject, new String[] {"functionCall"})),
1743+
toObject));
1744+
}
1745+
16831746
if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) {
16841747
Common.setValueByPath(
16851748
toObject,
@@ -1694,13 +1757,6 @@ ObjectNode partFromMldev(JsonNode fromObject, ObjectNode parentObject) {
16941757
Common.getValueByPath(fromObject, new String[] {"executableCode"}));
16951758
}
16961759

1697-
if (Common.getValueByPath(fromObject, new String[] {"functionCall"}) != null) {
1698-
Common.setValueByPath(
1699-
toObject,
1700-
new String[] {"functionCall"},
1701-
Common.getValueByPath(fromObject, new String[] {"functionCall"}));
1702-
}
1703-
17041760
if (Common.getValueByPath(fromObject, new String[] {"functionResponse"}) != null) {
17051761
Common.setValueByPath(
17061762
toObject,

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

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,31 @@ ObjectNode fileDataToMldev(JsonNode fromObject, ObjectNode parentObject) {
131131
return toObject;
132132
}
133133

134+
@ExcludeFromGeneratedCoverageReport
135+
ObjectNode functionCallToMldev(JsonNode fromObject, ObjectNode parentObject) {
136+
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
137+
if (Common.getValueByPath(fromObject, new String[] {"id"}) != null) {
138+
Common.setValueByPath(
139+
toObject, new String[] {"id"}, Common.getValueByPath(fromObject, new String[] {"id"}));
140+
}
141+
142+
if (Common.getValueByPath(fromObject, new String[] {"args"}) != null) {
143+
Common.setValueByPath(
144+
toObject,
145+
new String[] {"args"},
146+
Common.getValueByPath(fromObject, new String[] {"args"}));
147+
}
148+
149+
if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) {
150+
Common.setValueByPath(
151+
toObject,
152+
new String[] {"name"},
153+
Common.getValueByPath(fromObject, new String[] {"name"}));
154+
}
155+
156+
return toObject;
157+
}
158+
134159
@ExcludeFromGeneratedCoverageReport
135160
ObjectNode partToMldev(JsonNode fromObject, ObjectNode parentObject) {
136161
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
@@ -178,6 +203,16 @@ ObjectNode partToMldev(JsonNode fromObject, ObjectNode parentObject) {
178203
Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}));
179204
}
180205

206+
if (Common.getValueByPath(fromObject, new String[] {"functionCall"}) != null) {
207+
Common.setValueByPath(
208+
toObject,
209+
new String[] {"functionCall"},
210+
functionCallToMldev(
211+
JsonSerializable.toJsonNode(
212+
Common.getValueByPath(fromObject, new String[] {"functionCall"})),
213+
toObject));
214+
}
215+
181216
if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) {
182217
Common.setValueByPath(
183218
toObject,
@@ -192,13 +227,6 @@ ObjectNode partToMldev(JsonNode fromObject, ObjectNode parentObject) {
192227
Common.getValueByPath(fromObject, new String[] {"executableCode"}));
193228
}
194229

195-
if (Common.getValueByPath(fromObject, new String[] {"functionCall"}) != null) {
196-
Common.setValueByPath(
197-
toObject,
198-
new String[] {"functionCall"},
199-
Common.getValueByPath(fromObject, new String[] {"functionCall"}));
200-
}
201-
202230
if (Common.getValueByPath(fromObject, new String[] {"functionResponse"}) != null) {
203231
Common.setValueByPath(
204232
toObject,
@@ -867,6 +895,30 @@ ObjectNode fileDataToVertex(JsonNode fromObject, ObjectNode parentObject) {
867895
return toObject;
868896
}
869897

898+
@ExcludeFromGeneratedCoverageReport
899+
ObjectNode functionCallToVertex(JsonNode fromObject, ObjectNode parentObject) {
900+
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
901+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"id"}))) {
902+
throw new IllegalArgumentException("id parameter is not supported in Vertex AI.");
903+
}
904+
905+
if (Common.getValueByPath(fromObject, new String[] {"args"}) != null) {
906+
Common.setValueByPath(
907+
toObject,
908+
new String[] {"args"},
909+
Common.getValueByPath(fromObject, new String[] {"args"}));
910+
}
911+
912+
if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) {
913+
Common.setValueByPath(
914+
toObject,
915+
new String[] {"name"},
916+
Common.getValueByPath(fromObject, new String[] {"name"}));
917+
}
918+
919+
return toObject;
920+
}
921+
870922
@ExcludeFromGeneratedCoverageReport
871923
ObjectNode partToVertex(JsonNode fromObject, ObjectNode parentObject) {
872924
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
@@ -914,6 +966,16 @@ ObjectNode partToVertex(JsonNode fromObject, ObjectNode parentObject) {
914966
Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}));
915967
}
916968

969+
if (Common.getValueByPath(fromObject, new String[] {"functionCall"}) != null) {
970+
Common.setValueByPath(
971+
toObject,
972+
new String[] {"functionCall"},
973+
functionCallToVertex(
974+
JsonSerializable.toJsonNode(
975+
Common.getValueByPath(fromObject, new String[] {"functionCall"})),
976+
toObject));
977+
}
978+
917979
if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) {
918980
Common.setValueByPath(
919981
toObject,
@@ -928,13 +990,6 @@ ObjectNode partToVertex(JsonNode fromObject, ObjectNode parentObject) {
928990
Common.getValueByPath(fromObject, new String[] {"executableCode"}));
929991
}
930992

931-
if (Common.getValueByPath(fromObject, new String[] {"functionCall"}) != null) {
932-
Common.setValueByPath(
933-
toObject,
934-
new String[] {"functionCall"},
935-
Common.getValueByPath(fromObject, new String[] {"functionCall"}));
936-
}
937-
938993
if (Common.getValueByPath(fromObject, new String[] {"functionResponse"}) != null) {
939994
Common.setValueByPath(
940995
toObject,

0 commit comments

Comments
 (0)