Skip to content

Commit 1a24bed

Browse files
hkt74copybara-github
authored andcommitted
feat: Add FunctionResponsePart & ToolComputerUse.excludedPredefinedFunctions
FunctionResponsePart could be used to support the computer use tool with browser screenshot PiperOrigin-RevId: 811412522
1 parent c293633 commit 1a24bed

File tree

9 files changed

+556
-0
lines changed

9 files changed

+556
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,6 +2245,13 @@ ObjectNode toolComputerUseToMldev(JsonNode fromObject, ObjectNode parentObject)
22452245
Common.getValueByPath(fromObject, new String[] {"environment"}));
22462246
}
22472247

2248+
if (Common.getValueByPath(fromObject, new String[] {"excludedPredefinedFunctions"}) != null) {
2249+
Common.setValueByPath(
2250+
toObject,
2251+
new String[] {"excludedPredefinedFunctions"},
2252+
Common.getValueByPath(fromObject, new String[] {"excludedPredefinedFunctions"}));
2253+
}
2254+
22482255
return toObject;
22492256
}
22502257

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,13 @@ ObjectNode toolComputerUseToMldev(JsonNode fromObject, ObjectNode parentObject)
14701470
Common.getValueByPath(fromObject, new String[] {"environment"}));
14711471
}
14721472

1473+
if (Common.getValueByPath(fromObject, new String[] {"excludedPredefinedFunctions"}) != null) {
1474+
Common.setValueByPath(
1475+
toObject,
1476+
new String[] {"excludedPredefinedFunctions"},
1477+
Common.getValueByPath(fromObject, new String[] {"excludedPredefinedFunctions"}));
1478+
}
1479+
14731480
return toObject;
14741481
}
14751482

@@ -1483,6 +1490,13 @@ ObjectNode toolComputerUseToVertex(JsonNode fromObject, ObjectNode parentObject)
14831490
Common.getValueByPath(fromObject, new String[] {"environment"}));
14841491
}
14851492

1493+
if (Common.getValueByPath(fromObject, new String[] {"excludedPredefinedFunctions"}) != null) {
1494+
Common.setValueByPath(
1495+
toObject,
1496+
new String[] {"excludedPredefinedFunctions"},
1497+
Common.getValueByPath(fromObject, new String[] {"excludedPredefinedFunctions"}));
1498+
}
1499+
14861500
return toObject;
14871501
}
14881502

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

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,138 @@ ObjectNode functionDeclarationToVertex(JsonNode fromObject, ObjectNode parentObj
818818
return toObject;
819819
}
820820

