diff --git a/Google.GenAI/Batches.cs b/Google.GenAI/Batches.cs index 8d22580d..881f0295 100644 --- a/Google.GenAI/Batches.cs +++ b/Google.GenAI/Batches.cs @@ -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; } @@ -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; } diff --git a/Google.GenAI/Caches.cs b/Google.GenAI/Caches.cs index b7535dff..02b40700 100644 --- a/Google.GenAI/Caches.cs +++ b/Google.GenAI/Caches.cs @@ -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(); @@ -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) { @@ -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) { @@ -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; } @@ -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; } diff --git a/Google.GenAI/LiveConverters.cs b/Google.GenAI/LiveConverters.cs index 91c200fa..773c3d8b 100644 --- a/Google.GenAI/LiveConverters.cs +++ b/Google.GenAI/LiveConverters.cs @@ -122,6 +122,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 FileDataToMldev(JsonNode fromObject, JsonObject parentObject) { JsonObject toObject = new JsonObject(); @@ -426,6 +447,27 @@ internal JsonNode LiveClientContentToMldev(JsonNode fromObject, JsonObject paren return toObject; } + internal JsonNode LiveClientContentToVertex(JsonNode fromObject, JsonObject parentObject) { + JsonObject toObject = new JsonObject(); + + if (Common.GetValueByPath(fromObject, new string[] { "turns" }) != null) { + JsonArray keyArray = (JsonArray)Common.GetValueByPath(fromObject, new string[] { "turns" }); + JsonArray result = new JsonArray(); + + foreach (var record in keyArray) { + result.Add(ContentToVertex(JsonNode.Parse(JsonSerializer.Serialize(record)), toObject)); + } + Common.SetValueByPath(toObject, new string[] { "turns" }, result); + } + + if (Common.GetValueByPath(fromObject, new string[] { "turnComplete" }) != null) { + Common.SetValueByPath(toObject, new string[] { "turnComplete" }, + Common.GetValueByPath(fromObject, new string[] { "turnComplete" })); + } + + return toObject; + } + internal JsonNode LiveClientMessageToMldev(JsonNode fromObject, JsonObject parentObject) { JsonObject toObject = new JsonObject(); @@ -481,8 +523,11 @@ internal JsonNode LiveClientMessageToVertex(JsonNode fromObject, JsonObject pare } if (Common.GetValueByPath(fromObject, new string[] { "clientContent" }) != null) { - Common.SetValueByPath(toObject, new string[] { "clientContent" }, - Common.GetValueByPath(fromObject, new string[] { "clientContent" })); + Common.SetValueByPath( + toObject, new string[] { "clientContent" }, + LiveClientContentToVertex(JsonNode.Parse(JsonSerializer.Serialize(Common.GetValueByPath( + fromObject, new string[] { "clientContent" }))), + toObject)); } if (Common.GetValueByPath(fromObject, new string[] { "realtimeInput" }) != null) { @@ -704,9 +749,12 @@ internal JsonNode LiveClientSetupToVertex(JsonNode fromObject, JsonObject parent } if (Common.GetValueByPath(fromObject, new string[] { "systemInstruction" }) != null) { - Common.SetValueByPath(toObject, new string[] { "systemInstruction" }, - Transformers.TContent(Common.GetValueByPath( - fromObject, new string[] { "systemInstruction" }))); + Common.SetValueByPath( + toObject, 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) { @@ -972,9 +1020,12 @@ internal JsonNode LiveConnectConfigToVertex(JsonNode fromObject, JsonObject pare } if (Common.GetValueByPath(fromObject, new string[] { "systemInstruction" }) != null) { - Common.SetValueByPath(parentObject, new string[] { "setup", "systemInstruction" }, - Transformers.TContent(Common.GetValueByPath( - fromObject, new string[] { "systemInstruction" }))); + Common.SetValueByPath( + parentObject, new string[] { "setup", "systemInstruction" }, + ContentToVertex( + JsonNode.Parse(JsonSerializer.Serialize(Transformers.TContent( + Common.GetValueByPath(fromObject, new string[] { "systemInstruction" })))), + toObject)); } if (Common.GetValueByPath(fromObject, new string[] { "tools" }) != null) { @@ -1366,6 +1417,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; } diff --git a/Google.GenAI/Models.cs b/Google.GenAI/Models.cs index 63a126c2..4d83afd2 100644 --- a/Google.GenAI/Models.cs +++ b/Google.GenAI/Models.cs @@ -183,9 +183,15 @@ internal JsonNode ComputeTokensParametersToVertex(ApiClient apiClient, JsonNode } if (Common.GetValueByPath(fromObject, new string[] { "contents" }) != null) { - Common.SetValueByPath( - toObject, 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, + rootObject)); + } + Common.SetValueByPath(toObject, new string[] { "contents" }, result); } return toObject; @@ -270,6 +276,29 @@ internal JsonNode ContentToMldev(JsonNode fromObject, JsonObject parentObject, return toObject; } + internal JsonNode ContentToVertex(JsonNode fromObject, JsonObject parentObject, + JsonNode rootObject) { + 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, rootObject)); + } + 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 ControlReferenceConfigToVertex(JsonNode fromObject, JsonObject parentObject, JsonNode rootObject) { JsonObject toObject = new JsonObject(); @@ -315,9 +344,12 @@ internal JsonNode CountTokensConfigToVertex(JsonNode fromObject, JsonObject pare JsonObject toObject = new JsonObject(); 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, rootObject)); } if (Common.GetValueByPath(fromObject, new string[] { "tools" }) != null) { @@ -386,9 +418,15 @@ internal JsonNode CountTokensParametersToVertex(ApiClient apiClient, JsonNode fr } if (Common.GetValueByPath(fromObject, new string[] { "contents" }) != null) { - Common.SetValueByPath( - toObject, 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, + rootObject)); + } + Common.SetValueByPath(toObject, new string[] { "contents" }, result); } if (Common.GetValueByPath(fromObject, new string[] { "config" }) != null) { @@ -848,7 +886,9 @@ internal JsonNode EmbedContentParametersPrivateToVertex(ApiClient apiClient, if (Common.GetValueByPath(fromObject, new string[] { "content" }) != null) { Common.SetValueByPath( toObject, new string[] { "content" }, - Transformers.TContent(Common.GetValueByPath(fromObject, new string[] { "content" }))); + ContentToVertex(JsonNode.Parse(JsonSerializer.Serialize(Transformers.TContent( + Common.GetValueByPath(fromObject, new string[] { "content" })))), + toObject, rootObject)); } } @@ -1292,9 +1332,12 @@ internal JsonNode GenerateContentConfigToVertex(ApiClient apiClient, JsonNode fr JsonObject toObject = new JsonObject(); 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, rootObject)); } if (Common.GetValueByPath(fromObject, new string[] { "temperature" }) != null) { @@ -1404,8 +1447,11 @@ internal JsonNode GenerateContentConfigToVertex(ApiClient apiClient, JsonNode fr } 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, rootObject)); } if (Common.GetValueByPath(fromObject, new string[] { "labels" }) != null) { @@ -1521,9 +1567,15 @@ internal JsonNode GenerateContentParametersToVertex(ApiClient apiClient, JsonNod } if (Common.GetValueByPath(fromObject, new string[] { "contents" }) != null) { - Common.SetValueByPath( - toObject, 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, + rootObject)); + } + Common.SetValueByPath(toObject, new string[] { "contents" }, result); } if (Common.GetValueByPath(fromObject, new string[] { "config" }) != null) { @@ -3308,6 +3360,90 @@ 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, + JsonNode rootObject) { + 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; } @@ -3746,6 +3882,38 @@ internal JsonNode ToolConfigToMldev(JsonNode fromObject, JsonObject parentObject toObject, rootObject)); } + 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, + JsonNode rootObject) { + 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; } diff --git a/Google.GenAI/types/CodeExecutionResult.cs b/Google.GenAI/types/CodeExecutionResult.cs index 06661810..c66f5ff6 100644 --- a/Google.GenAI/types/CodeExecutionResult.cs +++ b/Google.GenAI/types/CodeExecutionResult.cs @@ -23,8 +23,8 @@ namespace Google.GenAI.Types { /// - /// Result of executing the [ExecutableCode]. Only generated when using the [CodeExecution] tool, - /// and always follows a `part` containing the [ExecutableCode]. + /// Result of executing the `ExecutableCode`. Generated only when the `CodeExecution` tool is + /// used. /// public record CodeExecutionResult { @@ -46,6 +46,17 @@ public string get; set; } + /// + /// The identifier of the `ExecutableCode` part this result is for. Only populated if the + /// corresponding `ExecutableCode` has an id. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string + ? Id { + get; set; + } + /// /// Deserializes a JSON string to a CodeExecutionResult object. /// diff --git a/Google.GenAI/types/ExecutableCode.cs b/Google.GenAI/types/ExecutableCode.cs index ed727000..40218131 100644 --- a/Google.GenAI/types/ExecutableCode.cs +++ b/Google.GenAI/types/ExecutableCode.cs @@ -23,9 +23,9 @@ namespace Google.GenAI.Types { /// - /// Code generated by the model that is meant to be executed, and the result returned to the - /// model. Generated when using the [CodeExecution] tool, in which the code will be automatically - /// executed, and a corresponding [CodeExecutionResult] will also be generated. + /// Model-generated code executed server-side, results returned to the model. Only generated when + /// using the `CodeExecution` tool, in which the code will be automatically executed, and a + /// corresponding `CodeExecutionResult` will also be generated. /// public record ExecutableCode { @@ -46,6 +46,17 @@ public Language get; set; } + /// + /// Unique identifier of the `ExecutableCode` part. The server returns the `CodeExecutionResult` + /// with the matching `id`. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string + ? Id { + get; set; + } + /// /// Deserializes a JSON string to a ExecutableCode object. /// diff --git a/Google.GenAI/types/Part.cs b/Google.GenAI/types/Part.cs index f7cc194e..182a52fd 100644 --- a/Google.GenAI/types/Part.cs +++ b/Google.GenAI/types/Part.cs @@ -143,6 +143,29 @@ public VideoMetadata get; set; } + /// + /// Server-side tool call. This field is populated when the model predicts a tool invocation + /// that should be executed on the server. The client is expected to echo this message back to + /// the API. + /// + [JsonPropertyName("toolCall")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public ToolCall + ? ToolCall { + get; set; + } + + /// + /// The output from a server-side ToolCall execution. This field is populated by the client with + /// the results of executing the corresponding ToolCall. + /// + [JsonPropertyName("toolResponse")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public ToolResponse + ? ToolResponse { + get; set; + } + /// /// Deserializes a JSON string to a Part object. /// diff --git a/Google.GenAI/types/ToolCall.cs b/Google.GenAI/types/ToolCall.cs new file mode 100644 index 00000000..97351692 --- /dev/null +++ b/Google.GenAI/types/ToolCall.cs @@ -0,0 +1,76 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Auto-generated code. Do not edit. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; +using Google.GenAI.Serialization; + +namespace Google.GenAI.Types { + /// + /// A predicted server-side `ToolCall` returned from the model. This message contains information + /// about a tool that the model wants to invoke. The client is NOT expected to execute this + /// `ToolCall`. Instead, the client should pass this `ToolCall` back to the API in a subsequent + /// turn within a `Content` message, along with the corresponding `ToolResponse`. + /// + + public record ToolCall { + /// + /// Unique identifier of the tool call. The server returns the tool response with the matching + /// `id`. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string ? Id { get; set; } + + /// + /// The type of tool that was called. + /// + [JsonPropertyName("toolType")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public ToolType + ? ToolType { + get; set; + } + + /// + /// The tool call arguments. Example: {"arg1": "value1", "arg2": "value2"}. + /// + [JsonPropertyName("args")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public Dictionary + ? Args { + get; set; + } + + /// + /// Deserializes a JSON string to a ToolCall object. + /// + /// The JSON string to deserialize. + /// Optional JsonSerializerOptions. + /// The deserialized ToolCall object, or null if deserialization fails. + public static ToolCall ? FromJson(string jsonString, JsonSerializerOptions? options = null) { + try { + return JsonSerializer.Deserialize(jsonString, options); + } catch (JsonException e) { + Console.Error.WriteLine($"Error deserializing JSON: {e.ToString()}"); + return null; + } + } + } +} diff --git a/Google.GenAI/types/ToolConfig.cs b/Google.GenAI/types/ToolConfig.cs index e8f7e7e6..a6972306 100644 --- a/Google.GenAI/types/ToolConfig.cs +++ b/Google.GenAI/types/ToolConfig.cs @@ -44,6 +44,17 @@ public FunctionCallingConfig get; set; } + /// + /// If true, the API response will include the server-side tool calls and responses within the + /// `Content` message. This allows clients to observe the server's tool invocations. + /// + [JsonPropertyName("includeServerSideToolInvocations")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public bool + ? IncludeServerSideToolInvocations { + get; set; + } + /// /// Deserializes a JSON string to a ToolConfig object. /// diff --git a/Google.GenAI/types/ToolResponse.cs b/Google.GenAI/types/ToolResponse.cs new file mode 100644 index 00000000..e104f867 --- /dev/null +++ b/Google.GenAI/types/ToolResponse.cs @@ -0,0 +1,76 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Auto-generated code. Do not edit. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; +using Google.GenAI.Serialization; + +namespace Google.GenAI.Types { + /// + /// The output from a server-side `ToolCall` execution. This message contains the results of a + /// tool invocation that was initiated by a `ToolCall` from the model. The client should pass this + /// `ToolResponse` back to the API in a subsequent turn within a `Content` message, along with the + /// corresponding `ToolCall`. + /// + + public record ToolResponse { + /// + /// The identifier of the tool call this response is for. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string ? Id { get; set; } + + /// + /// The type of tool that was called, matching the tool_type in the corresponding ToolCall. + /// + [JsonPropertyName("toolType")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public ToolType + ? ToolType { + get; set; + } + + /// + /// The tool response. + /// + [JsonPropertyName("response")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public Dictionary + ? Response { + get; set; + } + + /// + /// Deserializes a JSON string to a ToolResponse object. + /// + /// The JSON string to deserialize. + /// Optional JsonSerializerOptions. + /// The deserialized ToolResponse object, or null if deserialization fails. + public static ToolResponse + ? FromJson(string jsonString, JsonSerializerOptions? options = null) { + try { + return JsonSerializer.Deserialize(jsonString, options); + } catch (JsonException e) { + Console.Error.WriteLine($"Error deserializing JSON: {e.ToString()}"); + return null; + } + } + } +} diff --git a/Google.GenAI/types/ToolType.cs b/Google.GenAI/types/ToolType.cs new file mode 100644 index 00000000..54476ba2 --- /dev/null +++ b/Google.GenAI/types/ToolType.cs @@ -0,0 +1,106 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Auto-generated code. Do not edit. + +using System.Text.Json.Serialization; +using System.Collections.Generic; +using System.Text.Json; + +namespace Google.GenAI.Types { + /// + /// The type of tool in the function call. + /// + + [JsonConverter(typeof(ToolTypeConverter))] + public readonly record struct ToolType : IEquatable { + public string Value { get; } + + private ToolType(string value) { + Value = value; + } + + /// + /// Unspecified tool type. + /// + public static ToolType ToolTypeUnspecified { get; } = new("TOOL_TYPE_UNSPECIFIED"); + + /// + /// Google search tool, maps to Tool.google_search.search_types.web_search. + /// + public static ToolType GoogleSearchWeb { get; } = new("GOOGLE_SEARCH_WEB"); + + /// + /// Image search tool, maps to Tool.google_search.search_types.image_search. + /// + public static ToolType GoogleSearchImage { get; } = new("GOOGLE_SEARCH_IMAGE"); + + /// + /// URL context tool, maps to Tool.url_context. + /// + public static ToolType UrlContext { get; } = new("URL_CONTEXT"); + + /// + /// Google maps tool, maps to Tool.google_maps. + /// + public static ToolType GoogleMaps { get; } = new("GOOGLE_MAPS"); + + /// + /// File search tool, maps to Tool.file_search. + /// + public static ToolType FileSearch { get; } = new("FILE_SEARCH"); + + public static IReadOnlyList AllValues { + get; + } = new[] { ToolTypeUnspecified, GoogleSearchWeb, GoogleSearchImage, + UrlContext, GoogleMaps, FileSearch }; + + public static ToolType FromString(string value) { + if (string.IsNullOrEmpty(value)) { + return new ToolType("TOOL_TYPE_UNSPECIFIED"); + } + + foreach (var known in AllValues) { + if (known.Value == value) { + return known; + } + } + + return new ToolType(value); + } + + public override string ToString() => Value ?? string.Empty; + + public static implicit operator ToolType(string value) => FromString(value); + + public bool Equals(ToolType other) => Value == other.Value; + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + } + + public class ToolTypeConverter : JsonConverter { + public override ToolType Read(ref Utf8JsonReader reader, System.Type typeToConvert, + JsonSerializerOptions options) { + var value = reader.GetString(); + return ToolType.FromString(value); + } + + public override void Write(Utf8JsonWriter writer, ToolType value, + JsonSerializerOptions options) { + writer.WriteStringValue(value.Value); + } + } +}