Skip to content

Commit 09a8075

Browse files
matthew29tangcopybara-github
authored andcommitted
feat: Add safety_filter_level and person_generation for Imagen upscaling
PiperOrigin-RevId: 825183839
1 parent 7259f5f commit 09a8075

File tree

4 files changed

+154
-0
lines changed

4 files changed

+154
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4325,6 +4325,20 @@ ObjectNode upscaleImageAPIConfigToVertex(JsonNode fromObject, ObjectNode parentO
43254325
Common.getValueByPath(fromObject, new String[] {"outputGcsUri"}));
43264326
}
43274327

4328+
if (Common.getValueByPath(fromObject, new String[] {"safetyFilterLevel"}) != null) {
4329+
Common.setValueByPath(
4330+
parentObject,
4331+
new String[] {"parameters", "safetySetting"},
4332+
Common.getValueByPath(fromObject, new String[] {"safetyFilterLevel"}));
4333+
}
4334+
4335+
if (Common.getValueByPath(fromObject, new String[] {"personGeneration"}) != null) {
4336+
Common.setValueByPath(
4337+
parentObject,
4338+
new String[] {"parameters", "personGeneration"},
4339+
Common.getValueByPath(fromObject, new String[] {"personGeneration"}));
4340+
}
4341+
43284342
if (Common.getValueByPath(fromObject, new String[] {"includeRaiReason"}) != null) {
43294343
Common.setValueByPath(
43304344
parentObject,
@@ -6290,6 +6304,12 @@ UpscaleImageAPIConfig preProcessUpscaleImageConfig(UpscaleImageConfig config) {
62906304
if (config.outputCompressionQuality().isPresent()) {
62916305
builder = builder.outputCompressionQuality(config.outputCompressionQuality().get());
62926306
}
6307+
if (config.safetyFilterLevel().isPresent()) {
6308+
builder = builder.safetyFilterLevel(config.safetyFilterLevel().get());
6309+
}
6310+
if (config.personGeneration().isPresent()) {
6311+
builder = builder.personGeneration(config.personGeneration().get());
6312+
}
62936313
if (config.includeRaiReason().isPresent()) {
62946314
builder = builder.includeRaiReason(config.includeRaiReason().get());
62956315
}

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2424
import com.google.api.core.InternalApi;
2525
import com.google.auto.value.AutoValue;
26+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2627
import com.google.genai.JsonSerializable;
2728
import java.util.Map;
2829
import java.util.Optional;
@@ -45,6 +46,14 @@ public abstract class UpscaleImageAPIConfig extends JsonSerializable {
4546
@JsonProperty("outputGcsUri")
4647
public abstract Optional<String> outputGcsUri();
4748

49+
/** Filter level for safety filtering. */
50+
@JsonProperty("safetyFilterLevel")
51+
public abstract Optional<SafetyFilterLevel> safetyFilterLevel();
52+
53+
/** Allows generation of people by the model. */
54+
@JsonProperty("personGeneration")
55+
public abstract Optional<PersonGeneration> personGeneration();
56+
4857
/** Whether to include a reason for filtered-out images in the response. */
4958
@JsonProperty("includeRaiReason")
5059
public abstract Optional<Boolean> includeRaiReason();
@@ -127,6 +136,62 @@ public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) {
127136
@JsonProperty("outputGcsUri")
128137
public abstract Builder outputGcsUri(String outputGcsUri);
129138

139+
/**
140+
* Setter for safetyFilterLevel.
141+
*
142+
* <p>safetyFilterLevel: Filter level for safety filtering.
143+
*/
144+
@JsonProperty("safetyFilterLevel")
145+
public abstract Builder safetyFilterLevel(SafetyFilterLevel safetyFilterLevel);
146+
147+
/**
148+
* Setter for safetyFilterLevel given a known enum.
149+
*
150+
* <p>safetyFilterLevel: Filter level for safety filtering.
151+
*/
152+
@CanIgnoreReturnValue
153+
public Builder safetyFilterLevel(SafetyFilterLevel.Known knownType) {
154+
return safetyFilterLevel(new SafetyFilterLevel(knownType));
155+
}
156+
157+
/**
158+
* Setter for safetyFilterLevel given a string.
159+
*
160+
* <p>safetyFilterLevel: Filter level for safety filtering.
161+
*/
162+
@CanIgnoreReturnValue
163+
public Builder safetyFilterLevel(String safetyFilterLevel) {
164+
return safetyFilterLevel(new SafetyFilterLevel(safetyFilterLevel));
165+
}
166+
167+
/**
168+
* Setter for personGeneration.
169+
*
170+
* <p>personGeneration: Allows generation of people by the model.
171+
*/
172+
@JsonProperty("personGeneration")
173+
public abstract Builder personGeneration(PersonGeneration personGeneration);
174+
175+
/**
176+
* Setter for personGeneration given a known enum.
177+
*
178+
* <p>personGeneration: Allows generation of people by the model.
179+
*/
180+
@CanIgnoreReturnValue
181+
public Builder personGeneration(PersonGeneration.Known knownType) {
182+
return personGeneration(new PersonGeneration(knownType));
183+
}
184+
185+
/**
186+
* Setter for personGeneration given a string.
187+
*
188+
* <p>personGeneration: Allows generation of people by the model.
189+
*/
190+
@CanIgnoreReturnValue
191+
public Builder personGeneration(String personGeneration) {
192+
return personGeneration(new PersonGeneration(personGeneration));
193+
}
194+
130195
/**
131196
* Setter for includeRaiReason.
132197
*

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.fasterxml.jackson.annotation.JsonProperty;
2323
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2424
import com.google.auto.value.AutoValue;
25+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2526
import com.google.genai.JsonSerializable;
2627
import java.util.Map;
2728
import java.util.Optional;
@@ -43,6 +44,14 @@ public abstract class UpscaleImageConfig extends JsonSerializable {
4344
@JsonProperty("outputGcsUri")
4445
public abstract Optional<String> outputGcsUri();
4546

47+
/** Filter level for safety filtering. */
48+
@JsonProperty("safetyFilterLevel")
49+
public abstract Optional<SafetyFilterLevel> safetyFilterLevel();
50+
51+
/** Allows generation of people by the model. */
52+
@JsonProperty("personGeneration")
53+
public abstract Optional<PersonGeneration> personGeneration();
54+
4655
/** Whether to include a reason for filtered-out images in the response. */
4756
@JsonProperty("includeRaiReason")
4857
public abstract Optional<Boolean> includeRaiReason();
@@ -117,6 +126,62 @@ public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) {
117126
@JsonProperty("outputGcsUri")
118127
public abstract Builder outputGcsUri(String outputGcsUri);
119128

129+
/**
130+
* Setter for safetyFilterLevel.
131+
*
132+
* <p>safetyFilterLevel: Filter level for safety filtering.
133+
*/
134+
@JsonProperty("safetyFilterLevel")
135+
public abstract Builder safetyFilterLevel(SafetyFilterLevel safetyFilterLevel);
136+
137+
/**
138+
* Setter for safetyFilterLevel given a known enum.
139+
*
140+
* <p>safetyFilterLevel: Filter level for safety filtering.
141+
*/
142+
@CanIgnoreReturnValue
143+
public Builder safetyFilterLevel(SafetyFilterLevel.Known knownType) {
144+
return safetyFilterLevel(new SafetyFilterLevel(knownType));
145+
}
146+
147+
/**
148+
* Setter for safetyFilterLevel given a string.
149+
*
150+
* <p>safetyFilterLevel: Filter level for safety filtering.
151+
*/
152+
@CanIgnoreReturnValue
153+
public Builder safetyFilterLevel(String safetyFilterLevel) {
154+
return safetyFilterLevel(new SafetyFilterLevel(safetyFilterLevel));
155+
}
156+
157+
/**
158+
* Setter for personGeneration.
159+
*
160+
* <p>personGeneration: Allows generation of people by the model.
161+
*/
162+
@JsonProperty("personGeneration")
163+
public abstract Builder personGeneration(PersonGeneration personGeneration);
164+
165+
/**
166+
* Setter for personGeneration given a known enum.
167+
*
168+
* <p>personGeneration: Allows generation of people by the model.
169+
*/
170+
@CanIgnoreReturnValue
171+
public Builder personGeneration(PersonGeneration.Known knownType) {
172+
return personGeneration(new PersonGeneration(knownType));
173+
}
174+
175+
/**
176+
* Setter for personGeneration given a string.
177+
*
178+
* <p>personGeneration: Allows generation of people by the model.
179+
*/
180+
@CanIgnoreReturnValue
181+
public Builder personGeneration(String personGeneration) {
182+
return personGeneration(new PersonGeneration(personGeneration));
183+
}
184+
120185
/**
121186
* Setter for includeRaiReason.
122187
*

src/test/java/com/google/genai/AsyncModelsTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@
4747
import com.google.genai.types.MaskReferenceImage;
4848
import com.google.genai.types.Model;
4949
import com.google.genai.types.Part;
50+
import com.google.genai.types.PersonGeneration;
5051
import com.google.genai.types.RagRetrievalConfig;
5152
import com.google.genai.types.RagRetrievalConfigFilter;
5253
import com.google.genai.types.RawReferenceImage;
5354
import com.google.genai.types.Retrieval;
55+
import com.google.genai.types.SafetyFilterLevel;
5456
import com.google.genai.types.Tool;
5557
import com.google.genai.types.ToolCodeExecution;
5658
import com.google.genai.types.UpdateModelConfig;
@@ -626,6 +628,8 @@ public void testUpscaleImageAsync(boolean vertexAI) throws Exception {
626628
UpscaleImageConfig config =
627629
UpscaleImageConfig.builder()
628630
.includeRaiReason(true)
631+
.safetyFilterLevel(SafetyFilterLevel.Known.BLOCK_LOW_AND_ABOVE)
632+
.personGeneration(PersonGeneration.Known.ALLOW_ADULT)
629633
.outputMimeType("image/jpeg")
630634
.outputCompressionQuality(80)
631635
.enhanceInputImage(true)

0 commit comments

Comments
 (0)