File tree Expand file tree Collapse file tree 5 files changed +28
-0
lines changed
main/kotlin/com/google/firebase/vertexai
test/java/com/google/firebase/vertexai Expand file tree Collapse file tree 5 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ internal object FinishReasonSerializer :
38
38
internal data class PromptFeedback (
39
39
val blockReason : BlockReason ? = null ,
40
40
val safetyRatings : List <SafetyRating >? = null ,
41
+ val blockReasonMessage : String? = null ,
41
42
)
42
43
43
44
@Serializable(BlockReasonSerializer ::class )
Original file line number Diff line number Diff line change @@ -245,6 +245,7 @@ internal fun com.google.firebase.vertexai.common.server.PromptFeedback.toPublic(
245
245
return com.google.firebase.vertexai.type.PromptFeedback (
246
246
blockReason?.toPublic(),
247
247
safetyRatings,
248
+ blockReasonMessage
248
249
)
249
250
}
250
251
Original file line number Diff line number Diff line change @@ -21,10 +21,12 @@ package com.google.firebase.vertexai.type
21
21
*
22
22
* @param blockReason The reason that content was blocked, if at all.
23
23
* @param safetyRatings A list of relevant [SafetyRating].
24
+ * @param blockReasonMessage A message describing the reason that content was blocked, if any.
24
25
*/
25
26
class PromptFeedback (
26
27
val blockReason : BlockReason ? ,
27
28
val safetyRatings : List <SafetyRating >,
29
+ val blockReasonMessage : String?
28
30
)
29
31
30
32
/* * Describes why content was blocked. */
Original file line number Diff line number Diff line change @@ -123,6 +123,18 @@ internal class StreamingSnapshotTests {
123
123
}
124
124
}
125
125
126
+ @Test
127
+ fun `prompt blocked for safety with message` () =
128
+ goldenStreamingFile(" streaming-failure-prompt-blocked-safety-with-message.txt" ) {
129
+ val responses = model.generateContentStream(" prompt" )
130
+
131
+ withTimeout(testTimeout) {
132
+ val exception = shouldThrow<PromptBlockedException > { responses.collect() }
133
+ exception.response.promptFeedback?.blockReason shouldBe BlockReason .SAFETY
134
+ exception.response.promptFeedback?.blockReasonMessage shouldBe " Reasons"
135
+ }
136
+ }
137
+
126
138
@Test
127
139
fun `empty content` () =
128
140
goldenStreamingFile(" streaming-failure-empty-content.txt" ) {
Original file line number Diff line number Diff line change @@ -167,6 +167,18 @@ internal class UnarySnapshotTests {
167
167
}
168
168
}
169
169
170
+ @Test
171
+ fun `prompt blocked for safety with message` () =
172
+ goldenUnaryFile(" unary-failure-prompt-blocked-safety-with-message.json" ) {
173
+ withTimeout(testTimeout) {
174
+ shouldThrow<PromptBlockedException > { model.generateContent(" prompt" ) } should
175
+ {
176
+ it.response.promptFeedback?.blockReason shouldBe BlockReason .SAFETY
177
+ it.response.promptFeedback?.blockReasonMessage shouldContain " Reasons"
178
+ }
179
+ }
180
+ }
181
+
170
182
@Test
171
183
fun `empty content` () =
172
184
goldenUnaryFile(" unary-failure-empty-content.json" ) {
You can’t perform that action at this time.
0 commit comments