这是indexloc提供的服务,不要输入任何密码
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
67 changes: 63 additions & 4 deletions Google.GenAI/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,11 @@ internal JsonNode GenerateContentConfigToMldev(ApiClient apiClient, JsonNode fro
}

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

return toObject;
Expand Down Expand Up @@ -733,8 +736,11 @@ internal JsonNode GenerateContentConfigToVertex(ApiClient apiClient, JsonNode fr
}

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

return toObject;
Expand Down Expand Up @@ -1294,6 +1300,59 @@ internal JsonNode GoogleSearchToMldev(JsonNode fromObject, JsonObject parentObje
return toObject;
}

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

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

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

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

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

return toObject;
}

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

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

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

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

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

return toObject;
}

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

Expand Down
21 changes: 21 additions & 0 deletions Google.GenAI/types/ImageConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ public string
get; set;
}

/// <summary>
/// MIME type of the generated image. This field is not supported in Gemini API.
/// </summary>
[JsonPropertyName("outputMimeType")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string
? OutputMimeType {
get; set;
}

/// <summary>
/// Compression quality of the generated image (for ``image/jpeg`` only). This field is not
/// supported in Gemini API.
/// </summary>
[JsonPropertyName("outputCompressionQuality")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public int
? OutputCompressionQuality {
get; set;
}

/// <summary>
/// Deserializes a JSON string to a ImageConfig object.
/// </summary>
Expand Down
Loading