Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Google.GenAI/Batches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,16 @@ internal JsonNode PartToMldev(JsonNode fromObject, JsonObject parentObject) {
Common.GetValueByPath(fromObject, new string[] { "videoMetadata" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "toolCall" }) != null) {
Common.SetValueByPath(toObject, new string[] { "toolCall" },
Common.GetValueByPath(fromObject, new string[] { "toolCall" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "toolResponse" }) != null) {
Common.SetValueByPath(toObject, new string[] { "toolResponse" },
Common.GetValueByPath(fromObject, new string[] { "toolResponse" }));
}

return toObject;
}

Expand Down Expand Up @@ -1569,6 +1579,13 @@ internal JsonNode ToolConfigToMldev(JsonNode fromObject, JsonObject parentObject
toObject));
}

if (Common.GetValueByPath(fromObject, new string[] { "includeServerSideToolInvocations" }) !=
null) {
Common.SetValueByPath(
toObject, new string[] { "includeServerSideToolInvocations" },
Common.GetValueByPath(fromObject, new string[] { "includeServerSideToolInvocations" }));
}

return toObject;
}

Expand Down
162 changes: 154 additions & 8 deletions Google.GenAI/Caches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ internal JsonNode ContentToMldev(JsonNode fromObject, JsonObject parentObject) {
return toObject;
}

internal JsonNode ContentToVertex(JsonNode fromObject, JsonObject parentObject) {
JsonObject toObject = new JsonObject();

if (Common.GetValueByPath(fromObject, new string[] { "parts" }) != null) {
JsonArray keyArray = (JsonArray)Common.GetValueByPath(fromObject, new string[] { "parts" });
JsonArray result = new JsonArray();

foreach (var record in keyArray) {
result.Add(PartToVertex(JsonNode.Parse(JsonSerializer.Serialize(record)), toObject));
}
Common.SetValueByPath(toObject, new string[] { "parts" }, result);
}

if (Common.GetValueByPath(fromObject, new string[] { "role" }) != null) {
Common.SetValueByPath(toObject, new string[] { "role" },
Common.GetValueByPath(fromObject, new string[] { "role" }));
}

return toObject;
}

