Skip to content

Commit a53bffe

Browse files
committed
Several small changes to enums API
The changes restricted to enum values and names are: - Remove `UNSPECIFIED` from `FinishReason` - Renamed `BlockThreshold` to `HarmBlockThreshold` - Rename UNSPECIFIED to UNKNOWN in `HarmBlockThreshold` - Remove `UNSPECIFIED` from `HarmProbability` - Remove `UNSPECIFIED` from `HarmSeverity` - Remove `UNSPECIFIED` from `BlockReason` Additionally, additional changes to non-enum values include - Make `totalBillableCharacters` nullable and optional
1 parent da0eefa commit a53bffe

File tree

8 files changed

+18
-36
lines changed

8 files changed

+18
-36
lines changed

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ import com.google.firebase.vertexai.common.shared.FunctionCall
2626
import com.google.firebase.vertexai.common.shared.FunctionCallPart
2727
import com.google.firebase.vertexai.common.shared.FunctionResponse
2828
import com.google.firebase.vertexai.common.shared.FunctionResponsePart
29-
import com.google.firebase.vertexai.common.shared.HarmBlockThreshold
3029
import com.google.firebase.vertexai.type.BlobPart
3130
import com.google.firebase.vertexai.type.BlockReason
32-
import com.google.firebase.vertexai.type.BlockThreshold
31+
import com.google.firebase.vertexai.type.HarmBlockThreshold
3332
import com.google.firebase.vertexai.type.Candidate
3433
import com.google.firebase.vertexai.type.Citation
3534
import com.google.firebase.vertexai.type.CitationMetadata
@@ -142,13 +141,13 @@ internal fun ToolConfig.toInternal() =
142141
)
143142
)
144143

145-
internal fun BlockThreshold.toInternal() =
144+
internal fun HarmBlockThreshold.toInternal() =
146145
when (this) {
147-
BlockThreshold.NONE -> HarmBlockThreshold.BLOCK_NONE
148-
BlockThreshold.ONLY_HIGH -> HarmBlockThreshold.BLOCK_ONLY_HIGH
149-
BlockThreshold.MEDIUM_AND_ABOVE -> HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE
150-
BlockThreshold.LOW_AND_ABOVE -> HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
151-
BlockThreshold.UNSPECIFIED -> HarmBlockThreshold.UNSPECIFIED
146+
HarmBlockThreshold.NONE -> com.google.firebase.vertexai.common.shared.HarmBlockThreshold.BLOCK_NONE
147+
HarmBlockThreshold.ONLY_HIGH -> com.google.firebase.vertexai.common.shared.HarmBlockThreshold.BLOCK_ONLY_HIGH
148+
HarmBlockThreshold.MEDIUM_AND_ABOVE -> com.google.firebase.vertexai.common.shared.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE
149+
HarmBlockThreshold.LOW_AND_ABOVE -> com.google.firebase.vertexai.common.shared.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
150+
HarmBlockThreshold.UNKNOWN -> com.google.firebase.vertexai.common.shared.HarmBlockThreshold.UNSPECIFIED
152151
}
153152

154153
internal fun Tool.toInternal() =
@@ -262,8 +261,7 @@ internal fun com.google.firebase.vertexai.common.server.FinishReason?.toPublic()
262261
com.google.firebase.vertexai.common.server.FinishReason.SAFETY -> FinishReason.SAFETY
263262
com.google.firebase.vertexai.common.server.FinishReason.STOP -> FinishReason.STOP
264263
com.google.firebase.vertexai.common.server.FinishReason.OTHER -> FinishReason.OTHER
265-
com.google.firebase.vertexai.common.server.FinishReason.UNSPECIFIED -> FinishReason.UNSPECIFIED
266-
com.google.firebase.vertexai.common.server.FinishReason.UNKNOWN -> FinishReason.UNKNOWN
264+
else -> FinishReason.UNKNOWN
267265
}
268266

269267
internal fun com.google.firebase.vertexai.common.shared.HarmCategory.toPublic() =
@@ -274,7 +272,7 @@ internal fun com.google.firebase.vertexai.common.shared.HarmCategory.toPublic()
274272
HarmCategory.SEXUALLY_EXPLICIT
275273
com.google.firebase.vertexai.common.shared.HarmCategory.DANGEROUS_CONTENT ->
276274
HarmCategory.DANGEROUS_CONTENT
277-
com.google.firebase.vertexai.common.shared.HarmCategory.UNKNOWN -> HarmCategory.UNKNOWN
275+
else -> HarmCategory.UNKNOWN
278276
}
279277

280278
internal fun com.google.firebase.vertexai.common.server.HarmProbability.toPublic() =
@@ -284,9 +282,7 @@ internal fun com.google.firebase.vertexai.common.server.HarmProbability.toPublic
284282
com.google.firebase.vertexai.common.server.HarmProbability.LOW -> HarmProbability.LOW
285283
com.google.firebase.vertexai.common.server.HarmProbability.NEGLIGIBLE ->
286284
HarmProbability.NEGLIGIBLE
287-
com.google.firebase.vertexai.common.server.HarmProbability.UNSPECIFIED ->
288-
HarmProbability.UNSPECIFIED
289-
com.google.firebase.vertexai.common.server.HarmProbability.UNKNOWN -> HarmProbability.UNKNOWN
285+
else -> HarmProbability.UNKNOWN
290286
}
291287

