-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogleImageGenerationOptions.cs
More file actions
136 lines (120 loc) · 5.32 KB
/
GoogleImageGenerationOptions.cs
File metadata and controls
136 lines (120 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
namespace MultiImageClient
{
/// <summary>
/// Configuration options for Google image generation APIs (both Gemini and Imagen 4).
/// Not all options are supported by all APIs - see individual property docs.
/// </summary>
public class GoogleImageGenerationOptions
{
/// <summary>
/// Output image resolution. Gemini supports 1K/2K/4K, Imagen 4 only supports 1K/2K.
/// Default: Size1K
/// </summary>
public GoogleImageSize ImageSize { get; set; } = GoogleImageSize.Size1K;
/// <summary>
/// Aspect ratio of generated images.
/// Supported: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
/// Default: Ratio1x1
/// </summary>
public GoogleImageAspectRatio AspectRatio { get; set; } = GoogleImageAspectRatio.Ratio1x1;
/// <summary>
/// Controls generation of people/faces in images.
/// Imagen 4 only. Default: AllowAdult
/// </summary>
public GooglePersonGeneration PersonGeneration { get; set; } = GooglePersonGeneration.AllowAdult;
/// <summary>
/// Safety filter threshold level.
/// Imagen 4 only. Default: BlockMediumAndAbove
/// </summary>
public GoogleSafetyFilterLevel SafetyFilterLevel { get; set; } = GoogleSafetyFilterLevel.BlockMediumAndAbove;
/// <summary>
/// Output image format.
/// Imagen 4 only. Default: Png
/// </summary>
public GoogleOutputMimeType OutputMimeType { get; set; } = GoogleOutputMimeType.Png;
/// <summary>
/// JPEG compression quality (0-100). Only applies when OutputMimeType is Jpeg.
/// Imagen 4 only. Default: 75
/// </summary>
public int CompressionQuality { get; set; } = 75;
/// <summary>
/// Whether to use LLM-based prompt enhancement for higher quality images.
/// Imagen 4 only. Default: false (to preserve exact prompts)
/// </summary>
public bool EnhancePrompt { get; set; } = false;
/// <summary>
/// Whether to add a SynthID digital watermark to generated images.
/// When true, seed parameter is ignored.
/// Imagen 4 only. Default: false
/// </summary>
public bool AddWatermark { get; set; } = false;
/// <summary>
/// Random seed for deterministic output. Only works when AddWatermark=false and EnhancePrompt=false.
/// Set to null for random generation.
/// Imagen 4 only. Default: null
/// </summary>
public uint? Seed { get; set; } = null;
/// <summary>
/// Number of images to generate per request (1-4).
/// Imagen 4 only. Default: 1
/// </summary>
public int NumberOfImages { get; set; } = 1;
/// <summary>
/// Whether to include RAI (Responsible AI) filter reason in responses.
/// Imagen 4 only. Default: true
/// </summary>
public bool IncludeRaiReason { get; set; } = true;
/// <summary>
/// Creates a copy of this options object with potentially modified values.
/// </summary>
public GoogleImageGenerationOptions Clone()
{
return new GoogleImageGenerationOptions
{
ImageSize = this.ImageSize,
AspectRatio = this.AspectRatio,
PersonGeneration = this.PersonGeneration,
SafetyFilterLevel = this.SafetyFilterLevel,
OutputMimeType = this.OutputMimeType,
CompressionQuality = this.CompressionQuality,
EnhancePrompt = this.EnhancePrompt,
AddWatermark = this.AddWatermark,
Seed = this.Seed,
NumberOfImages = this.NumberOfImages,
IncludeRaiReason = this.IncludeRaiReason
};
}
/// <summary>
/// Validates options for Imagen 4 API compatibility.
/// </summary>
public void ValidateForImagen4()
{
if (ImageSize == GoogleImageSize.Size4K)
{
throw new System.ArgumentException("Imagen 4 does not support 4K resolution. Use 1K or 2K.");
}
if (NumberOfImages < 1 || NumberOfImages > 4)
{
throw new System.ArgumentException("NumberOfImages must be between 1 and 4.");
}
if (CompressionQuality < 0 || CompressionQuality > 100)
{
throw new System.ArgumentException("CompressionQuality must be between 0 and 100.");
}
}
/// <summary>
/// Gets a string representation of the key options for display/logging.
/// </summary>
public string ToDisplayString()
{
return $"{ImageSize.ToApiString()} {AspectRatio.ToApiString()}";
}
/// <summary>
/// Gets a filename-safe string representation of key options.
/// </summary>
public string ToFilenamePart()
{
return $"{ImageSize.ToApiString()}_{AspectRatio.ToApiString().Replace(":", "x")}";
}
}
}