Skip to content

Commit 82aeeef

Browse files
author
David Motsonashvili
committed
Add support for new FinishReason and BlockReason values
1 parent b4ff466 commit 82aeeef

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

firebase-vertexai/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Unreleased
2+
* [fixed] Added support for new values sent by the server for `FinishReason` and `BlockReason`
23

34

45
# 16.1.0

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Candidate.kt

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,13 @@ public class FinishReason private constructor(public val name: String, public va
247247
MAX_TOKENS,
248248
SAFETY,
249249
RECITATION,
250-
OTHER;
250+
OTHER,
251+
BLOCKLIST,
252+
PROHIBITED_CONTENT,
253+
SPII,
254+
MALFORMED_FUNCTION_CALL,
255+
MODEL_ARMOR,
256+
IMAGE_SAFETY;
251257

252258
internal object Serializer : KSerializer<Internal> by FirstOrdinalSerializer(Internal::class)
253259

@@ -258,6 +264,12 @@ public class FinishReason private constructor(public val name: String, public va
258264
SAFETY -> FinishReason.SAFETY
259265
STOP -> FinishReason.STOP
260266
OTHER -> FinishReason.OTHER
267+
BLOCKLIST -> FinishReason.BLOCKLIST
268+
PROHIBITED_CONTENT -> FinishReason.PROHIBITED_CONTENT
269+
SPII -> FinishReason.SPII
270+
MALFORMED_FUNCTION_CALL -> FinishReason.MALFORMED_FUNCTION_CALL
271+
MODEL_ARMOR -> FinishReason.MODEL_ARMOR
272+
IMAGE_SAFETY -> FinishReason.IMAGE_SAFETY
261273
else -> FinishReason.UNKNOWN
262274
}
263275
}
@@ -281,5 +293,27 @@ public class FinishReason private constructor(public val name: String, public va
281293

282294
/** Model stopped for another reason. */
283295
@JvmField public val OTHER: FinishReason = FinishReason("OTHER", 5)
296+
297+
/** Token generation stopped because the content contains forbidden terms. */
298+
@JvmField public val BLOCKLIST: FinishReason = FinishReason("BLOCKLIST", 6)
299+
300+
/** Token generation stopped for potentially containing prohibited content. */
301+
@JvmField public val PROHIBITED_CONTENT: FinishReason = FinishReason("PROHIBITED_CONTENT", 7)
302+
303+
/**
304+
* Token generation stopped because the content potentially contains Sensitive Personally
305+
* Identifiable Information (SPII).
306+
*/
307+
@JvmField public val SPII: FinishReason = FinishReason("SPII", 8)
308+
309+
/** The function call generated by the model is invalid. */
310+
@JvmField
311+
public val MALFORMED_FUNCTION_CALL: FinishReason = FinishReason("MALFORMED_FUNCTION_CALL", 9)
312+
313+
/** The model response was blocked by Model Armor. */
314+
@JvmField public val MODEL_ARMOR: FinishReason = FinishReason("MODEL_ARMOR", 10)
315+
316+
/** Token generation stopped because generated images has safety violations. */
317+
@JvmField public val IMAGE_SAFETY: FinishReason = FinishReason("IMAGE_SAFETY", 11)
284318
}
285319
}

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/PromptFeedback.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,22 @@ public class BlockReason private constructor(public val name: String, public val
5656
UNKNOWN,
5757
@SerialName("BLOCKED_REASON_UNSPECIFIED") UNSPECIFIED,
5858
SAFETY,
59-
OTHER;
59+
OTHER,
60+
BLOCKLIST,
61+
PROHIBITED_CONTENT,
62+
MODEL_ARMOR,
63+
IMAGE_SAFETY;
6064

6165
internal object Serializer : KSerializer<Internal> by FirstOrdinalSerializer(Internal::class)
6266

6367
internal fun toPublic() =
6468
when (this) {
6569
SAFETY -> BlockReason.SAFETY
6670
OTHER -> BlockReason.OTHER
71+
BLOCKLIST -> BlockReason.BLOCKLIST
72+
PROHIBITED_CONTENT -> BlockReason.PROHIBITED_CONTENT
73+
MODEL_ARMOR -> BlockReason.MODEL_ARMOR
74+
IMAGE_SAFETY -> BlockReason.IMAGE_SAFETY
6775
else -> BlockReason.UNKNOWN
6876
}
6977
}
@@ -76,5 +84,17 @@ public class BlockReason private constructor(public val name: String, public val
7684

7785
/** Content was blocked for another reason. */
7886
@JvmField public val OTHER: BlockReason = BlockReason("OTHER", 2)
87+
88+
/** Content was blocked for another reason. */
89+
@JvmField public val BLOCKLIST: BlockReason = BlockReason("BLOCKLIST", 3)
90+
91+
/** Candidates blocked due to the terms which are included from the terminology blocklist. */
92+
@JvmField public val PROHIBITED_CONTENT: BlockReason = BlockReason("PROHIBITED_CONTENT", 4)
93+
94+
/** The user prompt was blocked by Model Armor. */
95+
@JvmField public val MODEL_ARMOR: BlockReason = BlockReason("MODEL_ARMOR", 5)
96+
97+
/** Candidates blocked due to unsafe image generation content. */
98+
@JvmField public val IMAGE_SAFETY: BlockReason = BlockReason("IMAGE_SAFETY", 6)
7999
}
80100
}

0 commit comments

Comments
 (0)