292288
internal fun com.google.firebase.vertexai.common.server.HarmSeverity.toPublic() =
@@ -295,16 +291,14 @@ internal fun com.google.firebase.vertexai.common.server.HarmSeverity.toPublic()
295291
com.google.firebase.vertexai.common.server.HarmSeverity.MEDIUM -> HarmSeverity.MEDIUM
296292
com.google.firebase.vertexai.common.server.HarmSeverity.LOW -> HarmSeverity.LOW
297293
com.google.firebase.vertexai.common.server.HarmSeverity.NEGLIGIBLE -> HarmSeverity.NEGLIGIBLE
298-
com.google.firebase.vertexai.common.server.HarmSeverity.UNSPECIFIED -> HarmSeverity.UNSPECIFIED
299-
com.google.firebase.vertexai.common.server.HarmSeverity.UNKNOWN -> HarmSeverity.UNKNOWN
294+
else -> HarmSeverity.UNKNOWN
300295
}
301296

302297
internal fun com.google.firebase.vertexai.common.server.BlockReason.toPublic() =
303298
when (this) {
304-
com.google.firebase.vertexai.common.server.BlockReason.UNSPECIFIED -> BlockReason.UNSPECIFIED
305299
com.google.firebase.vertexai.common.server.BlockReason.SAFETY -> BlockReason.SAFETY
306300
com.google.firebase.vertexai.common.server.BlockReason.OTHER -> BlockReason.OTHER
307-
com.google.firebase.vertexai.common.server.BlockReason.UNKNOWN -> BlockReason.UNKNOWN
301+
else -> BlockReason.UNKNOWN
308302
}
309303

310304
internal fun com.google.firebase.vertexai.common.GenerateContentResponse.toPublic():

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ enum class FinishReason {
6868
/** A new and not yet supported value. */
6969
UNKNOWN,
7070

71-
/** Reason is unspecified. */
72-
UNSPECIFIED,
73-
7471
/** Model finished successfully and stopped. */
7572
STOP,
7673

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ package com.google.firebase.vertexai.type
2020
* Represents a response measuring model input.
2121
*
2222
* @property totalTokens A count of the tokens in the input
23-
* @property totalBillableCharacters A count of the characters that are billable in the input
23+
* @property totalBillableCharacters A count of the characters that are billable in the input, if available.
2424
*/
25-
class CountTokensResponse(val totalTokens: Int, val totalBillableCharacters: Int) {
25+
class CountTokensResponse(val totalTokens: Int, val totalBillableCharacters: Int? = null) {
2626
operator fun component1() = totalTokens
2727

2828
operator fun component2() = totalBillableCharacters

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/BlockThreshold.kt renamed to firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmBlockThreshold.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ package com.google.firebase.vertexai.type
1919
/**
2020
* Represents the threshold for some [HarmCategory] that is allowed and blocked by [SafetySetting].
2121
*/
22-
enum class BlockThreshold {
22+
enum class HarmBlockThreshold {
2323
/** The threshold was not specified. */
24-
UNSPECIFIED,
24+
UNKNOWN,
2525

2626
/** Content with negligible harm is allowed. */
2727
LOW_AND_ABOVE,

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ enum class HarmProbability {
2121
/** A new and not yet supported value. */
2222
UNKNOWN,
2323

24-
/** Probability for harm is unspecified. */
25-
UNSPECIFIED,
26-
2724
/** Probability for harm is negligible. */
2825
NEGLIGIBLE,
2926

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ enum class HarmSeverity {
2121
/** A new and not yet supported value. */
2222
UNKNOWN,
2323

24-
/** Severity for harm is unspecified. */
25-
UNSPECIFIED,
26-
2724
/** Severity for harm is negligible. */
2825
NEGLIGIBLE,
2926

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ enum class BlockReason {
3434
/** A new and not yet supported value. */
3535
UNKNOWN,
3636

37-
/** Content was blocked for an unspecified reason. */
38-
UNSPECIFIED,
39-
4037
/** Content was blocked for violating provided [SafetySetting]. */
4138
SAFETY,
4239

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
package com.google.firebase.vertexai.type
1818

1919
/**
20-
* A configuration for a [BlockThreshold] of some [HarmCategory] allowed and blocked in responses.
20+
* A configuration for a [HarmBlockThreshold] of some [HarmCategory] allowed and blocked in responses.
2121
*
2222
* @param harmCategory The relevant [HarmCategory].
2323
* @param threshold The threshold form harm allowable.
2424
*/
25-
class SafetySetting(val harmCategory: HarmCategory, val threshold: BlockThreshold) {}
25+
class SafetySetting(val harmCategory: HarmCategory, val threshold: HarmBlockThreshold) {}

0 commit comments

Comments
 (0)