821+
@ExcludeFromGeneratedCoverageReport
822+
ObjectNode functionResponseBlobToMldev(JsonNode fromObject, ObjectNode parentObject) {
823+
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
824+
if (Common.getValueByPath(fromObject, new String[] {"mimeType"}) != null) {
825+
Common.setValueByPath(
826+
toObject,
827+
new String[] {"mimeType"},
828+
Common.getValueByPath(fromObject, new String[] {"mimeType"}));
829+
}
830+
831+
if (Common.getValueByPath(fromObject, new String[] {"data"}) != null) {
832+
Common.setValueByPath(
833+
toObject,
834+
new String[] {"data"},
835+
Common.getValueByPath(fromObject, new String[] {"data"}));
836+
}
837+
838+
return toObject;
839+
}
840+
841+
@ExcludeFromGeneratedCoverageReport
842+
ObjectNode functionResponseBlobToVertex(JsonNode fromObject, ObjectNode parentObject) {
843+
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
844+
if (Common.getValueByPath(fromObject, new String[] {"mimeType"}) != null) {
845+
Common.setValueByPath(
846+
toObject,
847+
new String[] {"mimeType"},
848+
Common.getValueByPath(fromObject, new String[] {"mimeType"}));
849+
}
850+
851+
if (Common.getValueByPath(fromObject, new String[] {"data"}) != null) {
852+
Common.setValueByPath(
853+
toObject,
854+
new String[] {"data"},
855+
Common.getValueByPath(fromObject, new String[] {"data"}));
856+
}
857+
858+
return toObject;
859+
}
860+
861+
@ExcludeFromGeneratedCoverageReport
862+
ObjectNode functionResponseFileDataToMldev(JsonNode fromObject, ObjectNode parentObject) {
863+
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
864+
if (Common.getValueByPath(fromObject, new String[] {"fileUri"}) != null) {
865+
Common.setValueByPath(
866+
toObject,
867+
new String[] {"fileUri"},
868+
Common.getValueByPath(fromObject, new String[] {"fileUri"}));
869+
}
870+
871+
if (Common.getValueByPath(fromObject, new String[] {"mimeType"}) != null) {
872+
Common.setValueByPath(
873+
toObject,
874+
new String[] {"mimeType"},
875+
Common.getValueByPath(fromObject, new String[] {"mimeType"}));
876+
}
877+
878+
return toObject;
879+
}
880+
881+
@ExcludeFromGeneratedCoverageReport
882+
ObjectNode functionResponseFileDataToVertex(JsonNode fromObject, ObjectNode parentObject) {
883+
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
884+
if (Common.getValueByPath(fromObject, new String[] {"fileUri"}) != null) {
885+
Common.setValueByPath(
886+
toObject,
887+
new String[] {"fileUri"},
888+
Common.getValueByPath(fromObject, new String[] {"fileUri"}));
889+
}
890+
891+
if (Common.getValueByPath(fromObject, new String[] {"mimeType"}) != null) {
892+
Common.setValueByPath(
893+
toObject,
894+
new String[] {"mimeType"},
895+
Common.getValueByPath(fromObject, new String[] {"mimeType"}));
896+
}
897+
898+
return toObject;
899+
}
900+
901+
@ExcludeFromGeneratedCoverageReport
902+
ObjectNode functionResponsePartToMldev(JsonNode fromObject, ObjectNode parentObject) {
903+
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
904+
if (Common.getValueByPath(fromObject, new String[] {"inlineData"}) != null) {
905+
Common.setValueByPath(
906+
toObject,
907+
new String[] {"inlineData"},
908+
functionResponseBlobToMldev(
909+
JsonSerializable.toJsonNode(
910+
Common.getValueByPath(fromObject, new String[] {"inlineData"})),
911+
toObject));
912+
}
913+
914+
if (Common.getValueByPath(fromObject, new String[] {"fileData"}) != null) {
915+
Common.setValueByPath(
916+
toObject,
917+
new String[] {"fileData"},
918+
functionResponseFileDataToMldev(
919+
JsonSerializable.toJsonNode(
920+
Common.getValueByPath(fromObject, new String[] {"fileData"})),
921+
toObject));
922+
}
923+
924+
return toObject;
925+
}
926+
927+
@ExcludeFromGeneratedCoverageReport
928+
ObjectNode functionResponsePartToVertex(JsonNode fromObject, ObjectNode parentObject) {
929+
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
930+
if (Common.getValueByPath(fromObject, new String[] {"inlineData"}) != null) {
931+
Common.setValueByPath(
932+
toObject,
933+
new String[] {"inlineData"},
934+
functionResponseBlobToVertex(
935+
JsonSerializable.toJsonNode(
936+
Common.getValueByPath(fromObject, new String[] {"inlineData"})),
937+
toObject));
938+
}
939+
940+
if (Common.getValueByPath(fromObject, new String[] {"fileData"}) != null) {
941+
Common.setValueByPath(
942+
toObject,
943+
new String[] {"fileData"},
944+
functionResponseFileDataToVertex(
945+
JsonSerializable.toJsonNode(
946+
Common.getValueByPath(fromObject, new String[] {"fileData"})),
947+
toObject));
948+
}
949+
950+
return toObject;
951+
}
952+
821953
@ExcludeFromGeneratedCoverageReport
822954
ObjectNode functionResponseToMldev(JsonNode fromObject, ObjectNode parentObject) {
823955
ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode();
@@ -835,6 +967,17 @@ ObjectNode functionResponseToMldev(JsonNode fromObject, ObjectNode parentObject)
835967
Common.getValueByPath(fromObject, new String[] {"scheduling"}));
836968
}
837969

970+
if (Common.getValueByPath(fromObject, new String[] {"parts"}) != null) {
971+
ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"parts"});
972+
ObjectMapper objectMapper = new ObjectMapper();
973+
ArrayNode result = objectMapper.createArrayNode();
974+
975+
for (JsonNode item : keyArray) {
976+
result.add(functionResponsePartToMldev(JsonSerializable.toJsonNode(item), toObject));
977+
}
978+
Common.setValueByPath(toObject, new String[] {"parts"}, result);
979+
}
980+
838981
if (Common.getValueByPath(fromObject, new String[] {"id"}) != null) {
839982
Common.setValueByPath(
840983
toObject, new String[] {"id"}, Common.getValueByPath(fromObject, new String[] {"id"}));
@@ -868,6 +1011,17 @@ ObjectNode functionResponseToVertex(JsonNode fromObject, ObjectNode parentObject
8681011
throw new IllegalArgumentException("scheduling parameter is not supported in Vertex AI.");
8691012
}
8701013

1014+
if (Common.getValueByPath(fromObject, new String[] {"parts"}) != null) {
1015+
ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"parts"});
1016+
ObjectMapper objectMapper = new ObjectMapper();
1017+
ArrayNode result = objectMapper.createArrayNode();
1018+
1019+
for (JsonNode item : keyArray) {
1020+
result.add(functionResponsePartToVertex(JsonSerializable.toJsonNode(item), toObject));
1021+
}
1022+
Common.setValueByPath(toObject, new String[] {"parts"}, result);
1023+
}
1024+
8711025
if (Common.getValueByPath(fromObject, new String[] {"id"}) != null) {
8721026
Common.setValueByPath(
8731027
toObject, new String[] {"id"}, Common.getValueByPath(fromObject, new String[] {"id"}));
@@ -3206,6 +3360,13 @@ ObjectNode toolComputerUseToMldev(JsonNode fromObject, ObjectNode parentObject)
32063360
Common.getValueByPath(fromObject, new String[] {"environment"}));
32073361
}
32083362

