Skip to content

Commit 64986d9

Browse files
authored
Merge branch 'main' into rl.release.notes.newline
2 parents 98bd6e8 + d153670 commit 64986d9

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/server/Types.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ internal object FinishReasonSerializer :
3838
internal data class PromptFeedback(
3939
val blockReason: BlockReason? = null,
4040
val safetyRatings: List<SafetyRating>? = null,
41+
val blockReasonMessage: String? = null,
4142
)
4243

4344
@Serializable(BlockReasonSerializer::class)

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/conversions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ internal fun com.google.firebase.vertexai.common.server.PromptFeedback.toPublic(
245245
return com.google.firebase.vertexai.type.PromptFeedback(
246246
blockReason?.toPublic(),
247247
safetyRatings,
248+
blockReasonMessage
248249
)
249250
}
250251

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ package com.google.firebase.vertexai.type
2121
*
2222
* @param blockReason The reason that content was blocked, if at all.
2323
* @param safetyRatings A list of relevant [SafetyRating].
24+
* @param blockReasonMessage A message describing the reason that content was blocked, if any.
2425
*/
2526
class PromptFeedback(
2627
val blockReason: BlockReason?,
2728
val safetyRatings: List<SafetyRating>,
29+
val blockReasonMessage: String?
2830
)
2931

3032
/** Describes why content was blocked. */

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)