internal JsonNode CreateCachedContentConfigToMldev(JsonNode fromObject,
JsonObject parentObject) {
JsonObject toObject = new JsonObject();
Expand Down Expand Up @@ -193,15 +214,23 @@ internal JsonNode CreateCachedContentConfigToVertex(JsonNode fromObject,
}

if (Common.GetValueByPath(fromObject, new string[] { "contents" }) != null) {
Common.SetValueByPath(
parentObject, new string[] { "contents" },
Transformers.TContents(Common.GetValueByPath(fromObject, new string[] { "contents" })));
var keyList =
Transformers.TContents(Common.GetValueByPath(fromObject, new string[] { "contents" }));
JsonArray result = new JsonArray();

foreach (var record in keyList) {
result.Add(ContentToVertex(JsonNode.Parse(JsonSerializer.Serialize(record)), toObject));
}
Common.SetValueByPath(parentObject, new string[] { "contents" }, result);
}

if (Common.GetValueByPath(fromObject, new string[] { "systemInstruction" }) != null) {
Common.SetValueByPath(parentObject, new string[] { "systemInstruction" },
Transformers.TContent(Common.GetValueByPath(
fromObject, new string[] { "systemInstruction" })));
Common.SetValueByPath(
parentObject, new string[] { "systemInstruction" },
ContentToVertex(
JsonNode.Parse(JsonSerializer.Serialize(Transformers.TContent(
Common.GetValueByPath(fromObject, new string[] { "systemInstruction" })))),
toObject));
}

if (Common.GetValueByPath(fromObject, new string[] { "tools" }) != null) {
Expand All @@ -215,8 +244,11 @@ internal JsonNode CreateCachedContentConfigToVertex(JsonNode fromObject,
}

if (Common.GetValueByPath(fromObject, new string[] { "toolConfig" }) != null) {
Common.SetValueByPath(parentObject, new string[] { "toolConfig" },
Common.GetValueByPath(fromObject, new string[] { "toolConfig" }));
Common.SetValueByPath(
parentObject, new string[] { "toolConfig" },
ToolConfigToVertex(JsonNode.Parse(JsonSerializer.Serialize(Common.GetValueByPath(
fromObject, new string[] { "toolConfig" }))),
toObject));
}

if (Common.GetValueByPath(fromObject, new string[] { "kmsKeyName" }) != null) {
Expand Down Expand Up @@ -706,6 +738,89 @@ internal JsonNode PartToMldev(JsonNode fromObject, JsonObject parentObject) {
Common.GetValueByPath(fromObject, new string[] { "videoMetadata" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "toolCall" }) != null) {
Common.SetValueByPath(toObject, new string[] { "toolCall" },
Common.GetValueByPath(fromObject, new string[] { "toolCall" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "toolResponse" }) != null) {
Common.SetValueByPath(toObject, new string[] { "toolResponse" },
Common.GetValueByPath(fromObject, new string[] { "toolResponse" }));
}

return toObject;
}

internal JsonNode PartToVertex(JsonNode fromObject, JsonObject parentObject) {
JsonObject toObject = new JsonObject();

if (Common.GetValueByPath(fromObject, new string[] { "mediaResolution" }) != null) {
Common.SetValueByPath(
toObject, new string[] { "mediaResolution" },
Common.GetValueByPath(fromObject, new string[] { "mediaResolution" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "codeExecutionResult" }) != null) {
Common.SetValueByPath(
toObject, new string[] { "codeExecutionResult" },
Common.GetValueByPath(fromObject, new string[] { "codeExecutionResult" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "executableCode" }) != null) {
Common.SetValueByPath(toObject, new string[] { "executableCode" },
Common.GetValueByPath(fromObject, new string[] { "executableCode" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "fileData" }) != null) {
Common.SetValueByPath(toObject, new string[] { "fileData" },
Common.GetValueByPath(fromObject, new string[] { "fileData" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "functionCall" }) != null) {
Common.SetValueByPath(toObject, new string[] { "functionCall" },
Common.GetValueByPath(fromObject, new string[] { "functionCall" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "functionResponse" }) != null) {
Common.SetValueByPath(
toObject, new string[] { "functionResponse" },
Common.GetValueByPath(fromObject, new string[] { "functionResponse" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "inlineData" }) != null) {
Common.SetValueByPath(toObject, new string[] { "inlineData" },
Common.GetValueByPath(fromObject, new string[] { "inlineData" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "text" }) != null) {
Common.SetValueByPath(toObject, new string[] { "text" },
Common.GetValueByPath(fromObject, new string[] { "text" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "thought" }) != null) {
Common.SetValueByPath(toObject, new string[] { "thought" },
Common.GetValueByPath(fromObject, new string[] { "thought" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "thoughtSignature" }) != null) {
Common.SetValueByPath(
toObject, new string[] { "thoughtSignature" },
Common.GetValueByPath(fromObject, new string[] { "thoughtSignature" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "videoMetadata" }) != null) {
Common.SetValueByPath(toObject, new string[] { "videoMetadata" },
Common.GetValueByPath(fromObject, new string[] { "videoMetadata" }));
}

if (!Common.IsZero(Common.GetValueByPath(fromObject, new string[] { "toolCall" }))) {
throw new NotSupportedException("toolCall parameter is not supported in Vertex AI.");
}

if (!Common.IsZero(Common.GetValueByPath(fromObject, new string[] { "toolResponse" }))) {
throw new NotSupportedException("toolResponse parameter is not supported in Vertex AI.");
}

return toObject;
}

Expand All @@ -726,6 +841,37 @@ internal JsonNode ToolConfigToMldev(JsonNode fromObject, JsonObject parentObject
toObject));
}

if (Common.GetValueByPath(fromObject, new string[] { "includeServerSideToolInvocations" }) !=
null) {
Common.SetValueByPath(
toObject, new string[] { "includeServerSideToolInvocations" },
Common.GetValueByPath(fromObject, new string[] { "includeServerSideToolInvocations" }));
}

return toObject;
}

internal JsonNode ToolConfigToVertex(JsonNode fromObject, JsonObject parentObject) {
JsonObject toObject = new JsonObject();

if (Common.GetValueByPath(fromObject, new string[] { "retrievalConfig" }) != null) {
Common.SetValueByPath(
toObject, new string[] { "retrievalConfig" },
Common.GetValueByPath(fromObject, new string[] { "retrievalConfig" }));
}

if (Common.GetValueByPath(fromObject, new string[] { "functionCallingConfig" }) != null) {
Common.SetValueByPath(
toObject, new string[] { "functionCallingConfig" },
Common.GetValueByPath(fromObject, new string[] { "functionCallingConfig" }));
}

if (!Common.IsZero(Common.GetValueByPath(
fromObject, new string[] { "includeServerSideToolInvocations" }))) {
throw new NotSupportedException(
"includeServerSideToolInvocations parameter is not supported in Vertex AI.");
}

return toObject;
}

Expand Down
Loading
Loading