3363+
if (Common.getValueByPath(fromObject, new String[] {"excludedPredefinedFunctions"}) != null) {
3364+
Common.setValueByPath(
3365+
toObject,
3366+
new String[] {"excludedPredefinedFunctions"},
3367+
Common.getValueByPath(fromObject, new String[] {"excludedPredefinedFunctions"}));
3368+
}
3369+
32093370
return toObject;
32103371
}
32113372

@@ -3219,6 +3380,13 @@ ObjectNode toolComputerUseToVertex(JsonNode fromObject, ObjectNode parentObject)
32193380
Common.getValueByPath(fromObject, new String[] {"environment"}));
32203381
}
32213382

3383+
if (Common.getValueByPath(fromObject, new String[] {"excludedPredefinedFunctions"}) != null) {
3384+
Common.setValueByPath(
3385+
toObject,
3386+
new String[] {"excludedPredefinedFunctions"},
3387+
Common.getValueByPath(fromObject, new String[] {"excludedPredefinedFunctions"}));
3388+
}
3389+
32223390
return toObject;
32233391
}
32243392

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5602,6 +5602,13 @@ ObjectNode toolComputerUseToMldev(JsonNode fromObject, ObjectNode parentObject)
56025602
Common.getValueByPath(fromObject, new String[] {"environment"}));
56035603
}
56045604

5605+
if (Common.getValueByPath(fromObject, new String[] {"excludedPredefinedFunctions"}) != null) {
5606+
Common.setValueByPath(
5607+
toObject,
5608+
new String[] {"excludedPredefinedFunctions"},
5609+
Common.getValueByPath(fromObject, new String[] {"excludedPredefinedFunctions"}));
5610+
}
5611+
56055612
return toObject;
56065613
}
56075614

@@ -5615,6 +5622,13 @@ ObjectNode toolComputerUseToVertex(JsonNode fromObject, ObjectNode parentObject)
56155622
Common.getValueByPath(fromObject, new String[] {"environment"}));
56165623
}
56175624

5625+
if (Common.getValueByPath(fromObject, new String[] {"excludedPredefinedFunctions"}) != null) {
5626+
Common.setValueByPath(
5627+
toObject,
5628+
new String[] {"excludedPredefinedFunctions"},
5629+
Common.getValueByPath(fromObject, new String[] {"excludedPredefinedFunctions"}));
5630+
}
5631+
56185632
return toObject;
56195633
}
56205634

src/main/java/com/google/genai/types/FunctionResponse.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818

1919
package com.google.genai.types;
2020

21+
import static com.google.common.collect.ImmutableList.toImmutableList;
22+
2123
import com.fasterxml.jackson.annotation.JsonCreator;
2224
import com.fasterxml.jackson.annotation.JsonProperty;
2325
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2426
import com.google.auto.value.AutoValue;
2527
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2628
import com.google.genai.JsonSerializable;
29+
import java.util.Arrays;
30+
import java.util.List;
2731
import java.util.Map;
2832
import java.util.Optional;
2933

@@ -49,6 +53,13 @@ public abstract class FunctionResponse extends JsonSerializable {
4953
@JsonProperty("scheduling")
5054
public abstract Optional<FunctionResponseScheduling> scheduling();
5155

56+
/**
57+
* List of parts that constitute a function response. Each part may have a different IANA MIME
58+
* type.
59+
*/
60+
@JsonProperty("parts")
61+
public abstract Optional<List<FunctionResponsePart>> parts();
62+
5263
/**
5364
* Optional. The id of the function call this response is for. Populated by the client to match
5465
* the corresponding function call `id`.
@@ -134,6 +145,38 @@ public Builder scheduling(String scheduling) {
134145
return scheduling(new FunctionResponseScheduling(scheduling));
135146
}
136147

148+
/**
149+
* Setter for parts.
150+
*
151+
* <p>parts: List of parts that constitute a function response. Each part may have a different
152+
* IANA MIME type.
153+
*/
154+
@JsonProperty("parts")
155+
public abstract Builder parts(List<FunctionResponsePart> parts);
156+
157+
/**
158+
* Setter for parts.
159+
*
160+
* <p>parts: List of parts that constitute a function response. Each part may have a different
161+
* IANA MIME type.
162+
*/
163+
public Builder parts(FunctionResponsePart... parts) {
164+
return parts(Arrays.asList(parts));
165+
}
166+
167+
/**
168+
* Setter for parts builder.
169+
*
170+
* <p>parts: List of parts that constitute a function response. Each part may have a different
171+
* IANA MIME type.
172+
*/
173+
public Builder parts(FunctionResponsePart.Builder... partsBuilders) {
174+
return parts(
175+
Arrays.asList(partsBuilders).stream()
176+
.map(FunctionResponsePart.Builder::build)
177+
.collect(toImmutableList()));
178+
}
179+
137180
/**
138181
* Setter for id.
139182
*

0 commit comments

Comments
 (0)