Skip to content

Commit 7505ed4

Browse files
committed
Add blockReasonMessage to PromptFeedback
1 parent ca2ef42 commit 7505ed4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

firebase-vertexai/src/test/java/com/google/firebase/vertexai/StreamingSnapshotTests.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ internal class StreamingSnapshotTests {
123123
}
124124
}
125125

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+
126138
@Test
127139
fun `empty content`() =
128140
goldenStreamingFile("streaming-failure-empty-content.txt") {

firebase-vertexai/src/test/java/com/google/firebase/vertexai/UnarySnapshotTests.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ internal class UnarySnapshotTests {
167167
}
168168
}
169169

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+
170182
@Test
171183
fun `empty content`() =
172184
goldenUnaryFile("unary-failure-empty-content.json") {

0 commit comments

Comments
 (0)