Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
David Motsonashvili committed Jan 21, 2025
1 parent 269cda9 commit 316e187
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import com.google.firebase.vertexai.internal.util.toInternal
import com.google.firebase.vertexai.internal.util.toPublicGCS
import com.google.firebase.vertexai.internal.util.toPublicInline
import com.google.firebase.vertexai.type.FirebaseVertexAIException
import com.google.firebase.vertexai.type.ImagenSafetySettings
import com.google.firebase.vertexai.type.ImagenGCSImage
import com.google.firebase.vertexai.type.ImagenGenerationConfig
import com.google.firebase.vertexai.type.ImagenGenerationResponse
import com.google.firebase.vertexai.type.ImagenInlineImage
import com.google.firebase.vertexai.type.ImagenSafetySettings
import com.google.firebase.vertexai.type.PromptBlockedException
import com.google.firebase.vertexai.type.RequestOptions
import kotlin.time.Duration
Expand Down Expand Up @@ -115,7 +115,10 @@ internal constructor(
prompt: String,
): ImagenGenerationResponse<ImagenInlineImage> =
try {
controller.generateImage(constructRequest(prompt, null, generationConfig)).toPublicInline().validate()
controller
.generateImage(constructRequest(prompt, null, generationConfig))
.toPublicInline()
.validate()
} catch (e: Throwable) {
throw FirebaseVertexAIException.from(e)
}
Expand All @@ -131,7 +134,10 @@ internal constructor(
gcsUri: String,
): ImagenGenerationResponse<ImagenGCSImage> =
try {
controller.generateImage(constructRequest(prompt, gcsUri, generationConfig)).toPublicGCS().validate()
controller
.generateImage(constructRequest(prompt, gcsUri, generationConfig))
.toPublicGCS()
.validate()
} catch (e: Throwable) {
throw FirebaseVertexAIException.from(e)
}
Expand Down Expand Up @@ -164,8 +170,7 @@ internal constructor(
}
}

private fun <T> ImagenGenerationResponse<T>.validate():
ImagenGenerationResponse<T> {
private fun <T> ImagenGenerationResponse<T>.validate(): ImagenGenerationResponse<T> {
if (images.isEmpty()) {
throw PromptBlockedException(message = filteredReason ?: ImageModel.DEFAULT_FILTERED_ERROR)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ package com.google.firebase.vertexai.type
* @param addWatermark Adds an invisible watermark to mark the image as AI generated.
*/
public class ImagenGenerationConfig(
public val negativePrompt: String? = null,
public val numberOfImages: Int? = 1,
public val aspectRatio: ImagenAspectRatio? = null,
public val imageFormat: ImagenImageFormat? = null,
public val addWatermark: Boolean? = null
public val negativePrompt: String? = null,
public val numberOfImages: Int? = 1,
public val aspectRatio: ImagenAspectRatio? = null,
public val imageFormat: ImagenImageFormat? = null,
public val addWatermark: Boolean? = null
) {}

0 comments on commit 316e187

Please sign in to comment.